AnsweredAssumed Answered

Possible bug: .to_geojson produces invalid GeoJSON from Line features

Question asked by Ryan.Cooper@raleighnc.gov_ral on Jan 10, 2019
Latest reply on Jan 15, 2019 by jyaist-esristaff

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.

Outcomes