OsmDB.pm

From OpenStreetMap Wiki
Jump to: navigation, search

osmDB.pm is a module (in extension to osm.pm) to transfer data extracted from an osm file into a mysql database. It also provides functions to access this data. Of course some things are reinvented here...

Contents

Motivation

With the growing size of germany.osm (or osm in general) it is becoming harder by the day to handle all this data. Especially if not enough RAM is present. So I decided to move the data from the osm file (and RAM) to disk. On the one hand this will be convenient because all data is present. On the other hand this will significantly slow down some tasks. Otherwise I always wanted to do something with an sql server (again).

Setup

Programs used

Performance

Diff files

To keep your data up to date you can either load a new extract or use two osm files and osmosis to create an osc file. This can be used to update your database. If you are using a planet file these osc files are provided on a regular basis.

Data recall

Single objects

dbConnect ($databaseName) ;
my ($refProperties, $refTags) = getDBnode ($nodeId) ;
my %properties = %$refProperties ;
my @tags = @$refTags
dbDisconnect ($databaseName) ;

Loops

dbConnect ($databaseName) ;
loopInitNodes(null, null) ; # for all nodes
# loopInitNodes("place", "city") ; # only place=city
my $id = loopGetNextNode() ;
my ($refProperties, $refTags) = getDBNode ($id) ;
while (defined $properties) {
   ...
   # next
   $id = loopGetNextNode() ;
   ($refProperties, $refTags) = getDBNode ($id) ;
}
dbDisconnect ($databaseName) ;

Tags (key/values)

my ($name) = getTag ($type, $objectId, $key) ;
my ($name2) = getTag ("node", 12345, "name") ;
my ($ref) = getTag ("way", 12345, "ref") ;

Coordinates for waynodes

my ($lonRef, $latRef) = getDBWayNodesCoords ($wayId) ; # returns refs to hashes (keys = nodeId)

Data manipulation

deleteDBNode ($id)
deleteDBWay ($id)
deleteDBRelation ($id)
storeDBNode ($propRef, $tagRef)
storeDBWay ($propRef, $nodeRef, $tagRef)
storeDBRelation ($propRef, $memberRef, $tagRef)

Tables

The following tables will be created:

The ids, keys and values are indexed (k/v only first 12 characters to save time and space)

Source

Personal tools
Namespaces
Variants
Actions
site
Toolbox