nodetable is the fundamental table for open street map. Each node consists of a longitude (
lon) / latitude (
lat) pair and thus defines a geographical point on the surface of the earth. The original schema has a few more attributes, such as
version. I am not interested in these, so I don't load them:
Tables way and node_in_wayEach "line" (such as a street or border etc) on open street map is an ordered list of nodes. Open Street Map calles them ways. Ways are also used to define areas in which case the last node equals the first node in the list.
First, I need a table just to store each way. Again, I am not interested in attributes such as
changeset, so I just load the way's
node_in_wayrelates nodes and ways:
Tables relation and member_in_relationOpen Street Map allows to relate multipe nodes and ways (and even relations) in a relation:
Each member (that is either node, way or relation) is listed in
Thus, exactly one of the attributes
is not null:
Table tagFinally, there are tags. A tag is a key (
k) value (
v) pair that can be assigned to nodes, ways or relations. Often, the values for specific keys define what an object is. As in
member_in_relationexactly on of
relation_idis not null.
ERDHere's the ERD for these tables:
The ERD was created with dia from pbf2sqlite-erd.dia.
Loading the pbf to a sqlite dbIn order to run the script, a pbf must be obtained, for example with download-switzerland-pbf.py.
Then, this pbf can be loaded into a sqlite db on the command line with
The script is on github: pbf2sqlite.py.Parsing an Open Street Map pbf file with Python