pfoppe

arcpy.FeatureSet - Missing (truncated) JSON result

Discussion created by pfoppe on May 28, 2013
Latest reply on Nov 22, 2017 by nheick
I am having a problem using the arcpy.FeatureSet() method to load a polyline to a JSON structure (python Dictionary).  It seems that if features were constructed using 'freehand' that the arcpy.FeatureSet().JSON that the 'paths' key returns a truncated, incomplete list.  Any support is greatly appreciated.  Details below:

Testing from an ArcGIS Desktop 10.1 SP1

Scenario 1 - Works:
Basic Steps:

  • Start Editing

  • Open 'Create Features' frame

  • Choose 'Line' under 'Construction Tools'

  • Draw a simple line with few verticies

  • Select the Line

  • view the JSON from arcpy.FeatureSet(input).JSON

  • JSON looks complete


>>> import json
>>> arcpy.FeatureSet('complexfeatures').JSON
u'{"displayFieldName":"","fieldAliases":{"OBJECTID":"OBJECTID","ASSET_NUM":"ASSET_NUM","PROVIDER":"PROVIDER","CREATED_USER":"CREATED_USER","CREATED_DATE":"CREATED_DATE","LAST_EDITED_USER":"LAST_EDITED_USER","LAST_EDITED_DATE":"LAST_EDITED_DATE","Shape_Length":"Shape_Length"},"geometryType":"esriGeometryPolyline","spatialReference":{"wkid":4269,"latestWkid":4269},"fields":[{"name":"OBJECTID","type":"esriFieldTypeOID","alias":"OBJECTID"},{"name":"ASSET_NUM","type":"esriFieldTypeString","alias":"ASSET_NUM","length":12},{"name":"PROVIDER","type":"esriFieldTypeString","alias":"PROVIDER","length":50},{"name":"CREATED_USER","type":"esriFieldTypeString","alias":"CREATED_USER","length":255},{"name":"CREATED_DATE","type":"esriFieldTypeDate","alias":"CREATED_DATE","length":8},{"name":"LAST_EDITED_USER","type":"esriFieldTypeString","alias":"LAST_EDITED_USER","length":255},{"name":"LAST_EDITED_DATE","type":"esriFieldTypeDate","alias":"LAST_EDITED_DATE","length":8},{"name":"Shape_Length","type":"esriFieldTypeDouble","alias":"Shape_Length"}],"features":[{"attributes":{"OBJECTID":30,"ASSET_NUM":null,"PROVIDER":null,"CREATED_USER":null,"CREATED_DATE":null,"LAST_EDITED_USER":null,"LAST_EDITED_DATE":null,"Shape_Length":0.36837905314970948},"geometry":{"paths":[[[-108.05333952499996,32.113163973000042],[-107.92771386599998,32.035043815000051],[-107.96677394499994,31.967480436000073],[-108.10401205899996,31.92947603500005]]]}}]}'

>>> json.loads(arcpy.FeatureSet('complexfeatures').JSON)
{u'features': [{u'geometry': {u'paths': [[[-108.05333952499996, 32.11316397300004], [-107.92771386599998, 32.03504381500005], [-107.96677394499994, 31.967480436000073], [-108.10401205899996, 31.92947603500005]]]}, u'attributes': {u'Shape_Length': 0.3683790531497095, u'OBJECTID': 30, u'PROVIDER': None, u'ASSET_NUM': None, u'CREATED_USER': None, u'CREATED_DATE': None, u'LAST_EDITED_DATE': None, u'LAST_EDITED_USER': None}}], u'fieldAliases': {u'Shape_Length': u'Shape_Length', u'OBJECTID': u'OBJECTID', u'PROVIDER': u'PROVIDER', u'ASSET_NUM': u'ASSET_NUM', u'CREATED_USER': u'CREATED_USER', u'CREATED_DATE': u'CREATED_DATE', u'LAST_EDITED_DATE': u'LAST_EDITED_DATE', u'LAST_EDITED_USER': u'LAST_EDITED_USER'}, u'fields': [{u'alias': u'OBJECTID', u'type': u'esriFieldTypeOID', u'name': u'OBJECTID'}, {u'alias': u'ASSET_NUM', u'length': 12, u'type': u'esriFieldTypeString', u'name': u'ASSET_NUM'}, {u'alias': u'PROVIDER', u'length': 50, u'type': u'esriFieldTypeString', u'name': u'PROVIDER'}, {u'alias': u'CREATED_USER', u'length': 255, u'type': u'esriFieldTypeString', u'name': u'CREATED_USER'}, {u'alias': u'CREATED_DATE', u'length': 8, u'type': u'esriFieldTypeDate', u'name': u'CREATED_DATE'}, {u'alias': u'LAST_EDITED_USER', u'length': 255, u'type': u'esriFieldTypeString', u'name': u'LAST_EDITED_USER'}, {u'alias': u'LAST_EDITED_DATE', u'length': 8, u'type': u'esriFieldTypeDate', u'name': u'LAST_EDITED_DATE'}, {u'alias': u'Shape_Length', u'type': u'esriFieldTypeDouble', u'name': u'Shape_Length'}], u'displayFieldName': u'', u'spatialReference': {u'wkid': 4269, u'latestWkid': 4269}, u'geometryType': u'esriGeometryPolyline'}


