Makings your own custom vector maps 💻

|

Objective

To create a vector map of the island of Ireland (Republic of Ireland and Northern Ireland) with some cities.

Geographic data

You can get the geographic data from Natural Earth. You can get vector files with different themes (culture, physical), different topics (coastline, ocean, land), and different levels of detail (1:10m 1:50m, 1:110m).

Because Northern Ireland is a sovereign state, it is part of Great Britain, we need a map that includes administrative subunits, so we can filter by the subunits later to only include these 2 sovereign state. I will go for the maximum detail (1:10m), so I will go to 1:10m Cultural Vectors: Admin 0 - Details: Map subunits. I will also download Populated Places and extract some cities.

If you want to verify what you’ve downloaded, you can use mapshaper to view it in your browser, by simply dropping the file onto the webpage and then importing the files. It is a quick way to see the differences if you are not sure about what you’re getting!

Conversion tools

For Windows, you can install the geo tools from OSGeo4W, which will take care of downloading and installing everything you need to convert and manipulate the files you get from Natural Earth. You can open up OSGeo4W Shell to use the command-line for conversion; or you can use QGIS Desktop that has been installed, and use the GDAL Vector Processing tool inside.

I will do it on the command-line. I will create subunits.json that has the sovereign units for Ireland and Northern Ireland. We also filter the fields to include using -select switch, the Natural Earth files have many fields that we are not using, so we can exclude the majority of them.

ogr2ogr -f GeoJSON -where "SU_A3 IN ('NIR', 'IRL')" -select "ADM0_A3, SU_A3, NAME_EN" subunits.json ne_10m_admin_0_map_subunits.shp

We create places.json for populated places in Ireland. The result is the 15 biggest cities.

ogr2ogr -f GeoJSON -where "SOV_A3 = 'IRL'" -select "ADM0_A3, SOV_A3, NAME_EN" places.json ne_10m_populated_places.shp

We can combine the 2 files and convert them to topojson. We get a “countries” layer (from subunits.json), and a “places” layer (from places.json).

geo2topo countries=subunits.json places.json > ireland.json

You can use toposimplify to simplify the topology and reduce the file size. It did not work well for me, I tried a few different parameters, and every time it did not come out the way I wanted. I used mapshaper to do this instead and you can control how much detail you want with a slider, and see the results instantly. I reduced the filesize from 130KB to 12KB with the simplification, which is incredible!

mapshaper

Result

Use D3.js to show the final result! You can read Mike Bostock’s tutorial to learn more on that.

See the Pen SVG map of Ireland with cities by rob (@robjoeol) on CodePen.

References

Related Posts