Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix valhalla road id assignment; bump version #184

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Loading