diff options
author | Robin Nehls <nehls@mi.fu-berlin.de> | 2011-01-09 02:02:08 +0100 |
---|---|---|
committer | Robin Nehls <nehls@mi.fu-berlin.de> | 2011-01-09 02:27:13 +0100 |
commit | 186c67f2b33b09d4df776e0fba19f1085a2da88d (patch) | |
tree | b14266c3cfb8f373399bdce3680a2d071847ab0d /pbf2db/pbf2db.py | |
parent | 8b44fe1d3a298ee0772b08e41eb1ffca7288e4bb (diff) | |
download | osm-xapi-186c67f2b33b09d4df776e0fba19f1085a2da88d.tar.gz osm-xapi-186c67f2b33b09d4df776e0fba19f1085a2da88d.tar.xz osm-xapi-186c67f2b33b09d4df776e0fba19f1085a2da88d.zip |
first code for the db import tool
it only reads the osm header of pbf files for now, more will follow
Diffstat (limited to 'pbf2db/pbf2db.py')
-rwxr-xr-x | pbf2db/pbf2db.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/pbf2db/pbf2db.py b/pbf2db/pbf2db.py new file mode 100755 index 0000000..c6089fc --- /dev/null +++ b/pbf2db/pbf2db.py @@ -0,0 +1,44 @@ +#!/usr/bin/python + +import osmformat_pb2 +import fileformat_pb2 +import sys +import socket +import zlib +from binarystream import BinaryStream + + +headerSizeMax = 64 * 1024 +bodySizeMax = 32*1024*1024 + +f = open("berlin.osm.pbf") +stream = BinaryStream(f) +headerSize = socket.ntohl(stream.readUInt32()); + +if headerSizeMax < headerSize: + raise ValueError("Header to long") + +headerbuff = stream.readBytes(headerSize) +blobheader = fileformat_pb2.BlobHeader() +blobheader.ParseFromString(headerbuff) +bodysize = blobheader.datasize + +if bodySizeMax < bodysize: + raise ValueError("Body to fat") + +blobbuff = stream.readBytes(bodysize) +blob = fileformat_pb2.Blob() +blob.ParseFromString(blobbuff) + +if blob.raw != "": + rawstr = blob.raw +else: + rawstr = zlib.decompress(blob.zlib_data) + +headerblock = osmformat_pb2.HeaderBlock() +headerblock.ParseFromString(rawstr) + +print "Source:",headerblock.source +print "Writingprog:",headerblock.writingprogram +print "required features:",headerblock.required_features + |