Skip to content

Commit

Permalink
Merge pull request #184 from NREL/ndr/fix-valhalla-matcher
Browse files Browse the repository at this point in the history
fix valhalla road id assignment; bump version
  • Loading branch information
nreinicke authored May 28, 2024
2 parents 6806d85 + b8b39e5 commit c09800f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
6 changes: 3 additions & 3 deletions mappymatch/constructs/road.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
5 changes: 3 additions & 2 deletions mappymatch/matchers/valhalla.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }]
Expand Down
21 changes: 21 additions & 0 deletions tests/test_valhalla.py
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit c09800f

Please sign in to comment.