pyroutelib3.osm.reader

pyroutelib3.osm.reader.read_features(buf: IO[bytes], format: Literal['xml', 'gz', 'bz2', 'pbf'] | None = None, chunk_size: int = 8192) Iterable[Node | Way | Relation]

read_features_from_xml generates Feature instances from a possibly-compressed OSM XML or a OSM PBF file.

If format is not provided, this function will check if buf.name ends with .gz or .bz2 to determine whether the provided buffer needs to be decompressed, or .pbf to use the protocol buffer deserializer. If the file format cannot be determined, assumes that data will be in uncompressed XML format.

The chunk_size argument controls the size of XML data chunks read from the XML stream, after decompression. Read calls to buf of chunk_size are only guaranteed for non-compressed XML files. Size of the read calls for gzip or bz2 compressed XML files depends on the inner workings of the gz and bz2 modules, while for pbf files read calls can range from 4 bytes to 32 MiB, depending on the size of the object being deserialized.

pyroutelib3.osm.reader.collect_all_features(buf: IO[bytes], format: Literal['xml', 'gz', 'bz2', 'pbf'] | None = None, chunk_size: int = 8192) Tuple[List[Node], List[Way], List[Relation]]

collect_all_features reads all Feature instances from a possibly-compressed OSM XML or a OSM PBF file.

format and chunk_size are passed through to osm.reader.read_features().

pyroutelib3.osm.reader.Feature

Feature represents a single OpenStreetMap feature: a Node, Way or Relation.

alias of Node | Way | Relation

class pyroutelib3.osm.reader.Node(id: int, position: ~typing.Tuple[float, float], tags: ~typing.Dict[str, str] = <factory>)

Bases: object

Node represents a single OpenStreetMap node.

id: int
position: Tuple[float, float]
tags: Dict[str, str]
class pyroutelib3.osm.reader.Way(id: int, nodes: ~typing.List[int] = <factory>, tags: ~typing.Dict[str, str] = <factory>)

Bases: object

Way represents a single OpenStreetMap way.

is_closed() bool
id: int
nodes: List[int]
tags: Dict[str, str]
class pyroutelib3.osm.reader.RelationMember(type: Literal['node', 'way', 'relation'], ref: int, role: str)

Bases: object

RelationMember represents a single member of a OpenStreetMap relation.

ref: int
role: str
type: Literal['node', 'way', 'relation']
class pyroutelib3.osm.reader.Relation(id: int, members: ~typing.List[~pyroutelib3.osm.reader.RelationMember] = <factory>, tags: ~typing.Dict[str, str] = <factory>)

Bases: object

Relation represents a single OpenStreetMap relation.

id: int
members: List[RelationMember]
tags: Dict[str, str]
exception pyroutelib3.osm.reader.PBFError

Bases: ValueError

Exception raised by read_features() on invalid OSM PBF encoding.

pyroutelib3.osm.reader.FILE_FORMAT_T

Type of the format argument of read_features().

Useful when passing this argument forward from custom functions.

alias of Literal[‘xml’, ‘gz’, ‘bz2’, ‘pbf’] | None

pyroutelib3.osm.reader.DEFAULT_FILE_FORMAT = None

Default value for the format argument of read_features().

Useful when passing this argument forward from custom functions.

pyroutelib3.osm.reader.DEFAULT_CHUNK_SIZE = 8192

Default value for chunk_size argument of read_features(), io.DEFAULT_BUFFER_SIZE.

Useful when passing this argument forward from custom functions.