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

Posted A Promise

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用python从xls坐标文件中生成面要素相关的知识,希望对你有一定的参考价值。

#根据xls文件生成图形数据,并赋值其它属性信息
# coding:utf8
import arcpy
import xlrd
 
arcpy.env.workspace = r"F: est.gdb"
fc = "polygon"
cursor = arcpy.da.InsertCursor(fc, ["字段1", "字段2", "字段3", "[email protected]"])
xlsfile = xlrd.open_workbook(r"F: est.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)
 

以上是关于使用python从xls坐标文件中生成面要素的主要内容,如果未能解决你的问题,请参考以下文章

如何在 zip 文件中生成 xls 文件并将其发送到电子邮件以在那里下载 - groovy [关闭]

从坐标文件mdb中生成图形_批量

跪求:在ARCGIS中,如何将若干个点转成线,或者转成面

使用python在极坐标中生成一条直线

如何导出SHP文件中的点坐标

使用 pandas [Python] 提取 xls 文件后如何从输出中删除编号