Friday, 3 August 2018

How to restrict Mapshaper's `-dissolve` to merge only certain specified features on a layer


I'm try to merge a few specified features on a topojson map using Mapshaper. For this example, I'm trying to merge Somalia, Somaliland and Puntland to match a dataset that doesn't separate them.


Mapshaper has command features, -dissolve and -dissolve2, that seem to do what I want. However, they seem to apply to every feature in the selected layer, and I can't see any obvious way in the Mapshaper docs to select only certain features within a layer to apply to.


The options name and target apply to files and layers respectively, not features. Likewise all the usage examples I can find don't select specific features to merge.


There's a feature to limit it by field:



Name of a data field to dissolve on.



... but I can't find any way to pipe in a list of field values. I can specify the name field, but can't find a way to specify that the name field should be "Somalia" or "Somaliland".


If possible, I'd prefer not to move the features onto a temporary dummy layer then move them back again.



Ideally I'd use something similar to how -each and -filter allow to match by an expression but that doesn't seem to exist for -dissolve. For example, this, which works perfectly for -filter, doesn't work:


 -dissolve '(NAME == "Somaliland" || NAME == "Puntland" || NAME == "Somalia")'

...because that parameter must be a field name and can't be an expression:



Data table is missing field: (NAME == "Somaliland" || NAME == "Puntland" || NAME == "Somalia")





No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...