TransWikia.com

Converting osm.pbf to shp-format using ogr2ogr to extract major highways

Geographic Information Systems Asked by jreith on January 28, 2021

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 
attributes=name,highway

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?

One Answer

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

Answered by jreith on January 28, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP