AnsweredAssumed Answered

Converting geometries between GeoJSON, esri JSON, and esri Python

Question asked by filipkral on Mar 31, 2014
Latest reply on Jun 15, 2018 by bixb0012
Hi,
I want to be able to convert geometries between GeoJSON [1], esri JSON [2, 3], and esri Python objects [4] using ArcGIS 10.1 SP1.

[1] http://geojson.org/geojson-spec.html
[2] http://resources.arcgis.com/en/help/main/10.1/index.html#//018v0000004m000000
[3] https://developers.arcgis.com/javascript/jsapi/geometry-amd.html etc.
[4] http://resources.arcgis.com/en/help/main/10.1/index.html#/Geometry/018z00000070000000/

Converting GeoJSON to esri Python using arcpy.AsShape as described in [2] works.

However, converting esri JSON to esri Python described in example 6 on the same help page [2] raises an error.
I understand the error but none of my experiments worked and this example is from the official help.
esri_json = {"paths" : [[[-97.08, 32.8], [-97.05, 32.6], [-97.06, 32.7], [-97.07, 32.6]], [[-97.4, 32.5], [-97.2, 32.75]]], "spatialReference" : {"wkid" : 4326}} polyline = arcpy.AsShape(esri_json, True) >>> # returns Traceback (most recent call last):   File "<editor selection>", line 1, in <module> TypeError: AsShape() takes exactly 1 argument (2 given)


I believed it was possible to get esri JSON from esri Python using the JSON property on geometry objects [4], but this consistently fails with errors like:
Traceback (most recent call last):   File "<editor selection>", line 6, in <module> AttributeError: 'PointGeometry' object has no attribute 'JSON'


Do you know about a reliable way of converting esri geometries to GeoJSON in Python?

I would be grateful for any comments.
Filip.

Outcomes