We’ll look at how to download and prepare OpenStreetMap data for a network analysis, then at all the QGis processes grouped together under the heading Network Analysis.

We’ll look here at examples of road network analysis, but it’s clear that the same possibilities apply to any type of network: pipes, hydrographic, etc.

One of the most common uses of network analysis is to find the shortest (or fastest) path. This requires a topologically flawless network, i.e. one in which all sections are well connected to each other, and in which the digitization of the section has been carried out in the direction of travel (from the starting point to the end point of the section).

The hardest part of the job is bringing the network up to standard.

As far as the road network is concerned, we have data in OpenStreetMap that meets all these conditions.

For a given area, we have three sources of data, all available on the Geofabrik website: shapefiles, compressed .osm files and pbf files.

network analysis :download page on geofabrik.de with the different types of format available.

Preparing OSM data

Depending on the type of file you have chosen and your software configuration, the data preparation stage before you can use the network analysis tools can be more or less time-consuming and complicated.

If you only have QGis

If you don’t have a PostgreSQL / Postgis database, the format to download is the shapefile format. You won’t get all the information contained in the other formats, but for road network (or hydrographic) analysis you’ll have everything you need.

layers contained in the OSM shp file (geofabrik)

To work with QGis network analysis processes, we’ll be using the gis_osm_roads_free_1 layer.

If you have QGis and Postgis

Depending on the tools you use to load an OSM file into Postgis, you may choose either OSM or pbf format.

osm2pgrouting is a command-line utility for loading .osm format files into a PostgreSQL / Postgis database.

If you have osm2pgrouting

As its name suggests, it prepares OSM data by default for use with Postgis routing tools (pgrouting).

An example command line is shown below:

osm2pgrouting.exe –clean=1 -f fichier_telechargé.osm -d base_de_données -p 5433 -h localhost --schema uruguay -U postgres -W ******  -c mapconfig_for_cars.xml

-d indicates which database on your server the data should be loaded into

-p corresponds to the PostgreSQL server listening port

-W is the user password

-c the configuration file to be used for loading. osm2pgrouting offers three files, adapted for cars, pedestrians and bicycles.

ligne de commande de osm2pgrouting pour charger dans postgis un fichier .osm

The loading result is as follows:

tables created by osm2pgrouting in the postgis database

If you have osm2pgsql

osm2pgsql is a command-line utility for loading all OSM data from a .pbf file into a PostgreSQL / Postgis database.

An example command line is

C:\osm2pgsql\osm2pgsql-bin\osm2pgsql.exe -c -d postgis_33_sample -U postgres -W -H localhost -P 5433 -S default.style uruguay-latest.osm.pbf

The parameters are similar to those used by osm2pgrouting, except for the -S parameter which defines the style file to be used. You’ll find this default style file in the osm2pgsql-bin directory, in the osm2pgsql installation directory. It indicates which columns are to be created in the postgis table.

For our network analysis work, it’s likely that at some point we’ll use the maximum authorized speed of the sections to calculate the fastest route. Unfortunately, this parameter (maxspeed) is not included in the list of attributes to be created. For it to be created, a line must be added to the default.style file:

node,way maxspeed text linear

add line to default.style file for osm2pgsql

UOnce the command line has been executed:

run osm2pgsql command line to load into postgis

You’ll have four new tables in your Postgis database:


postgis tables created by osm2pgsql

Loading in QGis

For shp files, load the gis_osm_roads_free_1 layer.

load osm shapefile into qgis

For osm files processed with osm2pgrouting, load the ways table.

load file from osm2pgrouting into qgis

For pbf files processed with osm2pgsql, load the planet_osm_line table. Contrary to popular belief, the planet_osm_roads table contains only the main roads. In the planet_osm_line table, you’ll have all linear entities, not just the road network. To have only the roads, you need to apply a filter on the highway attribute to retain only those rows where this attribute is not NULL. If you want to work on the hydrographic network, the IS NOT NULL filter must be applied to the waterway attribute, and if you want to work on the railway network, the railway attribute must be filtered.

loading tables from osm2pgsql into qgis.

If you’re working on the scale of a small town or village, you can use a specific symbology.

network symbology with direction arrows

You can download these symbols in xml format from this link. To use them, open the style manager, click on import/export and point to the downloaded oneway.xml file.

symboles pour oneway osm avec Qgis

To apply them, open the layer properties gis_osm_roadfs_free_1 -> symbology. Select Categorized, value-> oneway.

You’ll get three classes with values B, F and T.

Apply the symbol

  • oneway_both to value B,
  • oneway_forward to value F,
  • oneway_opposite to value T.

You also have network_speed tags, which display the maximum speed of the section and must use the layer’s maxspeed field.

Si cet article vous a intéressé et que vous pensez qu'il pourrait bénéficier à d'autres personnes, n'hésitez pas à le partager sur vos réseaux sociaux en utilisant les boutons ci-dessous. Votre partage est apprécié !

Leave a Reply

Your email address will not be published. Required fields are marked *