使用python从xls坐标文件中生成面要素

#根据xls文件生成图形数据,并赋值其它属性信息
# coding:utf8
import arcpy
import xlrd
 
arcpy.env.workspace = r"F:\test.gdb"
fc = "polygon"
cursor = arcpy.da.InsertCursor(fc, ["字段1", "字段2", "字段3", "SHAPE@"])
xlsfile = xlrd.open_workbook(r"F:\test.xls", "r")
mysheet1 = xlsfile.sheet_by_name("sheet1")
polygonarray = arcpy.Array()
rownum = mysheet1.nrows
colnum = mysheet1.ncols
fid = ""
count = 0
ismark = False
i = 0
try:
    for i in range(rownum):
        row = mysheet1.row_values(i)
        flowsn = row[1]
        if fid == "":
            fid = int(row[0])
        xmmc = row[2]
        bh = int(row[3])
        x = row[4]
        y = row[5]
        iswk = row[6]
        pnt = arcpy.Point()
        pnt.ID = bh
        pnt.X = x
        pnt.Y = y
        if fid == row[0]:
            if iswk == 1:
                polygonarray.add(pnt)
            else:
                if ismark:
                    polygonarray.add(pnt)
                else:
                    polygonarray.add(arcpy.Point())
                    ismark = True
                    polygonarray.add(pnt)
            if i == rownum - 1:
                poly = arcpy.Polygon(polygonarray)
                cursor.insertRow([fid, flowsn, xmmc, poly])
                print "要素{0}已经生成".format(fid)
                count = count + 1
                polygonarray.removeAll()
                ismark = False
        else:
            nfid = int(row[0])
            poly = arcpy.Polygon(polygonarray)
            row = mysheet1.row_values(i - 1)
            flowsn = row[1]
            xmmc = row[2]
            fid = int(row[0])
            cursor.insertRow([fid, flowsn, xmmc, poly])
            print "要素{0}已经生成".format(fid)
            count = count + 1
            polygonarray.removeAll()
            polygonarray.add(pnt)
            fid = nfid
            ismark = False
except Exception as e:
    print e.message
if cursor:
    del cursor
print "共生成要素{0}个".format(count)
 

转载于:https://www.cnblogs.com/apromise/p/10021773.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值