Possible bug: .to_geojson produces invalid GeoJSON from Line features

1624
5
01-10-2019 01:15 PM
by Anonymous User
Not applicable

I have come across a potential bug when using the .to_geojson method to convert a feature set object to GeoJSON using the ArcGIS Python API (v1.5.2). While attempting to convert a Feature Set of single-part line geometries to GeoJSON, the API produced invalid GeoJSON. From what I can tell, the API appears to be formatting the coordinates for single-part line geometries as multi-part line geometries.

According to the GeoJSON specification, the geometry of a single part line geometry (LineString) should look like this:

{
  "type": "LineString",
  "coordinates": [ [100.0, 0.0],[101.0, 1.0] ]
}‍‍‍‍‍‍‍‍‍‍‍‍

As you can see here the value for "coordinates" is a single array containing 2 or more coordinate arrays. (Source)

The geometry of a multi-part line geometry (MultiLineString) should look like this:

{ 
  "type": "MultiLineString",
  "coordinates": [
                   [ [100.0, 0.0], [101.0, 1.0] ], 
                   [ [102.0, 2.0], [103.0, 3.0] ]
                 ]
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍

The value for "coordinates" is a single array containing 2 or more LineString geometries (i.e. a single array containing 2 or more coordinate arrays). (Source)

However, when I use .to_geojson on a single-part line geometry, the following is returned:

{
  "type": "LineString",
  "coordinates": [
                   [ [100.0, 0.0], [101.0, 1.0] ]
                 ]
}‍‍‍‍‍‍

The geometry type value is properly  set as a LineString, but the coordinates are formatted as a MultiLineString.

I have created a Jupyter notebook using some sample data of single-part point, line, and polygon datasets:

This notebook documents my process troubleshooting this issue. Please feel free to take a look, run the code, and offer feedback if I am in error on how I have tried to access single-part line geometries as GeoJSON.

0 Kudos
5 Replies
JoshuaBixby
MVP Esteemed Contributor

Nice work isolating and demonstrating the issue.  It is clearly a bug, I recommend logging it with Esri Support.

Atma Mani‌, John Yaist‌, thoughts?

0 Kudos
JohnYaist1
Esri Contributor

Thanks for the thorough report, Ryan.Cooper@raleighnc.gov_ral . Certainly looks like a bug - give me a day or two to run through and try to reproduce it here so I can get it into the system. I'll keep you posted.

JohnYaist1
Esri Contributor

I've logged this as a bug in the API, Ryan.Cooper@raleighnc.gov_ral .  When I hear any info about when it's fixed, I'll let you know.

JohnYaist1
Esri Contributor

Hey Ryan Cooper - fyi...we pushed a fix up for this last night, it should be working in the next release. As you suggested, some internal functions were returning geojson as LineString. WE updated it to MultiLineStrings and it fixed it. Thanks for pointing it out.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Did you check for polygons to make sure it outputs MultiPolygon instead of Polygon?

0 Kudos