Notice how the 'paths' key in the JSON struct appears to be correct.  Shows 4 simple XY verticies that were hand digitized on the map.  I can also use the json module to load the string (json.loads) correctly into a pyton dict.

Scenario 2 - Fails:
Basic Steps:

  • Start Editing

  • Open 'Create Features' frame

  • Choose 'Freehand' under 'Construction Tools'

  • Draw a 's' shaped feature

  • Select the Line

  • view the JSON from arcpy.FeatureSet(input).JSON

  • JSON is malformed and missing the 'paths' elements...


>>> import json
>>> 
>>> arcpy.FeatureSet('complexfeatures').JSON
u'{"displayFieldName":"","fieldAliases":{"OBJECTID":"OBJECTID","ASSET_NUM":"ASSET_NUM","PROVIDER":"PROVIDER","CREATED_USER":"CREATED_USER","CREATED_DATE":"CREATED_DATE","LAST_EDITED_USER":"LAST_EDITED_USER","LAST_EDITED_DATE":"LAST_EDITED_DATE","Shape_Length":"Shape_Length"},"geometryType":"esriGeometryPolyline","spatialReference":{"wkid":4269,"latestWkid":4269},"fields":[{"name":"OBJECTID","type":"esriFieldTypeOID","alias":"OBJECTID"},{"name":"ASSET_NUM","type":"esriFieldTypeString","alias":"ASSET_NUM","length":12},{"name":"PROVIDER","type":"esriFieldTypeString","alias":"PROVIDER","length":50},{"name":"CREATED_USER","type":"esriFieldTypeString","alias":"CREATED_USER","length":255},{"name":"CREATED_DATE","type":"esriFieldTypeDate","alias":"CREATED_DATE","length":8},{"name":"LAST_EDITED_USER","type":"esriFieldTypeString","alias":"LAST_EDITED_USER","length":255},{"name":"LAST_EDITED_DATE","type":"esriFieldTypeDate","alias":"LAST_EDITED_DATE","length":8},{"name":"Shape_Length","type":"esriFieldTypeDouble","alias":"Shape_Length"}],"features":[{"attributes":{"OBJECTID":31,"ASSET_NUM":null,"PROVIDER":null,"CREATED_USER":null,"CREATED_DATE":null,"LAST_EDITED_USER":null,"LAST_EDITED_DATE":null,"Shape_Length":0.31265287393441688},"geometry":{"paths":['

>>> json.loads(arcpy.FeatureSet('complexfeatures').JSON)
Runtime error 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Python27\ArcGIS10.1\Lib\json\__init__.py", line 326, in loads
    return _default_decoder.decode(s)
  File "C:\Python27\ArcGIS10.1\Lib\json\decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python27\ArcGIS10.1\Lib\json\decoder.py", line 382, in raw_decode
    obj, end = self.scan_once(s, idx)
ValueError: Expecting object: line 1 column 1259 (char 1259)


Notice how the 'paths' value does not contain a valid array?

I have the same problem if I try to declare the FeatureSet empty and load it using something like:
fs=arcpy.FeatureSet()
fs.load(in_features)

Outcomes