diff --git a/mappymatch/constructs/road.py b/mappymatch/constructs/road.py index 442e1b0..240b998 100644 --- a/mappymatch/constructs/road.py +++ b/mappymatch/constructs/road.py @@ -6,9 +6,9 @@ class RoadId(NamedTuple): - start: Union[int, str] - end: Union[int, str] - key: Union[int, str] + start: Optional[Union[int, str]] + end: Optional[Union[int, str]] + key: Optional[Union[int, str]] def to_string(self) -> str: return f"{self.start},{self.end},{self.key}" diff --git a/mappymatch/matchers/valhalla.py b/mappymatch/matchers/valhalla.py index 3c40968..561fabd 100644 --- a/mappymatch/matchers/valhalla.py +++ b/mappymatch/matchers/valhalla.py @@ -10,7 +10,7 @@ from shapely.geometry import LineString from mappymatch.constructs.match import Match -from mappymatch.constructs.road import Road +from mappymatch.constructs.road import Road, RoadId from mappymatch.constructs.trace import Trace from mappymatch.matchers.matcher_interface import MatcherInterface, MatchResult from mappymatch.utils.crs import LATLON_CRS @@ -45,6 +45,7 @@ def build_path_from_result( path = [] for edge in edges: way_id = edge["way_id"] + road_id = RoadId(start=None, end=None, key=way_id) start_point_i = edge["begin_shape_index"] end_point_i = edge["end_shape_index"] start_point = shape[start_point_i] @@ -59,7 +60,7 @@ def build_path_from_result( "length_miles": length, } - road = Road(road_id=way_id, geom=geom, metadata=metadata) + road = Road(road_id=road_id, geom=geom, metadata=metadata) path.append(road) diff --git a/pyproject.toml b/pyproject.toml index ed2cd36..f7f6fc8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "mappymatch" -version = "0.4.2" +version = "0.4.3" description = "Package for mapmatching." readme = "README.md" authors = [{ name = "National Renewable Energy Laboratory" }] diff --git a/tests/test_valhalla.py b/tests/test_valhalla.py new file mode 100644 index 0000000..47e7553 --- /dev/null +++ b/tests/test_valhalla.py @@ -0,0 +1,21 @@ +from unittest import TestCase + +from mappymatch.constructs.trace import Trace +from mappymatch.matchers.valhalla import ValhallaMatcher +from tests import get_test_dir + + +class TestTrace(TestCase): + def test_valhalla_on_small_trace(self): + file = get_test_dir() / "test_assets" / "test_trace.geojson" + + trace = Trace.from_geojson(file, xy=False) + + matcher = ValhallaMatcher() + + result = matcher.match_trace(trace) + + match_df = result.matches_to_dataframe() + _ = result.path_to_dataframe() + + self.assertEqual(len(match_df), len(trace))