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:
<SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"type"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"LineString"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"coordinates"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">100.0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0.0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">101.0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1.0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="punctuation token">]</SPAN>
<SPAN class="punctuation token">}</SPAN>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:
<SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"type"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"MultiLineString"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"coordinates"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN>
<SPAN class="punctuation token">[</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">100.0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0.0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">101.0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1.0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="punctuation token">[</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">102.0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2.0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">103.0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">3.0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="punctuation token">]</SPAN>
<SPAN class="punctuation token">]</SPAN>
<SPAN class="punctuation token">}</SPAN>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:
<SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"type"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"LineString"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"coordinates"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN>
<SPAN class="punctuation token">[</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">100.0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0.0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">101.0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1.0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="punctuation token">]</SPAN>
<SPAN class="punctuation token">]</SPAN>
<SPAN class="punctuation token">}</SPAN>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.