Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Converting geometries between GeoJSON, esri JSON, and esri Python

$
0
0
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/...0000004m000000
[3] https://developers.arcgis.com/javasc...-amd.html etc.
[4] http://resources.arcgis.com/en/help/...0000070000000/

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.
Code:

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:
Code:

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.

Viewing all articles
Browse latest Browse all 2485

Trending Articles