创建面几何

import re,arcpy
from arcpy import env
env.overwriteOutput=True
path=''
env.workspace=path
TXTlst=arcpy.ListFiles('*.txt')
coordidic={}
for txt in TXTlst:
    n=txt.split('.')[0]
    reader=open(path+'\\'+txt)
    pat=re.compile('^<coordinates>$')
    while True:
        line=reader.readline()
        if len(line)==0:
            break
        line=line.strip()
        m=pat.match(line)
        if m:
            corstr=reader.readline()
            corstr=corstr.strip()
    reader.close()
    coordilst=corstr.split(' ')
    coordif=[]
    for s in coordilst:
        xyz=s.split(',')
        xyz=[float(a) for a in xyz]
        coordif.append(xyz)
    coordidic.setdefault(n,coordif)
fc='BJGreen'
prjFile='WGS 1984.prj'
nlst=coordidic.keys()
array=arcpy.Array()
arcpy.CreateFeatureclass_management(path,fc,'Polygon')
arcpy.AddField_management(fc,'Name','TEXT',9,'','','Name','NULLABLE','REQUIRED')
cursor=arcpy.da.InsertCursor(fc,['SHAPE@','Name'])
for n in nlst:
    dic=coordidic[n]
    pointA=arcpy.Array([arcpy.Point(*coords) for coords in dic])
    pl=arcpy.Polygon(pointA,SpatialRef)
    print(pl.length)
    cursor.insertRow([pl,n])
del cursor

上一篇:1411. 给 N x 3 网格图涂色的方案数


下一篇:一些重要的非常棒的畅游宇宙的网站