Exemplo n.º 1
0
 def __init__(self, filename):
     """Initialize the class with the filename of the pbf you want to parse"""
     self.filename = filename
     self.tags = {}  # content is {key: set(values)}, ...
     self.nodes = []
     if getattr(self, 'fpbf', None):
         self.fpbf.close()
     self.fpbf = open(self.filename, 'rb')
     self.blobhead = fileformat_pb2.BlobHeader()
     self.blob = fileformat_pb2.Blob()
     self.hblock = osmformat_pb2.HeaderBlock()
     self.primblock = osmformat_pb2.PrimitiveBlock()
     self.membertype = {0: 'node', 1: 'way', 2: 'relation'}
     if not self._read_pbf_blob_header():
         return False
     #read the blob
     if not self._read_blob():
         return False
     #check the contents of the first blob are supported
     self.hblock.ParseFromString(self.BlobData)
     for rf in self.hblock.required_features:
         if rf in {"OsmSchema-V0.6", "DenseNodes"}:
             pass
         else:
             raise TypeError("not a required feature %s" % rf)
Exemplo n.º 2
0
 def __init__(self, filename):
     """Initialize the class with the filename of the pbf you want to parse"""
     self.filename = filename
     self.fpbf = open(self.filename, "r")
     self.tags = {}
     self.nodes = []
     self.blobhead = fileformat_pb2.BlobHeader()
     self.blob = fileformat_pb2.Blob()
     self.hblock = osmformat_pb2.HeaderBlock()
     self.primblock = osmformat_pb2.PrimitiveBlock()
     self.membertype = {0: 'node', 1: 'way', 2: 'relation'}
     if self.readPBFBlobHeader() == False:
         return False
     #read the blob
     if self.readBlob() == False:
         return False
     #check the contents of the first blob are supported
     self.hblock.ParseFromString(self.BlobData)
     for rf in self.hblock.required_features:
         if rf in ("OsmSchema-V0.6", "DenseNodes"):
             pass
         else:
             raise TypeError("not a required feature %s" % rf)
def go(pbf_filename, callback_node, callback_way, callback_relation):

    global pb2_blob_header
    global pb2_blob
    global pb2_header_block
    global pb2_primitve_block

    global pbf_file

    global cb_node
    global cb_way
    global cb_relation

    cb_node     = callback_node
    cb_way      = callback_way
    cb_relation = callback_relation

    if  not os.path.exists(pbf_filename) :
        print "The binary file %s cannot be found" % (pbf_filename)
        sys.exit(1)

    pbf_file = open(pbf_filename, "rb")

    pb2_blob_header=fileformat_pb2.BlobHeader()
    pb2_blob=fileformat_pb2.Blob()
    pb2_header_block=osmformat_pb2.HeaderBlock()

    pb2_primitve_block=osmformat_pb2.PrimitiveBlock()

    if check_pbf_file_header("pbfparser.py 1.3")==False:
        print "Header trouble"
        exit(1)

    parse()

    pbf_file.close()