RuntimeError: Object: CreateObject cannot create geometry from inputs

3186
2
Jump to solution
10-31-2017 08:11 AM
DevonCanady
New Contributor II

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)

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

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))

View solution in original post

0 Kudos
2 Replies
JoshuaBixby
MVP Esteemed Contributor

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))
0 Kudos
DevonCanady
New Contributor II

Yep! Thanks

0 Kudos