Getting geodata

Compared with other types of data, geodata generally comes in formats less conducive to online presentation, and you'll need to convert it to TopoJSON. We'll find some data in Shapefile or GeoJSON formats, and then use the topojson command-line utilities to transform them into TopoJSON. Finding detailed data can be difficult, but is not impossible - if wanting to make a map of your country, google your country's census bureau. For instance, the US Census Bureau has many useful datasets available at https://www.census.gov/geo/maps-data/the equivalent for the UK is at https://geoportal.statistics.gov.uk/geoportal/, and Canada's is: https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/bound-limit-2011-eng.cfm.

Natural Earth is another magnificent resource for geodata at different levels of detail. The biggest advantage is that different layers (oceans, countries, roads, and so on) are carefully made to fit together without discrepancies and are frequently updated. You can find the datasets at http://www.naturalearthdata.com, or install the political boundaries pre-converted to TopoJSON via npm using the world-atlas package.

We're going to convert Natural Earth to TopoJSON because the world-atlas package doesn't give us things like terrain or rivers.

First, download everything from http://naciscdn.org/naturalearth/packages/natural_earth_vector.zip.

Unzip the archive and navigate to it in the console. Then, install the following dependencies globally:

    npm install --global topojson shapefile

We install it topojson globally here, because we need its accompanying geo2topo command-line tool to convert GeoJSON to TopoJSON. Assuming you've extracted the aforementioned zip file and you're currently residing in the resulting directory, run:

$ mkdir output
$ geo2topo water=<(shp2json 50m_physical/ne_50m_rivers_lake_centerlines.shp) >
water.json $ geo2topo land=<(shp2json 50m_physical/ne_50m_land.shp) > land.json
$ geo2topo -n ne_50m_admin_0_boundary_lines_land=<(shp2json -n 50m_cultural/ne_50m_admin_0_boundary_lines_land.shp) ne_50m_urban_areas=<(shp2json -n 50m_cultural/ne_50m_urban_areas.shp) > cultural.json

Copy the resulting data files from build into your project's data/ directory.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset