FeatureSet() .load Cannot open table for Load

579
5
Jump to solution
07-17-2019 11:13 AM
JamesCrandall
MVP Frequent Contributor

I've got the results of a map service query urlib2.Request setup as 

jsonResult = json.load(response)

From this I am attempting to setup an in_memory FeatureSet() but it is failing when fs.load(jsronResult) with "RuntimeError: RecordSetObject: Cannot open table for Load".

The odd thing is this works if I write the jsonResult to a local .json file and then issue arcpy.JSONToFeatures_conversion() with the same exact contents as the jsonResult payload.

Anyone have similar scenario?  Must be something simple I'm missing here.


Thanks!

qryLandUseURL = 'https://SomeAGSurl/MapServer/0/query'

qryLandUseParams = urllib.urlencode({'f': 'pjson','geometryType': 'esriGeometryPolygon','geometry': inGeometry,'spatialRel': 'esriSpatialRelIntersects','outFields': flds,'returnGeometry': 'true'})

qryLandUseReq = urllib2.Request(qryLandUseURL, qryLandUseParams)

response = urllib2.urlopen(qryLandUseReq)
jsonResult = json.load(response)

fs = arcpy.FeatureSet()
fs.load(jsonResult)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Edit: my original implementation works when I set the fs.load() to the url of the map service like this:

rquery = "?where={}&outFields={}&returnGeometry=true&f=json".format(rwhere, rflds)
rqueryfsURL = rtaburl + rquery
rfs = arcpy.FeatureSet()
rfs.load(rqueryfsURL)

But I need it to have an input geometry and spatialRel type instead of a simple WHERE clause.

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

Try:

fs = arcpy.AsShape(jsonResult, True) 

View solution in original post

5 Replies
JoshuaBixby
MVP Esteemed Contributor

Try:

fs = arcpy.AsShape(jsonResult, True) 

View solution in original post

JamesCrandall
MVP Frequent Contributor

Huge amt of thank you on this one.  I was way off track for a good workaround, saved me bigtime.

0 Kudos
JamesCrandall
MVP Frequent Contributor

Odd.  The script works when I step thru it.  Fails if I simply run it from start-to-finish.  When stepping thru the code in the IDE, it correctly sets:

rfs = arcpy.AsShape(jsonResult, True)

And the feature layer that is generated contains features (resultfl > 0):

arcpy.MakeFeatureLayer_management(rfs,landuseFL)
resultlfl = arcpy.GetCount_management(landuseFL)
However, when I simply execute the script, the resultfl count = 0
Full def:
qryLandUseURL = 'https://myAGSsite/MapServer/0/query'
qryLandUseParams = urllib.urlencode({'f': 'pjson',
'geometryType': 'esriGeometryPolygon',
'geometry': inGeometry,
'spatialRel': 'esriSpatialRelIntersects',
'outFields': outFlds,
'returnGeometry': 'true'
})

qryLandUseReq = urllib2.Request(qryLandUseURL, qryLandUseParams)
response = urllib2.urlopen(qryLandUseReq)
jsonResult = json.load(response)
rfs = arcpy.AsShape(jsonResult, True)

landuseFL = os.path.join('in_memory','flLanduse')
arcpy.MakeFeatureLayer_management(rfs,landuseFL)
resultlfl = arcpy.GetCount_management(landuseFL)
0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Put some print statements to see which step is messing up.

JamesCrandall
MVP Frequent Contributor

Instead of creating FeatureLayer from the AsShape result, I specified it in a CopyFeatures_management and output to in_memory instead and it likes it.

jsonResult = json.load(response)

rfs = arcpy.AsShape(jsonResult, True)

fc = arcpy.CopyFeatures_management(rfs, r'in_memory\flLanduse')

0 Kudos