AnsweredAssumed Answered

Need help with creating a Polygon from JSON

Question asked by jread79 on May 7, 2019
Latest reply on May 7, 2019 by jread79

I am using a Python script to query an ArcGIS Online feature service, and then I want to create records in an on-premise feature class based on the results. I've done this many, many times with point features, but never with polygon features. I cannot seem to figure out how to create a polygon shape from the JSON parameters (coordinates/rings).

 

for feat in agolQueryJson['features']:
   feature_coords = feat['geometry']['rings']

 

For the first record, the value of feature_coords is as follows:

 

 

[[[3119080.82716037, 10062393.2323891], [3119167.33715791, 10062378.1910806], [3119165.12029902, 10062150.6820212], [3119136.04194509, 10062115.4521047], [3119109.98523858, 10062106.2047479], [3119106.03478733, 10062060.0765594], [3119080.82716037, 10062393.2323891]], [[3119080.82716037, 10062393.2323891], [3119079.78123078, 10062393.4141472], [3119079.72545653, 10062407.7937117], [3119080.82716037, 10062393.2323891]]]

 

I have not figured out how to take this and turn it into a polygon shape that can be used in an insert cursor. I've tried using arcpy.AsShape and just arcpy.Polygon, but no luck with either method:

 

poly = arcpy.AsShape(feature_coords)

 

poly = arcpy.Polygon(arcpy.Array([arcpy.Point(*coords) for coords in feature_coords]))

 

Any suggestions would be most appreciated!

Outcomes