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
Featureinstances from a possibly-compressed OSM XML or a OSM PBF file.If
formatis not provided, this function will check ifbuf.nameends with.gzor.bz2to determine whether the provided buffer needs to be decompressed, or.pbfto use the protocol buffer deserializer. If the file format cannot be determined, assumes that data will be in uncompressed XML format.The
chunk_sizeargument controls the size of XML data chunks read from the XML stream, after decompression. Read calls tobufofchunk_sizeare 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 thegzandbz2modules, while forpbffiles 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
Featureinstances from a possibly-compressed OSM XML or a OSM PBF file.formatandchunk_sizeare passed through toosm.reader.read_features().
- pyroutelib3.osm.reader.Feature¶
Feature represents a single OpenStreetMap feature: a
Node,WayorRelation.
- class pyroutelib3.osm.reader.Node(id: int, position: ~typing.Tuple[float, float], tags: ~typing.Dict[str, str] = <factory>)¶
Bases:
objectNode 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:
objectWay 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:
objectRelationMember 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:
objectRelation represents a single OpenStreetMap relation.
- id: int¶
- members: List[RelationMember]¶
- tags: Dict[str, str]¶
- exception pyroutelib3.osm.reader.PBFError¶
Bases:
ValueErrorException raised by
read_features()on invalid OSM PBF encoding.
- pyroutelib3.osm.reader.FILE_FORMAT_T¶
Type of the
formatargument ofread_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
formatargument ofread_features().Useful when passing this argument forward from custom functions.
- pyroutelib3.osm.reader.DEFAULT_CHUNK_SIZE = 8192¶
Default value for
chunk_sizeargument ofread_features(), io.DEFAULT_BUFFER_SIZE.Useful when passing this argument forward from custom functions.