#polylineList 对线的转换
def handlePolyline(db):
fcList = arcpy.ListFeatureClasses(feature_type='Polyline')
for fc in fcList:
fieldList = arcpy.ListFields(fc)
fields = [field.name for field in fieldList]
fields.pop()
fields.append("SHAPE@")
lines=db[fc]
with arcpy.da.SearchCursor(fc, fields) as cursor:
print 'Handling '+fc
for row in cursor:
line={}
i=0
for value in row:
if(isinstance(value,arcpy.Polyline)):
loc={"type" : "LineString"}
coordinates=[]
for path in value:
for point in path:
coordinates.append([point.X,point.Y])
loc['coordinates']=coordinates
line['line']=loc
else:
line[fields]=value
i=i+1
lines.insert(line)
#pointList 对点的转换
def handlePoint(db):
fcList = arcpy.ListFeatureClasses(feature_type='Point')
for fc in fcList:
fieldList = arcpy.ListFields(fc)
fields = [field.name for field in fieldList]
fields.pop()
fields.append("SHAPE@")
points=db[fc]
with arcpy.da.SearchCursor(fc, fields) as cursor:
print 'Handling '+fc
for row in cursor:
pointfc={}
i=0
for value in row:
if(isinstance(value,arcpy.PointGeometry)):
loc={"type" : "Point"}
loc['coordinates']=[value.firstPoint.X,value.firstPoint.Y]
pointfc['point']=loc
else:
pointfc[fields]=value
i=i+1
points.insert(pointfc)