使用arcpy对shp文件进行操作
将某一文件夹下的shp文件全部加载:
import arcpy
mxd = arcpy.mapping.MapDocument(r"D:\tes\Operation.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
# set workspace to directory of interest
arcpy.env.workspace = r"D:\data"
# create list of all files ending in .shp
list_shapefiles = arcpy.ListFiles("*.shp")
targetGroupLayer = arcpy.mapping.ListLayers(mxd, "Actual", df)[0]
# loop through list, adding each shapefile to group layer
for shapefile in list_shapefiles:
addLayer = shapefile
arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, addLayer, "TOP")
mxd.saveACopy(r"D:\tes\Operation_2.mxd")
python结合Arcpy处理EXCEL数据生成多边形
import xlrd
import xlwt
import arcpy
xlsPath = r"C:\Users\Administrator\Desktop\Polygon.xls"
data = xlrd.open_workbook(xlsPath)
table = data.sheets()[0]#通过索引顺序获取
cols = table.col_values(5)
nrows = table.nrows
point = arcpy.Point()
array = arcpy.Array()
polygonGeometryList = []
for i in range(1,nrows):
str = table.cell(i,5).value
points = str.split(u';')
for j in points:
xy = j.split(',')
print xy[0]
print xy[1]
print '\n'
point.X = float(xy[0]);point.Y = float(xy[1])
array.add(point)
polygon = arcpy.Polygon(array)
polygonGeometryList.append(polygon)
array.removeAll()
arcpy.CopyFeatures_management(polygonGeometryList, "d:\\polygon.shp")
print 'over'
转载自:https://blog.csdn.net/x5675602/article/details/88012680