Customizing the Generator to Your City

In order to customize the generator to a particular city the only thing we need is to define a bounding box that will be used to download the data from OSM. There are many ways to obtain such a bounding box, and a typical way to proceed is to use one of the multiple online services that allows one to visually define a bounding box over a map. Figure 2.5, “Defining the bounding box for obtaining OSM data from Barcelona.” shows how we can define the bounding box around Barcelona using the web site bboxfinder.

Figure 2.5. Defining the bounding box for obtaining OSM data from Barcelona.

Defining the bounding box for obtaining OSM data from Barcelona.

After obtaining the bounding box, we can proceed as we stated in the section called “Quick Start”. We create a new database barcelona, then add both PostGIS, MobilityDB, and pgRouting to it.

CREATE EXTENSION mobilitydb CASCADE;
CREATE EXTENSION pgRouting;

Then, we download the OSM data from Barcelona using the Overpass API by writing the following in a terminal:

CITY="barcelona"
BBOX="2.042084,41.267743,2.258720,41.445043"
wget --progress=dot:mega -O "$CITY.osm" 
"http://www.overpass-api.de/api/xapi?*[bbox=${BBOX}][@meta]"

We can optionally reduce the size of the OSM file as follows

sed -r "s/version=\"[0-9]+\" timestamp=\"[^\"]+\" changeset=\"[0-9]+\" uid=\"[0-9]+\" 
user=\"[^\"]+\"//g" barcelona.osm -i.org

Finally, we load the map and convert it into a routable format suitable for pgRouting as follows.

osm2pgrouting -f barcelona.osm --dbname barcelona -c mapconfig_brussels.xml