How to merge regions with Mapshaper
Sometimes, you might want one large region that consists of different sub-regions, but your GeoJSON has all the regions listed separately and they all appear with their own popup. This help doc will walk you through merging those regions using a free online tool called Mapshaper.
In this help doc, we're going to be merging regions to create the regions displayed above.
TIP: Struggling to find the right regions for your map? Check out our GeoJSON repository where we've sourced, checked, and resized various region files ready for you to download and use in Flourish.
- Upload your GeoJSON file to Mapshaper. https://geojson-maps.ash.ms/ is a great resource to get public domain GeoJSON files from Natural Earth.
- Use the "select regions" tool to select the regions you would like to merge into one. We're looking to merge the USA and Canada into "North America" in this example. Once selected, choose "Split" from the options that appear in the upper area of the editor.
- Once you've split out your regions, they will appear greyed out. If you click on the dropdown where the name of your GeoJSON is displaying, you'll see they've been moved to a separate layer. Click into that layer.
Once you're in your new layer (the regions you want to merge should display with a black outline), it's time to merge. To do this, open the console in Mapshaper and run the command
-dissolve.This will merge adjacent polygons by erasing shared boundaries.
Go back to the main layer and repeat, splitting out and then dissolving groups of polygons you'd like to appear as one region in your map. In our case, we end up with five different layers, in which we've all ran the
You can check if the merging has worked by hovering over your regions with the selection tool. If they've been merged correctly, the whole block of split out regions will appear outlined in black.
Now it's time to merge the layers back together. To do this, open the console and run the command
merge-layers target=region1,region2 force. (Replace
region2with the names of your regions.) Keep merging the split out layers back into the master layer one by one, until you only have one layer again. Note that the region names are separated by a comma without any spaces.
- Once you have one layer, you can export that as a GeoJSON file and import it to Flourish.