mbloch / mapshaper

Tools for editing Shapefile, GeoJSON, TopoJSON and CSV files
http://mapshaper.org
Other
3.74k stars 532 forks source link

filter-islands not processing all islands #464

Open hyperknot opened 3 years ago

hyperknot commented 3 years ago

I have the following GeoJSON from mapbox-gl-js's queryRenderedFeatures(), run on an OSM water layer: browser.geojson (renamed to .txt)

I'd like to remove small islands from it (<1 km2), I'm running the following code:

mapshaper browser.geojson \
  -filter-islands min-area=1km2 \
  -o geojson-type=FeatureCollection out.geojson

What happens is that 99% of the islands get removed, but not all. The result is the same with 1000000km2.

fix

Adding -clean removes a bit more, but still not all of them.

Running geojsonhint on it throws up warning Polygons and MultiPolygons should follow the right-hand rule lines for 456 features, but almost all of these get removed correctly.

hyperknot commented 3 years ago

I checked with fixed right-hand rule using:

ogr2ogr -f GeoJSON -lco RFC7946=YES fixed.geojson input.geojson

And the result is the same. So it is not related to any geojsonhint errors, as the fixed file has none.

hyperknot commented 3 years ago

At the end I figured out the best results by running the following chain multiple times, in my case 3x was needed:

-clean
-explode
-filter-islands 
-dissolve2

finishing with a clean.

Does it make sense or I'm doing something wrong here?

// I also realised clean rewind fixes the right-hand-rule.