Running the generator is done in three steps:
Firstly, load the street network. Create a new database brussels
, then add the extensions hstore, PostGIS, MobilityDB, and pgRouting to it.
# in a console: createdb -h localhost -p 5432 -U dbowner brussels # replace localhost with your database host, 5432 with your port, # and dbowner with your database user psql -h localhost -p 5432 -U dbowner -d brussels -c 'CREATE EXTENSION hstore' # adds the hstore extension needed by osm2pgsql psql -h localhost -p 5432 -U dbowner -d brussels -c 'CREATE EXTENSION MobilityDB CASCADE' # adds the PostGIS and the MobilityDB extensions to the database psql -h localhost -p 5432 -U dbowner -d brussels -c 'CREATE EXTENSION pgRouting' # adds the pgRouting extension
For the moment, we will use the OSM map of Brussels. It is given in the data section of this workshop in the two files: brussels.osm, mapconfig.xml
. In the next sections, we will explain how to use other maps. It has been downloaded using the Overpass API, hence it is by default in Spherical Mercator (SRID 3857), which is good for calculating distances. Next load the map and convert it into a routable network topology format suitable for pgRouting.
# in a console, go to the generatorHome then: osm2pgrouting -h localhost -p 5432 -U dbowner -W passwd -f brussels.osm --dbname brussels \ -c mapconfig.xml
The configuration file mapconfig.xml
tells osm2pgrouting which are the roads that will be selected to build the road network as well as the speed limits of the different road types. During the conversion, osm2pgrouting transforms the data into WGS84 (SRID 4326), so we will need later to convert it back to SRID 3857.
Secondly, prepare the base data for the simulation. Now, the street network is ready in the database. The simulation scenario requires to sample home and work locations. To make it realistic, we want to load a map of the administrative regions of Brussels (called communes) and feed the simulator with real population and employment statistics in every commune.
Load the administrative regions from the downloaded brussels.osm
file, then run the brussels_generatedata.sql
script using your PostgreSQL client, for example:
osm2pgsql -c -H localhost -P 5432 -U dbowner -W -d brussels brussels.osm # loads all layers in the osm file, including the adminstrative regions psql -h localhost -p 5432 -U dbowner -d brussels -f brussels_preparedata.sql # samples home and work nodes, transforms data to SRID 3857, does further data preparation psql -h localhost -p 5432 -U dbowner -d brussels -f berlinmod_datagenerator.sql # adds the pgplsql functions of the simulation to the database
Finally, run the generator.
psql -h localhost -p 5432 -U dbowner -d brussels \ -c 'select berlinmod_generate(scaleFactor := 0.005)' # calls the main pgplsql function to start the simulation
If everything is correct, you should see an output like that starts with this:
INFO: ------------------------------------------------------------------ INFO: Starting the BerlinMOD data generator with scale factor 0.005 INFO: ------------------------------------------------------------------ INFO: Parameters: INFO: ------------ INFO: No. of vehicles = 141, No. of days = 4, Start day = 2020-06-01 INFO: Path mode = Fastest Path, Disturb data = f INFO: Verbosity = minimal, Trip generation = C ...
The generator will take about one minute. It will generate trajectories, according to the default parameters, for 141 cars over 4 days starting from Monday, June 1st 2020. As you may have guessed, it is possible to generate more or less data by respectively passing a bigger or a smaller scale factor value. If you want to save the messages produced by the generator in a file you can use a command such as the following one.
psql -h localhost -p 5432 -U dbowner -d brussels -c \ "SELECT berlinmod_generate(scaleFactor := 0.005, messages := 'medium')" 2>&1 | \ tee trace.txt
You can show more messages describing the generation process by setting the optional parameter messages
with one of the values minimal
(the default), medium
, verbose
, or debug
. In the section called “Customizing the Generator to Your City” are explained all the parameters that can be used to customize the simulation.
We have shown in Figure 1.2, “Visualization of the trips in QGIS. The streets are shown in blue, the trips are shown in black, the home nodes in black and the work nodes in red.” a visualization of the trips generated in QGIS.