2

In ArcPy, I want to use JSONToFeatures_conversion, but I'm working with data that I pulled from a web service. I have no need to save the data to disk. So, I thought I could do something like this:

fd = StringIO.StringIO(<my JSON string>)
arcpy.JSONToFeatures_conversion(fd, 'in_memory\\output')

arcpy definitely doesn't like that though. I'm considering using the tempfile module, but that's not an ideal solution for this. Temp files aren't really a good solution for this because of a few factors, from environmental constraints (permissions in some of the environments where it may run) to the size of the datasets (IO overhead).

doing this:

fs = arcpy.FeatureSet()
fs.load(<url to service>)

Isn't exactly ideal either because the dataset is composed of data from a couple sources, with different attributes that have to be reconciled.

Ultimately, the product of this operation will be passed in to arcpy.SelectLayerByLocation_management as the select_features parameter

Environment: ArcGIS 10.x (multiple machines running slightly different versions, but none of it's ArcPro, hence all Python2 not Python3)

  • 3
    The in_memory object is a table emulator; it does not support files. Creating temp files/folders in a GP service is trivial, and Server will clean them up after the process finishes execution. – Vince Apr 11 at 22:24
  • 2
    You could also have a look at arcpy.AsShape, but it only supports individual geometries, not features or feature collections, i.e. {"type": "PointLineOrPolygon", "coordinates": [etc...]} – user2856 Apr 11 at 23:16
  • Thanks, but temp files really aren't ideal for this. I tried arcpy.AsShape, but the output is a featureset, and can't be passed into later processing tools such as arcpy.SelectLayerByLocation_management – Charlie Elverson Apr 11 at 23:55
  • Does copy features work on feature set? – FelixIP Apr 12 at 0:36
  • 1
    AsShape returns a geometry object and you can use CopyFeatures on a list of geometries. Or if you have other info in the json aside from the coordinates then store those that a separate list and use a cursor to insert them into a feature class – mikewatt Apr 12 at 0:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.