arcpy.FeatureSet - Missing (truncated) JSON result

3845
5
05-28-2013 09:07 AM
PF1
by
Occasional Contributor II
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)
Tags (2)
5 Replies
PF1
by
Occasional Contributor II
In addition - I can still describe the feature using a simple SearchCursor:


>>> sc=arcpy.SearchCursor("complexfeatures")
>>> row=sc.next()
>>> row.SHAPE.JSON
u'{"paths":[[[-107.73663618399996,32.118442362000053],[-107.73884077039791,32.119504690926618],[-107.74105642221301,32.120527416729146],... <Removed for length> ]]],"spatialReference":{"wkid":4269}}'
>>> 
>>> json.loads(row.SHAPE.JSON)
{u'paths': [[[-107.73663618399996, 32.11844236200005], [-107.73884077039791, 32.11950469092662], [-107.741056422213, 32.120527416729146], [-107.74328313944785, 32.12151053940891], [-107.74552092210487, 32.12245405896694], [-107.74776977018637, 32.1233579754042], [-107.75002968369428, 32.12422228872146], [-107.75230066263127, 32.12504699891979], [-107.75458270699994, 32.125832106000075], [-107.75659821899549, 32.12652689818116], [-107.75890406515417, 32.12736096534411], [-107.7666821019275, 32.13028862152029], [-107.76958348743116, 32.131359269059764], [-107.77228464403181, 32.13231601581619], [-107.77473470999132, 32.13313605229926], [-107.77626089730433, 32.133617955489875], [-107.77772344080708, 32.1340552612864], [-107.77913117752215, 32.13445060766041], [-107.78048977721855, 32.134805580023084], [-107.78180549588528, 32.135121762264916], [-107.78308006205398, 32.135399516422645], [-107.78431635157999, 32.135639467773984], [-107.78551650304402, 32.13584202945609], [-107.78682130311263, 32.13602504846348], [-107.78808506738325, 32.13616175389723], [-107.78930956314306, 32.13625233583096], [-107.79049616390569, 32.13629689444882], [-107.79164633087659, 32.136295469626624], [-107.79276078276014, 32.136248044824185], [-107.79384039381608, 32.13615458225699], [-107.79488587568524, 32.1360150196027], [-107.79589885597944, 32.135829063924575], [-107.79687881627672, 32.135596732116255], [-107.79782624013392, 32.135317909177175], [-107.79874153209693, 32.13499247562364], [-107.79962511107819, 32.13462027716119], [-107.80047723427302, 32.13420119986392],...<Removed for length>]], u'spatialReference': {u'wkid': 4269}}
0 Kudos
RamiGhali2
New Contributor II

Hi Patrick,

I'm having the same issue. Have you reached any solution or workaround ?

Regards.

0 Kudos
PF1
by
Occasional Contributor II

Hi Ghali, I had opened a ticket with Esri, but if I recall right... we were using the pre-release version of the software.  The ticket was closed until I could confirm if we had the same issue with the final release, but I had given up and worked out an alternate solution for our issue at hand.  Unfortunately I ended up building my own object to implement some of the same functionality that I needed from the FeatureSet.  I had always intended to get back to this, but ran out of time and the object I built meet the needs for the project I was on at the time. 

0 Kudos
MikeMillerGIS
Esri Frequent Contributor

I have seen this issue when there are true curves in the data.  Try a generalize first.  This should remove all the curves and product the proper JSON.

0 Kudos
NathanHeick
Occasional Contributor II

For what it is worth, I was also experiencing this issue at ArcGIS Desktop 10.1 SP1.  I was having issues with some large property boundaries and some large dissolved features, but not point and smaller line features.  This issue is fixed at least at version 10.4.1, so I upgraded and the problem went away without modifying the data at all.

0 Kudos