clarisma / geodesk-py

Fast and storage-efficient spatial database engine for OpenStreetMap data
https://docs.geodesk.com/python
GNU Lesser General Public License v3.0
36 stars 0 forks source link

GeoJSON format wrong? #34

Closed osmuser63783 closed 7 months ago

osmuser63783 commented 8 months ago

It looks like Geodesk exports OSM ways that are areas with a geometry of "type": "Polygon" but gives the "coordinates" like you would give the coordinates for a LineString, with two levels of square brackets instead of three.

Similarly, multipolygons that are areas (single-member multipolygons) get exported with a geometry of "type": "Polygon" but the "coordinates" are given as if they were of type MultiPolygon, with four levels of square brackets instead of three.

This causes MapRoulette, and possibly other tools that consume GeoJSON, to fail.

osmuser63783 commented 8 months ago

I should add that the above is my current theory of why it didn't work.

What I was actually trying to do was upload a GeoJSON created with Geodesk into Maproulette. When I uploaded a GeoJSON containing a number of features, Maproulette was able to turn some into tasks but not others. I noticed that all of my relations had imported correctly, but none of my ways (which were all areas). When I changed "Polygon" to "LineString" in the GeoJSON and tried again, it worked but some multipolygons (which were actually just simple polygons) did not import correctly.

I had a look at the Wikipedia page for GeoJSON and noticed the mismatch in the number of square brackets for the "coordinates" in the geometry between what is valid GeoJSON according to Wikipedia and what Geodesk outputs.

I don't think it's an issue with Maproulette because when you add an extra set of brackets it works with "Polygon".

Hope this makes sense.

osmuser63783 commented 8 months ago

Sorry, have amended the first post. Multipolygons are handled fine. Single-member MPs get turned into "Polygon" with three levels of brackets ("array of arrays of positions"). Multi-member MPs get turned into "MultiPolygon" with four. The issue I was having with multipolygons was related to my own code.

Ways that are areas get turned into Polygon with two levels only ("array of positions"). This is against the GeoJSON spec.

Haven't tested ways that aren't areas.

Nodes seem to be fine.

clarisma commented 8 months ago

Thanks! There is indeed a bug that causes incorrect GeoJSON for ways that are areas (The same bug affects WKT, but in reverse: polygons are fine, linestrings are wrong). This is now fixed in main and will be released in 0.1.5.