说明:现实中可能获取了很多存在excel中的点坐标信息,当需要获取shape文件时,常规的方法是通过arcgis中add XY,生成event图层,然后导出为shape的点文件,
如果需要再生成line或者polygon则需要其他的工具。比较繁琐,基于此,本代码实现批处理的有excel转为Polygon文件。
# -*- coding: utf-8 -*-
import arcpy
# Local variables:
InputFileDir ="E:/test/BP/1PointExcelFile/";
OutputShapelineDir = "E:/test/BP/2Shapeline/"
OutputShapePolygonDir = "E:/test/BP/3ShapePolygon/"
spRef = "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]];-400 -400 1000000000;-100000 10000;-100000 10000;8.98315284119522E-09;.001;.001;IsHighPrecision";
arcpy.CheckOutExtension("Spatial")
arcpy.env.workspace=InputFileDir
filelist=arcpy.ListFiles("*.xls")
print "Total File Num: "+str(len(filelist))
flag=1;
for inputExcelFile in filelist:
print "Total:" +str(len(filelist)) +" Current:"+str(flag) +" Filename:" +inputExcelFile; flag=flag+1;
InputExcelSheet=InputFileDir+str(inputExcelFile)+"/Sheet1$"
EventLayer = "Sheet1$_Layer"
OutputShapelineName = OutputShapelineDir+str(inputExcelFile)[0:-4]+".shp";
OutputShapePolygonName=OutputShapePolygonDir+str(inputExcelFile)[0:-4]+".shp";
# # 1 Process: Make XY Event Layer
arcpy.MakeXYEventLayer_management(InputExcelSheet, "x", "y", EventLayer,spRef, "")
# # 2 point to line
arcpy.PointsToLine_management(EventLayer , OutputShapelineName , "", "")
# # 3 line to polygon
arcpy.FeatureToPolygon_management(OutputShapelineName,OutputShapePolygonName,"","NO_ATTRIBUTES", "" )
print "OK! "