I want to convert some json data being returned from a request to a feature class, but I keep getting a RuntimeError: Object: Error in executing tool
. I made a test gdb in a folder 'C:/Workspace/Sandbox/ScratchTests/cslf.gdb' in which to populate my new feature class after conversion. To test that the request is correct and that I am returning Json data, I added a couple of print statements. Otherwise, everything is pretty straight forward. Does anyone see a problem with my code? I am following the arcpy [JSON to Features][1] directions from the documentation. The only thing I am doing differently is instead of using an actual file, I am just plugging in the variable 'cslfJson`.
import arcpy, sys, os, arcgis, requests
arcpy.env.workspace = "C:/Workspace/Sandbox/ScratchTests"
params = {'f': 'json', 'where': '1=1', 'geometryType': 'esriGeometryPolygon', 'spatialRel': 'esriSpatialRelIntersects','outFields': '*', 'returnGeometry': 'false'}
r = requests.get('https://hazards.fema.gov/gis/nfhl/rest/services/CSLF/Prelim_CSLF/MapServer/3/query', params)
print(r.url)
cslfJson = r.json()
print(cslfJson)
arcpy.JSONToFeatures_conversion(cslfJson, os.path.join("cslf.gdb", "cslf"))
Also, Here's the Traceback:
https://hazards.fema.gov/gis/nfhl/rest/services/CSLF/Prelim_CSLF/MapServer/3/query?f=json&where=1%3D1&geometryType=esriGeometryPolygon&spatialRel=esriSpatialRelIntersects&outFields=%2A&returnGeometry=false Traceback (most recent call last):
File "", line 1, in runfile('C:/Workspace/Sandbox/ScratchTests/CSLF.py', wdir='C:/Workspace/Sandbox/ScratchTests')
File "C:\Users\jbridwell\AppData\Local\Continuum\anaconda3\envs\acrpro\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 668, in runfile execfile(filename, namespace)
File "C:\Users\jbridwell\AppData\Local\Continuum\anaconda3\envs\acrpro\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Workspace/Sandbox/ScratchTests/CSLF.py", line 20, in arcpy.JSONToFeatures_conversion(cslfJson, os.path.join("cslf.gdb", "cslf"))
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\conversion.py", line 403, in JSONToFeatures raise e
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\conversion.py", line 400, in JSONToFeatures retval = convertArcObjectToPythonObject(gp.JSONToFeatures_conversion(*gp_fixargs((in_json_file, out_features), True)))
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing_base.py", line 506, in return lambda *args: val(*gp_fixargs(args, True))
RuntimeError: Object: Error in executing tool
[1]: http://desktop.arcgis.com/en/arcmap/10.3/tools/conversion-toolbox/json-to-features.htm
2 Answers 2
Be sure to have the latest ArcGIS PRO patch release (2.2.1)
There were known issues in previous releases dealing with JSON conversions.
- BUG-000115464
GeoJSON to Features crashes ArcGIS Pro at GPCoreFunctions!Bucket_JSON2F::UnionProperties (gpesrijsontofeaturesfunction.cpp @ 1029).
- BUG-000110564
The Key Metadata function fails to run a JSON Metadata String in ArcGIS Pro, even with a valid input.
these BUGS are not limited to your issue but will affect your processing. Implement the patch and see if it clears the problem.
I was actually able to get this to work without updating to 2.2. Essentially, I had to turn the json data into a physical file in order for it to work. This is a little cumbersome, but as the file should get overwritten each time I run the script (as the REST service data is updated) it should be fine. I just added a part at then end to open a file and then write to that file, then use the newly created json file in JSONToFeatures_conversion:
cslfJson = r.json()
path = r"C:/Workspace/Sandbox/ScratchTests/cslf.json"
with open(path, 'w') as f:
json.dump(cslfJson, f, indent=2)
arcpy.JSONToFeatures_conversion("cslf.json", os.path.join("cslf.gdb", "cslf"))
RuntimeError: Object: Error in executing tool
. See the Traceback for details.