I cannot seem to create a geometry using a list of coordinates. I'm parsing these coordinates from a JSON object, which I have successfully tested, but from the documentation it seems this should work once I have a double to input. Here is another similar example.
import arcpy, json
jsonObj = """{
"points": [
{
"Y": 35.631453769591765,
"X": -97.586939334869385
},
{
"Y": 35.628907432142576,
"X": -97.587132453918457
},
{
"Y": 35.627703997864323,
"X": -97.589900493621826
},
{
"Y": 35.630180611005642,
"X": -97.590758800506592
},
{
"Y": 35.630302695584653,
"X": -97.5909948348999
},
{
"Y": 35.631453769591765,
"X": -97.586939334869385
}
],
"spatialReference": {
"wkid": 4326
}
}"""dictionary = json.loads(jsonObj)
#the Polygon method fails whether I input a list of Points or PointGeometries
coordsList = []
for items in dictionary["points"]:
pt = arcpy.Point(items["X"], items["Y"])
coordsList.append(arcpy.PointGeometry(pt, arcpy.SpatialReference(4326)))
geometry = arcpy.Polygon(coordsList, arcpy.SpatialReference(4326)) #fails here# arcpy.CopyFeatures_management(geometry, FILEPATH)
Solved! Go to Solution.
You are close, try this:
import arcpy, json
jsonObj = """{
"points": [
{
"Y": 35.631453769591765,
"X": -97.586939334869385
},
{
"Y": 35.628907432142576,
"X": -97.587132453918457
},
{
"Y": 35.627703997864323,
"X": -97.589900493621826
},
{
"Y": 35.630180611005642,
"X": -97.590758800506592
},
{
"Y": 35.630302695584653,
"X": -97.5909948348999
},
{
"Y": 35.631453769591765,
"X": -97.586939334869385
}
],
"spatialReference": {
"wkid": 4326
}
}"""
dictionary = json.loads(jsonObj)
coordsList = arcpy.Array()
for items in dictionary["points"]:
pt = arcpy.Point(items["X"], items["Y"])
coordsList.append(pt)
geometry = arcpy.Polygon(coordsList, arcpy.SpatialReference(4326))
You are close, try this:
import arcpy, json
jsonObj = """{
"points": [
{
"Y": 35.631453769591765,
"X": -97.586939334869385
},
{
"Y": 35.628907432142576,
"X": -97.587132453918457
},
{
"Y": 35.627703997864323,
"X": -97.589900493621826
},
{
"Y": 35.630180611005642,
"X": -97.590758800506592
},
{
"Y": 35.630302695584653,
"X": -97.5909948348999
},
{
"Y": 35.631453769591765,
"X": -97.586939334869385
}
],
"spatialReference": {
"wkid": 4326
}
}"""
dictionary = json.loads(jsonObj)
coordsList = arcpy.Array()
for items in dictionary["points"]:
pt = arcpy.Point(items["X"], items["Y"])
coordsList.append(pt)
geometry = arcpy.Polygon(coordsList, arcpy.SpatialReference(4326))
Yep! Thanks