I want to extract all major roads (motorway, trunk, primary, secondary) of the world from OSM data. So far I downloaded the continent.osm.pbf files. Now I need to convert them into .shp-format. Searching for a way to do so I found the ogr2ogr-tool and so far, it extracts all lines to a sqlite database.

ogr2ogr -f SQLite continent.sqlite continent.osm.pbf lines

Now I also wanted to edit the osmconf.ini file, so that it only includes highways with the tag: motorway, trunk, primary, secondary. I deleted other keys such as waterway,aerialway from the file, but it does not exclude them from the sqlite-database.

# keys to report as OGR fields 

Further, I just want highways with the tags "motorway, trunk, primary, secondary", but the only line where it seems to be possible to select them is the following line, which I do not understand fully

z_order_sql="SELECT (CASE [highway] WHEN 'minor' THEN 3 WHEN 'road' THEN 3 WHEN 'unclassified' THEN 3 WHEN 'residential' THEN 3 WHEN 'tertiary_link' THEN 4 WHEN 'tertiary' THEN 4 WHEN 'secondary_link' THEN 6 WHEN 'secondary' THEN 6 WHEN 'primary_link' THEN 7 WHEN 'primary' THEN 7 WHEN 'trunk_link' THEN 8 WHEN 'trunk' THEN 8 WHEN 'motorway_link' THEN 9 WHEN 'motorway' THEN 9 ELSE 0 END) + (CASE WHEN [bridge] IN ('yes', 'true', '1') THEN 10 ELSE 0 END) + (CASE WHEN [tunnel] IN ('yes', 'true', '1') THEN -10 ELSE 0 END) + (CASE WHEN [railway] IS NOT NULL THEN 5 ELSE 0 END) + (CASE WHEN [layer] IS NOT NULL THEN 10 * CAST([layer] AS INTEGER) ELSE 0 END)"

I found the wiki.openstreetmap blog entry, describing how to edit the osmconf.ini, but it also did not clarify things for me.

So my question is: Can I edit the osmconf.ini file in such a way that it only extracts major roads from the OSM-file or do I have to do this in a separate step in my sqlite-database and export it just then to QGIS?

  • 1
    If you edited the lines section of the osmconf.ini and removed waterways and aerialways they should really not get included. Could it be possible that you have several osmconf.ini and you have edited wrong file? z_order sql is certainly not what you should edit. Study the -sql option of ogr2ogr. Or -where, it should work with your simple use case.
    – user30184
    Aug 25, 2020 at 19:20
  • 1
    I would use -f SQLite -dsco spatialite=yes instead of plain -f SQLite. Or perhaps -f gpkg but it depends on what you plan to do with your data later.
    – user30184
    Aug 25, 2020 at 19:29

1 Answer 1


Indeed, I actually had four distinct osmconf.ini files on my system, all in different subfolders of R, thanks for the comment @user30184. The following lines produced what I wanted, only highway lines excluding minor roads. So in the end, I did not even have to change the osmconf.ini file at all.

ogr2ogr -where "highway='trunk' OR highway='motorway' OR highway='primary' OR highway='secondary'" output-streets.shp input.osm.pbf lines

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.