question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FeatureSet.from_geojson Fails on MultiPolygons

See original GitHub issue

While responding to a GeoNet thread, FeatureSet.from_geojson bug?, I was able to verify a defect in FeatureSet.from_geojson with MultiPolygon.

Using a basic MultiPolygon example from GeoJSON - Wikipedia, you can generate an error:

>>> from arcgis.features import FeatureSet
>>>
>>> geojson_multipolygon = {
...   "type": "FeatureCollection",
...   "features": [{
...     "type": "Feature",
...     "geometry" : {
...       "type": "MultiPolygon",
...       "coordinates": [
...         [[[30, 20], [45, 40], [10, 40], [30, 20]]],
...         [[[15, 5], [40, 10], [10, 20], [5, 10], [15, 5]]]
...       ]
...     },
...     "properties": {
...       "name": "Wikipedia MultiPolygon example"
...     }
...   }]
... }
>>>
>>> FeatureSet.from_geojson(geojson_multipolygon)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\feature.py", line 922, in from_geojson
    return FeatureSet.from_dict(geo_to_esri(geojson))
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\feature.py", line 826, in geo_to_esri
    esri["features"] = list(esri_features)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\feature.py", line 832, in extract
    geometry = get_geometry(feature)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\feature.py", line 880, in get_geometry
    geometry = Geometry(json.loads(geom))
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\json\__init__.py", line 348, in loads
    'not {!r}'.format(s.__class__.__name__))
TypeError: the JSON object must be str, bytes or bytearray, not 'Polygon'
>>> 

Using the polygon with a hole example from GeoJSON - Wikipedia , the method works fine:

>>> from arcgis.features import FeatureSet
>>> 
>>> geojson_polygon = {
...   "type": "FeatureCollection",
...   "features": [{
...     "type": "Feature",
...     "geometry": {
...       "type": "Polygon",
...       "coordinates": [
...         [[35, 10], [45, 45], [15, 40], [10, 20], [35, 10]],
...         [[20, 30], [35, 35], [30, 20], [20, 30]]
...       ]
...     },
...     "properties": {
...       "name": "Wikipedia Polygon example with hole"
...     }
...   }]
... }
>>>
>>> FeatureSet.from_geojson(geojson_polygon)
<FeatureSet> 1 features
>>> 

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
achapkowskicommented, Sep 1, 2020

It will be fixed in the next release. That is why it was closed.

0reactions
bixb0012commented, Sep 1, 2020

@achapkowski , I see this with ArcPy from Pro 2.6 installed as well.

>>> from operator import itemgetter
>>> from arcgis.features import FeatureSet
>>>
>>> import arcpy
>>> import arcgis
>>>
>>> itemgetter('ProductName', 'Version', 'BuildNumber')(arcpy.GetInstallInfo())
('ArcGISPro', '2.6', '24783')
>>> arcgis.__version__
'1.8.1'
>>>
>>> geojson_multipolygon = {
...   "type": "FeatureCollection",
...   "features": [{
...     "type": "Feature",
...     "geometry" : {
...       "type": "MultiPolygon",
...       "coordinates": [
...         [[[30, 20], [45, 40], [10, 40], [30, 20]]],
...         [[[15, 5], [40, 10], [10, 20], [5, 10], [15, 5]]]
...       ]
...     },
...     "properties": {
...       "name": "Wikipedia MultiPolygon example"
...     }
...   }]
... }
>>>
>>> FeatureSet.from_geojson(geojson_multipolygon)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\feature.py", line 922, in from_geojson
    return FeatureSet.from_dict(geo_to_esri(geojson))
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\feature.py", line 826, in geo_to_esri
    esri["features"] = list(esri_features)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\feature.py", line 832, in extract
    geometry = get_geometry(feature)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\feature.py", line 880, in get_geometry
    geometry = Geometry(json.loads(geom))
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\json\__init__.py", line 348, in loads
    'not {!r}'.format(s.__class__.__name__))
TypeError: the JSON object must be str, bytes or bytearray, not 'Polygon'
>>>

Esri Support was able to reproduce the defect with ArcPy installed as well, and the following Esri Support bug was logged:

#BUG-000133455 FeatureSet.from_geojson Fails when used with MultiPolygons.

Read more comments on GitHub >

github_iconTop Results From Across the Web

FeatureSet.from_geojson bug? - Esri Community
When calling FeatureSet.from_geojson (ArcGIS API for Python) in an ArcGIS ... Using a basic MultiPolygon example from GeoJSON - Wikipedia, ...
Read more >
QGIS/GeoJSON: Dissolve featurecollection consisting of ...
Do a dissolve (vector --> geoprocessing tools --> dissolve). Then all the normal polygons get merged into a giant multipolygon, but not the ......
Read more >
Bokeh is not rendering properly multipolygon (islands) from ...
My geodata is an GeoJSON with Polygons and MultiPolygons. I have trouble rendering the Multipolygons: If I extract all geometries of an feature ......
Read more >
GeoJSONLayer | ArcGIS Maps SDK for JavaScript 4.25
Set featureEffect property if different effects need to be applied features that meet or fail a specified filter. If all of the following...
Read more >
Geography functions | BigQuery - Google Cloud
See ST_GEOGFROMGEOJSON to construct a GEOGRAPHY from GeoJSON. ... Pre-GA products and features may have limited support, and changes to pre-GA products and ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found