AnsweredAssumed Answered

__geo_interface__ Generates Different and Incorrect Output When ArcPy Not Installed

Question asked by bixb0012 Champion on Mar 7, 2018
Latest reply on Sep 4, 2018 by bixb0012

Hey ArcGIS API for Python staff on GeoNet, I found a bug for you.

 

It turns out the __geo_interface__ methods generate different, and incorrect, output when ArcPy is not installed along with ArcGIS API for Python.

>>> from arcgis.geometry import Geometry
>>> from pprint import pprint
>>>
>>> # simple square with a hole in the middle
... json = {
...     "rings": [
...         [
...             [0, 0],
...             [0, 10],
...             [10, 10],
...             [10, 0],
...             [0, 0]
...         ],
...         [
...             [3, 3],
...             [7, 3],
...             [7, 7],
...             [3, 7],
...             [3, 3]
...         ]
...     ],
...     "spatialReference": {
...         "wkid": 3857
...     }
... }
>>>
>>> # __geo_interface__ output when ArcPy is installed
>>> pprint(Geometry(json).__geo_interface__)
{'coordinates': [[[(0.0, 0.0),
                   (0.0, 10.0),
                   (10.0, 10.0),
                   (10.0, 0.0),
                   (0.0, 0.0)],
                  [(3.0, 3.0),
                   (7.0, 3.0),
                   (7.0, 7.0),
                   (3.0, 7.0),
                   (3.0, 3.0)]]],
'type': 'MultiPolygon'}
>>>
>>> # __geo_interface__ output when ArcPy is not installed
>>> pprint(Geometry(json).__geo_interface__)
{'coordinates': [[[(0, 0),
                   (0, 10),
                   (10, 10),
                   (10, 0),
                   (0, 0)]],
                 [[(3, 3),
                 (7, 3),
                 (7, 7),
                 (3, 7),
                 (3, 3)]]],
'type': 'MultiPolygon'}
>>>

 

Notice when ArcPy is not installed, the __geo_interface__ output contains an extra closing bracket on the outer ring of the polygon, thus turning a single-part polygon with a hole into a overlapping multi-part polygon.

Outcomes