Select to view content in your preferred language

AGOL export to geojson, holes not represented as expected

581
4
12-09-2020 09:33 AM
Kirk_d
by
New Contributor

I am downloading geojson from a government agency that uses a hosted AGOL instance.  The geojson does not appear to come back in the expected format for any polygons with holes (as shown in https://tools.ietf.org/html/rfc7946#appendix-A )

"A.3. Polygons

   Coordinates of a Polygon are an array of linear ring (see
   Section 3.1.6) coordinate arrays.  The first element in the array
   represents the exterior ring.  ...

Instead, the holes are returned as additional rings with reverse winding order.  Is this the expected geojson format to be returned?  Is it a configuration on their server (or hosted service) to specify how holes are represented? 

 

Here is an example using the AGOL viewer (notice the holes)

https://data-nifc.opendata.arcgis.com/datasets/wildfire-perimeters/data?geometry=-125.090%2C39.654%2...

 

Here is a link to get the geojson returned

https://services3.arcgis.com/T4QMspbfLg3qTGWY/arcgis/rest/services/Public_Wildfire_Perimeters_View/F...

Showing that geojson in QGIS, the holes are seen as "filled in".  Same happens with FME.

Any suggestions?  

Kirk

 

 

 

4 Replies
Kirk_d
by
New Contributor

One other addon to this, the geojson is often very slow with large payload.  Is there any documentation regarding how to parse or deserialize if using pbf as the requested output from the service?

0 Kudos
TX-KunKun
New Contributor

One thing i noticed is that all coordinates have tons of unnecessary decimal points that are longer than what NASA uses. I run the geojson through Turf.js's truncate function which instantly cut of 60% file size without losing much precision.

0 Kudos
TX-KunKun
New Contributor

It's 2024 and I just encountered this exact issue. The output multi-polygon is not structured correctly for holes. It won't even pass the lint tool that ESRI suggested, geojsonlint.com, because the winding order is incorrect.

 

Update: I have found a solution after wasting many hours on what was supposed to be a '10-minute job.'

 

The Solution: You will need to modify the data hosted on AGO. Specifically, you'll need to convert Multipart to Singlepart for objects with this issue. This operation will break those multi-polygons into individual polygons. You might want to add a real ID field so you can still group these newly created pieces together later, but it will resolve the issue.

Other Findings:

  1. The lint tool will complain about the winding issue. However, if you use Turf.js's rewind function to fix the winding, the Leaflet instance on the lint tool page could actually display the holes correctly. I didn't get a chance to test it on a real Leaflet page, though.

  2. The rewound GeoJSON will still have issues in a Mapbox JS instance as before; the polygons for holes will be considered additional features instead of being used for clipping holes.

  3. No other parameter in AGO's REST service will assist with this. At one point, I almost decided to decode the pbf to extract the data.

I hope this helps others, or at least my future self.

 

 

ATDPublisher
New Contributor

Yep, the ArcGIS REST API geojson endpoints are still busted. It's miserable. A javascript approach to solving this is to use the terraformer arcgis package:

https://www.npmjs.com/package/@terraformer/arcgis

This package has a function called arcgisToGeoJSON which does correctly convert an ESRI json polygon to geojson.

0 Kudos