mbloch / mapshaper

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

Clip command removes Features visually but not from exported file. #634

Closed NMC92 closed 5 months ago

NMC92 commented 5 months ago

Hi. I've noticed that when using the -clip command the Features are indeed removed from the map visually(you no longer see them on the map, for example when clipping unwanted Features), but after exporting the clipped data it continues to be present in the exported files. The command I am using is:

-filter 'tags.admin_level == 2 && tags["ISO3166-1"] == "ES"' name=country no-replace target=1 -clip country target=1

In this case I'm clipping by the polygon of Spain, but I notice that I still have French polygons in my output, even though I don't see them. Why are the features not being deleted on the .geojson file but when I upload the file on mapshaper.org I can't see them? Also, if I inspect for "admin_level == 2" I get two results when I should be getting only 1(countries have "admin_level == 2") meaning France(the country) was not removed.

photo1 photo2

mbloch commented 5 months ago

Based on what you've reported, I think I know what is happening, but I won't know for sure if I can't download and test your data file myself.

Your initial filter command takes the boundary of Spain and copies it to a second layer. Your clip command then uses the Spanish boundary layer to clip the first layer. The France country boundary polygon may overlap the Spain boundary just a little bit, so it becomes a tiny sliver polygon after the clip command -- so small that you can't clearly see it, although it shows up in the -inspect command. That's my best guess as to what is happening. If you want to thoroughly remove all of the France features, I suggest that you do that in an initial -filter command, like this: -filter 'tags["ISO3166-1"] == "ES"'.

NMC92 commented 5 months ago

Hi. Thank you for the reply. I will prepare the data in a bit for you to test it yourself. I'm thinking of manually checking the resulting file, handpicking the few "sliver" Features, put them in a geojson file and then upload them to mapshaper. I'm assuming the view will snap to the tiny slivers so I'll finally be able to see them.

NMC92 commented 5 months ago

I got what the problem is. https://www.openstreetmap.org/note/2121166 There's an island that is French for half of the year but Spanish for the other half. When I use the clip command it does exactly what it is supposed to do. I hate these complicated cases...

mbloch commented 5 months ago

good sleuthing!