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 )
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)
Here is a link to get the geojson returned
Showing that geojson in QGIS, the holes are seen as "filled in". Same happens with FME.
Any suggestions?
Kirk
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?
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.
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:
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.
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.
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.
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.