Extract Node Lat/lon from .osm.pbf file in python

Hi guys,

So i’ve download my great britain .osm.pbf file and all i want to be able to do is within python extract all nodes and their relevant lat/lon and then store this in python to lookup.


I’m not sure what “store this in python” means - Python is a programming language rather than a database. You might also want to rethink “all the nodes” since there are a lot of them, and most of them will just be part of ways.

However, if you follow one of the https://switch2osm.org/serving-tiles/ options you’ll get a postgresql/postgis database that you can then query (including from Python). If you don’t want to create a map you can ignore anything map-related (“Shapefile download” onwards), although a map is sometimes the easiest way to look at data :slight_smile:

The OSM tags that cause objects to actually go into the database is determined by the “openstreetmap-carto.style” file, essentially a list of “things that you define that you are interested in”.

A database is probably unnecessary if the goal is just to read all the nodes (or perhaps all nodes with tags) from a medium-sized .osm.pbf file, which is how I would interpret the question.

I would look into a library for reading .osm.files, like pyosmium.

Turns out the same question was also asked on StackOverflow, and I’ve provided an answer over there.