清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
#coding:utf-8 import arcpy from arcpy import env env.workspace = 'g:/python' ## 设置工作空间 file = open('11.txt') ## 读取text文件 def create_polygon(coord_l): point = arcpy.Point() array = arcpy.Array() featureList = [] for feature in coord_l: for coord in feature: point.X = coord[0] point.Y = coord[1] array.add(point) array.add(array.getObject(0)) polygon = arcpy.Polygon(array) array.removeAll() featureList.append(polygon) return featureList li = [] for line in file: li.append(map(float,line.split())) ##将坐标导入列表 coord_l = [] code_l = [] for i in range(len(li)): if len(li[i]) == 2: code_l.append(str(int(li[i][0]))+str(int(li[i][1]))) coord_l.append([]) else: coord_l[len(coord_l)-1].append([li[i][1],li[i][2]]) poly = create_polygon(coord_l) arcpy.CopyFeatures_management(poly,'g:/python/polygons.shp') ##设置生成的shp文件名 arcpy.AddField_management('polygons.shp','code','TEXT') cur = arcpy.UpdateCursor('polygons.shp') i = 0 for row in cur: row.code = code_l[i] cur.updateRow(row) i = i + 1 del cur,row