arcpy support for JSON strings

1020
2
10-18-2018 09:37 AM
Status: Open
Labels (1)
EricEagle
Occasional Contributor III

As far as I'm aware the arcpy.JSONToFeatures_conversion utility only takes a flat file, e.g., your-json-file.json sitting in a directory.

 

I would like to suggest that this utility provide support for strings embedded right in one's script instead of having to summon os and mess with paths.  So basically instead of:

 

import arcpy

import os

file = your_file.json

path = r"C:\Temp"

json_file = os.path.join(path, file)

arcpy.JSONToFeatures(json_fileaaaaahhhhh just makes my head hurt writing it)

 

 

it should be like this:

 

import arcpy

json = { bunch of json/geojson }

arcpy.JSONToFeatures(json, output)

 

 

Currently, the second approach throws a series of GP errors as it does not appear the tool is set up to handle strings but only files.

2 Comments
EricEagle

I just want to add that because of this limitation, I am doing the following extremely dubious workflow -

I am doing an automatic "project this raster to the correct UTM zone" script that is meant to be a part of a larger model run by many users with varying levels of connectivity to data.

So, in the script I put the entire UTM grid in geojson, perfect use case for a geojson string, nobody has to worry about external files, I should be able to simply spatially join the extracted raster geometry (center point) to the grid, keep only common, and read the attributes for the containing zone.  Right?

Currently I have to take that text, dump it to a file on the user's temp directory, then re-read the file in, and convert it to a feature. (facepalm)

by Anonymous User

I think this would help alleviate a lot of frustrations and very unnecessary IO operations to disk.