Thursday 28 September 2017

d3 - Remove outlying territories/islands from Europe map


Using a shapefile from Natural earth, I am trying create a map of Europe with d3-geo’s new command-line interface. The following:



shp2json -n ne_50m_admin_0_countries/ne_50m_admin_0_countries.shp \
| ndjson-filter '["ALB", "AND", "AUT", "BEL", "BGR", "BIH", "BLR", "CHE", "CYP", "CZE", "DEU", "DNK", "ESP", "EST", "FIN", "FRA", "FRO", "GBR", "GIB", "GRC", "HRV", "HUN", "IMN", "IRL", "ISL", "ITA", "LIE", "LTU", "LUX", "LVA", "MCO", "MDA", "MDA", "MKD", "MLT", "MNE", "NLD", "NOR", "POL", "PRT", "ROU", "SMR", "SRB", "SVK", "SVN", "SWE", "UKR", "VAT", "XKX"].includes(d.properties.adm0_a3)' \
| ndjson-reduce \
| ndjson-map '{type: "FeatureCollection", features: d}' \
| geoproject 'd3.geoConicEqualArea().parallels([43, 62]).rotate([0, 0]).fitSize([960, 960], d)' \
| geo2svg -w 960 -h 960 \
> europe.svg

...creates this output:


enter image description here



How can I remove all the overseas territories (e.g. French Guyana) and distant islands, so I'm left with a map of just 'mainland' Europe? Nothing west of Portugal, nothing south of mainland Spain etc. More like this:


enter image description here



Answer



I'd bring it into QGIS and use Vector > Geometry > Multipart to Singlepart.


In Natural Earth, France is a multipolygon so it is one feature with lots of individual polygons (France, French Guiana, Reunion etc).


Doing this breaks each of these polygons into its own feature - so your shapefile jumps in size from ~250 (roughly one feature per 'country') to several thousand features.


Then select the ones you want with the select tool, dragging your selection over the region of Europe you want, and save as a new shapefile (making sure you check "save selected features only")


You should now be able to plug in the new shapefile into your first line of code and it should work.


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...