Skip to content

Commit

Permalink
[#35] Add str and repr functions to NxMap
Browse files Browse the repository at this point in the history
  • Loading branch information
machallboyd committed Jun 23, 2022
1 parent 1d8699b commit cad702b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions mappymatch/constructs/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ class Trace:
def __init__(self, frame: GeoDataFrame):
self._frame = frame


def __getitem__(self, i) -> Trace:
if isinstance(i, int):
i = [i]
new_frame = self._frame.iloc[i]
return Trace(new_frame)


def __add__(self, other: Trace) -> Trace:
if self.crs != other.crs:
raise TypeError(
Expand Down
13 changes: 12 additions & 1 deletion mappymatch/maps/nx/nx_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
DEFAULT_GEOMETRY_KEY = "geometry"
DEFAULT_ROAD_ID_KEY = "road_id"


class NxMap(MapInterface):
"""
A road map that uses a networkx graph to represent its roads.
Expand Down Expand Up @@ -62,6 +61,7 @@ def __init__(self, graph: nx.MultiDiGraph):
self._nodes = [nid for nid in self.g.nodes()]
self._roads = self._build_rtree()


def _build_rtree(self) -> List[Road]:
road_lookup = []

Expand All @@ -85,6 +85,17 @@ def _build_rtree(self) -> List[Road]:
self.rtree = idx
return road_lookup

def __str__(self):
output_lines = [
'Mappymatch NxMap object',
f'roads: {len(self._roads)} Road objects',
f'graph: {self.g}',
]
return '\n'.join(output_lines)

def __repr__(self):
return self.__str__()

@property
def roads(self) -> List[Road]:
return self._roads
Expand Down

0 comments on commit cad702b

Please sign in to comment.