aboutsummaryrefslogtreecommitdiffstats
path: root/pbf2db/pbf2db.py
diff options
context:
space:
mode:
authorslomo <steve.harrison@gmx.net>2011-01-09 02:29:00 +0100
committerslomo <steve.harrison@gmx.net>2011-01-09 02:29:00 +0100
commita1c5e0674a2431e8fef080ed0eea7e5eb8e0feab (patch)
treeb675cd23c2146ea5bf402774fa161cf38d659c67 /pbf2db/pbf2db.py
parent9adc1a65ba87963db5de9c3aa15604cf56121794 (diff)
parent186c67f2b33b09d4df776e0fba19f1085a2da88d (diff)
downloadosm-xapi-a1c5e0674a2431e8fef080ed0eea7e5eb8e0feab.tar.gz
osm-xapi-a1c5e0674a2431e8fef080ed0eea7e5eb8e0feab.tar.xz
osm-xapi-a1c5e0674a2431e8fef080ed0eea7e5eb8e0feab.zip
Merge branch 'master' of github.com:slomo/osm-spline-xapi
Diffstat (limited to 'pbf2db/pbf2db.py')
-rwxr-xr-xpbf2db/pbf2db.py44
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
+