mbloch/mapshaper

BUG: Nodes Disappearing After Downloading Without Modification

ViniciusCestarii opened this issue · 2 comments

I encountered an issue with Mapshaper where nodes in my GeoJSON file disappear after uploading and downloading the file without making any modifications. This behavior is unexpected, as I did not alter the file during the process.

Steps to Reproduce:

Upload a GeoJSON file to Mapshaper.
Download the GeoJSON file without making any changes.
Compare the downloaded file with the original file.

Expected Behavior:

The downloaded GeoJSON file should match the original file exactly, with all nodes and features intact.

Actual Behavior:

Some nodes and features are missing in the downloaded GeoJSON file. This issue persists even though no modifications were made to the file during the process.

GeoJSON File:

https://github.com/dadosfera/brasil-municipios-geojson/blob/main/geojs-100-mun-v2.json

Before:

image

After:

image

I highlighted these two nodes which have disappeared, but there are additional nodes affected as well.

image

Thanks for reporting this :)

I extracted one of the disappearing shapes for testing, here's a link to the sample file and an image of the shape in mapshaper:
extract.json

image

The example shape consists of two polygon rings. This kind of shape should be represented as a MultiPolygon in GeoJSON, but if you look at the file, you'll see that the geometry type is Polygon, with two coordinate rings. According to the GeoJSON spec, when a Polygon contains multiple rings, the first ring in the array is an exterior ring and the following rings are holes. When mapshaper exports the file, it sees that the "hole" is not actually contained by the exterior ring and deletes it. The shapes are disappearing because they are not valid GeoJSON polygons.

You can fix the problem in mapshaper by running the console command: -clean rewind.

Mapshaper should give you some kind of warning about the problem, instead of just silently deleting rings... this kind of invalid geometry appears so rarely that I didn't think to add a warning, but I will put it on my TODO list.

--Matt

Thank you Matt for the quick response and the solution! I appreciate the explanation. I tried the -clean rewind command, and it worked perfectly!