Table Of Contents

Previous topic

Parsing API

This Page

Parsing

class imposm.parser.pbf.parser.PBFParser(nodes_callback=None, ways_callback=None, relations_callback=None, coords_callback=None, nodes_tag_filter=None, ways_tag_filter=None, relations_tag_filter=None, marshal=False)

OSM PBF parser.

Parameters:
  • xxx_callback – callback functions for coords, nodes, ways and relations. Each callback function gets called with a list of multiple elements.
  • xxx_filter – functions that can manipulate the tag dictionary. Nodes and relations without tags will not passed to the callback.
  • marshal – return the data as a marshaled string
parse(filename, offset, size)

Parse primitive block from filename.

Parameters:
  • filename – path to PBF file
  • offset – byte offset of the primitive block to parse
  • size – size in bytes of the primitive block to parse

Low level

class imposm.parser.pbf.parser.PBFFile(filename)

OSM PBF file reader.

Parses the low-level file structure with header sizes, offsets and blob headers.

Parameters:filename – path to the PBF file
blob_offsets()

Returns an iterator of the blob offsets in this file.

Each offsets is stored in a dictionary with:

  • filename the path of this PBF file.
  • blob_pos the byte offset
  • blob_size the size of this blob in bytes
primitive_block_parsers()

Returns an iterator of PrimitiveBlockParser.

imposm.parser.pbf.parser.read_blob_zlib_data(filename, blob_pos, blob_size)

Returns the unzipped blob data from.

class imposm.parser.pbf.parser.PrimitiveBlockParser(filename, blob_pos, blob_size)

Low level PBF primitive block parser.

Parses a single primitive block and handles OSM PBF internals like dense nodes, delta encoding, stringtables, etc.

Parameters:
  • filename – path to PBF file
  • offset – byte offset of the primitive block to parse
  • size – size in bytes of the primitive block to parse
nodes()

Return an iterator for all nodes in this primitive block.

Return type:iterator of (osm_id, tags, (lon, lat)) tuples
relations()

Return an iterator for all relations in this primitive block.

Return type:iterator of (osm_id, tags, [(ref1, type, role), ...]) tuples
ways()

Return an iterator for all ways in this primitive block.

Return type:iterator of (osm_id, tags, [ref1, ref2, ...]) tuples