2

I have a topojson which treats French Guiana as part of the "France" feature (therefore also, part of the Western Europe layer). To match my dataset, I want to split this out from France, while keeping Corsica as part of France:

enter image description here

On browsing the Mapshaper docs, -explode looks like my best bet. But there are a few problems:

  • It explodes out every multi-part feature in a layer, and there doesn't seem to be any way to limit it to just one feature or field value: target= is layers only. This isn't a huge problem for me in this particular example, as for this data the other features on this layer aren't multi part and I could temporarily move it onto a dummy layer, but I'll also need to do this with a variant where there are other multi-part features on the layer and the dummy layer workaround is rather clumsy (I'd like to preserve the order of the features in the layers if possible), so if there is a way to specify the target feature that would be useful.
  • It explodes all the parts of the feature, and there are two problems here:
    • The obvious way to recombine them, -dissolve or -dissolve2, in my experience seems to require the features to be touching or overlapping.
    • If I can get around that, another difficulty with -dissolve is that I would need to specify Corsica but not French Guiana using field data, but after exploding they get identical field data to the original feature (France). This technique using MapShaper's internal feature ID is a possibility here, not tried it in this context yet

So:

  • Is there a simpler, cleaner workflow for this general case than moving "France" to a dummy layer, exploding the dummy layer, then trying to dissolve Corsica back into France?
  • If no, how can I reliably dissolve Corsica back into France when they don't touch or overlap?

Please, no puns like "Can Mapshaper do this? Of Cors-i-can!"...

1 Answer 1

1

Not sure where I got the idea from that -dissolve needs the features to be touching, it doesn't.

This is long-winded, involves a temporary layer and requires some messy cleanup work at the end but it seems to work:

  • Move the feature to be exploded onto a new dummy layer:

    • Find a unique field value by clicking on it using the i button, e.g. NAME == 'France'
    • Give it a temporary field value where all features have the same value except this one
    -each 'moveLayer = 0'
    -each 'moveLayer = 1' where='NAME == "France"'
    
    • Split the layer on this field
    -split moveLayer
    
  • Explode it. You don't need the layer name and can just use -explode on its own if you switch to the new layer using the interface

-explode layerName 
  • Give each new feature a dummy field value based on MapShaper ID, for example TEMP:
-each 'TEMP = this.id'
  • Use the i button to click on the new features you want to continue to be seperate and note their TEMP value, for example 3
  • Choose any field value that is the same between the exploded features. For example, NAME
  • Give the one(s) you want to stay separate a new NAME:
-each 'NAME = "Some name"' where='TEMP == 3'
  • -dissolve on that field. The ones you didn't rename should all merge back together.
-dissolve NAME
  • Clean up the newly created fields you no longer need:
-filter-fields moveLayer
-filter-fields TEMP

That last step isn't ideal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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