[GIS] Converting .osm.pbf to .shp

convertopenstreetmappbfrshapefile

The website http://download.geofabrik.de/north-america.html does not have shapefiles (shp.zip) for sizable states or countries.

How do you convert the available osm.pbf to shp.zip?

I have tried QGIS but it does not export all the shapefiles from (osm.pbf) to (shp).

I have tried R, but again, only exported a fraction of shapes.

library(rgdal)

osmfilename = 'california-latest.osm.pbf'
directory_name = 'shp_directory'
layer_name = 'output_layer'
osm <- readOGR(osmfilename, 'lines')
writeOGR(osm, directory_name, layer_name, driver = 'ESRI Shapefile')

Do you have any other way that I could try?

Best Answer

OSM data has a lot of different data types, tags, etc. It is probably best as a lot of different shape files. You could import it into a Spatialite file using either OGR2OGR or QGIS, and then extract each layer type that makes sense for your application. Eg. one for roads, one for roads, one for linear water features, another for polygon water features.

(as an aside, I am currently writing a QGIS plugin that will import certain "feature types" into layers from a PBF file. The required use case was for Admin Areas, but I am adding other feature types like water, buildings, etc. Let me know if you're interested in testing it. I intend to put it in the main plugin repository and on github)