2

I've got a TOPOJSON file that is nearly perfect, but contains one item (a multi polygon) that I'd like to remove. Doing so manually from the code is difficult because it'd require manually counting through hundreds of arcs in the nested arrays.

The feature in question has an ID I can identify it by, so I thought this would be easy using the MapShaper console. However looking in the docs I'm struggling to find any tool that seems to do this. Closest is -erase:

-erase. Remove features or portions of features that fall inside an area.

...but it seems like all the direct targeting options are for targeting layers, not features, or by drawing a bounding box (which for this geography is tricky). Everything I've tried to select the feature by ID instead tries and fails to find a layer with an error message Missing data layer.

Surely there's a simple way to do something like (fake code):

-delete [id='someId']

I'm open to suggestions using (ideally open-source) tools other than MapShaper, but I'd prefer to not need to convert my TopoJSON to another format then back again, and would prefer a simple solution to such a seemingly simple problem.

3

With a little experimentation, I found a reasonably simple solution using -filter. Assuming the identifying field is named FID (check exact name using -info and note that everything here is case-sensitive):

-filter 'FID !== "someId"'

...or drop the inner quotes if the field value is numeric:

-filter 'SOME_FIELD !== 123'

That's a javascript expression that will evaluate as true for everything except features where the FID is someId. Mapshaper's -filter command then tests this Javascript expression against every feature, and deletes the ones where it returns false.

Be careful you don't forget the !, if you use == or === by mistake it'll delete everything except the feature you want to delete!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.