mappymatch.constructs.road#
Classes
|
Represents a road segment in the road network that can be matched to GPS trajectories. |
|
- class mappymatch.constructs.road.RoadId(start, end, key)[source]#
- start: int | str | None#
Alias for field number 0
- end: int | str | None#
Alias for field number 1
- key: int | str | None#
Alias for field number 2
- class mappymatch.constructs.road.Road(road_id: RoadId, geom: LineString, metadata: dict | None = None)[source]#
Represents a road segment in the road network that can be matched to GPS trajectories.
A Road is an immutable object representing a directional edge in a road network graph. Roads have a unique identifier (composed of start/end junctions and a key), a geometry (typically a LineString), and optional metadata for storing additional attributes like speed limits, road names, etc.
- Attributes:
road_id: A RoadId tuple uniquely identifying this road segment (start, end, key) geom: The Shapely LineString geometry representing the road's path metadata: An optional dictionary for storing additional road attributes such as speed limits, road names, surface type, etc.
- geom: LineString#
Alias for field number 1
- metadata: dict | None#
Alias for field number 2
- to_dict() Dict[str, Any][source]#
Convert the road to a dictionary representation.
This creates a dictionary with all road attributes, extracting the origin and destination junction IDs from the road_id for convenience.
- Returns:
A dictionary containing the road's attributes with separate keys for origin_junction_id, destination_junction_id, and road_key
- to_flat_dict() Dict[str, Any][source]#
Convert the road to a flat dictionary with metadata unpacked.
This method creates a single-level dictionary by unpacking the metadata dictionary and merging it with the road's other attributes. This is useful for creating DataFrames or exporting to formats that don't support nested structures.
- Returns:
A flat dictionary with all road attributes and metadata fields at the top level. The 'metadata' key itself is removed.