Here data preprocessing means taking data files in provided format and converting them to format suitable for D3. Specifically, we are taking a few shapefiles and convert them into a single TopoJSON file.
-
At first we convert each shapefile to GeoJSON file. Usually we perform some filtering at this step. For example, we want data only for specific area, not for the entire world. Or we may need data only for objects of certain size, like the biggest rivers. Typically a shell command looks like
ogr2ogr -f GeoJSON \ -clipdst 20.5 43.6 42 53 \ build/countries.json raw_data/ne_10m_admin_0_countries/ne_10m_admin_0_countries.shp -
Then we convert each GeoJSON file to TopoJSON file. At this step we decide which object properties will be available in JavaScript. Mostly we are interested in
names and want to omit accessory properties likenote,comment. Typically a shell command looks liketopojson -p name -o lakes.topo.json lakes.json -
At the end we merge all TopoJSON files into a single TopoJSON file. A shell command looks like
topojson -p -o full.topo.json countries.topo.json regions.topo.json …
The easiest way to install all necessary tools is by using a virtual machine. You can use VirtualBox as a virtualization software and Vagrant to manage your environment. You perform data preprocessing with the following shell commands:
-
Run
vagrant upinukraine_map_datato start the virtual machine. The first time you need to wait until the virtual machine is downloaded and all necessary tools are installed. -
Run
vagrant sshand in the virtual machinecd /vagrant. At this point you see in the virtual machine the same files as in the host machine. -
Run
raketo create resulting TopoJSON filebuild/full.topo.json. -
In the end exit the virtual machine with
exitand shutdown it withvagrant halt.