Implement __geo_interface__ in ArcGIS Python API

2498
7
01-05-2017 01:21 PM
Status: Implemented
JoshuaBixby
MVP Esteemed Contributor

I suggest adding __geo_interface__ support to arcgis.features and arcgis.geometry.

__geo_interface__ is "a GeoJSON-like protocol for geo-spatial (GIS) vector data."  It follows a similar model/idea as NumPy's Array Interface.  It was proposed or put forward in 2013, and more than a dozen geospatial Python applications (see Python Geo_interface applications) implement the protocol.  The protocol allows for simple and efficient transferring of features and geometries between various geospatial Python packages.

ArcPy currently supports __geo_interface__ in its Geometry classes (it can be argued there is only partial support since the current implementation is broken in several ways).    On a system with both ArcPy and Shapely installed, passing a geometry object from the former to the latter can be done efficiently with a single function call:

>>> import arcpy
>>> from shapely.geometry import shape
>>> 
>>> arc_polygon = arcpy.FromWKT('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
...                             arcpy.SpatialReference(3857))
... 
>>> arc_polygon.area
100.0
>>> 
>>> shapely_polygon = shape(arc_polygon)  # pass ArcPy geometry to Shapely
>>> 
>>> shapely_polygon.area
100.0
>>> shapely_polygon.buffer(1.0).area
143.13654849054595
>>>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍


Granted, there are numerous ways features and geometry objects can be passed between geospatial Python packages, but __geo_interface__ represents an established, open, well-adopted, and efficient means that should be supported within the ArcGIS Python API.  Additionally, the protocol is lightweight and straightforward to implement.

7 Comments
JoshuaBixby

Ironically, this has already been implemented, although parts of the support are broken at the moment.

RohitSingh2

Can you post which parts are broken on the Community forum or the SDK repo? We'll look into fixing them.

JoshuaBixby

Rohit Singh‌, the issue is discussed in more detail here:  https://community.esri.com/thread/210827-geointerface-generates-different-and-incorrect-output-when-... .  The issue is isolated to when ArcPy is not installed.  I can't speak for all the ways it is, or isn't, broken; but it definitely handles polygons with hole in them incorrectly when ArcPy is not installed.

DanPatterson_Retired

almost 2 years on.... still under consideration

JoshuaBixby

When I originally posted this Idea, it was already partially supported/implemented.  The issue at the time were some edge cases that were not compliant, but as noted in https://community.esri.com/thread/210827-geointerface-generates-different-and-incorrect-output-when-..., those edge cases were address in version 1.5.  For all intents and purposes, this Idea is "Implemented."  Why wouldn't the ArcGIS API for Python team want to take credit for their work and update the status?  No idea.

John-Foster
Status changed to: Implemented