问题描述
通常利用arcpy向面矢量添加面数据的方法如下
import arcpy
singlePolygon = [[86.30491319444444, 31.08521484375], [86.30491427951388, 31.08521484375], [86.30491427951388, 31.085215928819444], [86.30491319444444, 31.085215928819444],[86.30491319444444, 31.08521484375]]
Polygonshp=arcpy.CreateFeatureclass_management(arcpy.env.scratchGDB,"ToPOLYGON","POLYGON","","","",spatial_reference=4490)
with arcpy.da.InsertCursor(Polygonshp,["SHAPE@"]) as cursor:
array = arcpy.Array()
for pt in singlePolygon:
point = arcpy.Point()
point.X = pt[0]
point.Y = pt[1]
array.append(point)
polygon = arcpy.Polygon(array)
cursor.insertRow([polygon])
解决方案
使用WKT、WKB、CoordString、Geohash或者geojson/EsriJson去构建面几何,然后再利用游标插入面矢量中
WKT
import arcpy
coordinatesstr ="POLYGON((86.30491319444444 31.08521484375, 86.30491427951388 31.08521484375, 86.30491427951388 31.085215928819444, 86.30491319444444 31.085215928819444, 86.30491319444444 31.08521484375))"
result = arcpy.management.CreateFeatureclass(
arcpy.env.scratchGDB, "wktToPOLYGON", "POLYGON", spatial_reference=4490
)
feature_class = result[0]
with arcpy.da.InsertCursor(feature_class, ["SHAPE@"]) as cursor:
cursor.insertRow([arcpy.FromWKT(coordinatesstr)])
Geojson/EsriJson
import arcpy
coordinates = [[86.30491319444444, 31.08521484375], [86.30491427951388, 31.08521484375], [86.30491427951388, 31.085215928819444], [86.30491319444444, 31.085215928819444]]
coordinatesstr ="POLYGON((86.30491319444444 31.08521484375, 86.30491427951388 31.08521484375, 86.30491427951388 31.085215928819444, 86.30491319444444 31.085215928819444, 86.30491319444444 31.08521484375))"
geojson_polygon = {
"type": "Polygon",
"coordinates": [
coordinates]}
polygon = arcpy.AsShape(geojson_polygon)
result = arcpy.management.CreateFeatureclass(
arcpy.env.scratchGDB, "esriJsonToPOLYGON", "POLYGON", spatial_reference=4326
)
feature_class = result[0]
with arcpy.da.InsertCursor(feature_class, ["SHAPE@"]) as cursor:
cursor.insertRow([polygon])
参考文献
AsShape—ArcGIS Pro |文档
FromWKT—ArcGIS Pro | Documentation