Exemplo n.º 1
0
    def _collect_geo(nodes, path, transition_lane):
        geo = Geometry([
            GeoCoordinate(nodes[pair[0]]["data"].coord.lat,
                          nodes[pair[0]]["data"].coord.lng)
            for index, pair in enumerate(path) if index not in transition_lane
        ])

        # Adds the last coordinate for last node
        geo.coords += [
            GeoCoordinate(
                nodes[path[-1][1]]["data"].coord.lat,
                nodes[path[-1][1]]["data"].coord.lng,
            )
        ]
        return geo
Exemplo n.º 2
0
 def get_geometry(self, index=0):
     match = self.response["matchings"][index]
     match_geometry = []
     for leg in match["legs"]:
         match_geometry.extend(
             map(
                 lambda geo: GeoCoordinate(float(geo["lat"]),
                                           float(geo["lon"])),
                 leg["geometry"],
             ))
     return Geometry(match_geometry)
Exemplo n.º 3
0
 def node(self, n):
     """
     Node callback logic to osmium.SimpleHandler
     """
     geo = GeoCoordinate(lng=n.location.lon, lat=n.location.lat)
     metadata = dict(
         version=n.version,
         **{tag.k: tag.v
            for tag in n.tags},
         hd_edges=self.hd_mapping.get(n.id, []) if hasattr(
             self, "hd_mapping") else [],
     )
     node_data = Node(id=n.id, coord=geo, metadata=metadata)
     self.nodes[n.id] = node_data
Exemplo n.º 4
0
 def _get_edge(self, lane):
     return {
         "id":
         lane["id"],
         "from_edges":
         lane["fromLaneIdsList"],
         "to_edges":
         lane["toLaneIdsList"],
         "geometry":
         list(
             map(
                 lambda x: GeoCoordinate(float(x["lng"]), float(x["lat"])),
                 lane["centerLine"]["geometry"],
             )),
         "car_allowed":
         "CAR" in lane["restrictions"].get("allowedVehicleTypesList", []),
         "neighbours":
         self._get_lanes_changes(lane),
     }
def mock_path_generator(mocker):
    paths = [
        Path(
            geometry=Geometry([
                GeoCoordinate(lat=0, lng=0),
                GeoCoordinate(lat=1, lng=0),
                GeoCoordinate(lat=2, lng=0),
            ]),
            edges=[[1, 2]],
        ),
        Path(
            geometry=Geometry([
                GeoCoordinate(lat=1, lng=0),
                GeoCoordinate(lat=2, lng=0),
                GeoCoordinate(lat=3, lng=0),
            ]),
            edges=[[2, 3]],
        ),
    ]
    generate_mock = Mock(return_value=paths)
    mocker.patch.object(PathsGenerator, "generate", generate_mock)
    return paths, generate_mock
Exemplo n.º 6
0
def find_midpoint(geometry):
    start_coord = geometry[0]
    end_coord = geometry[-1]
    return GeoCoordinate((end_coord.lng + start_coord.lng / 2),
                         (end_coord.lat + start_coord.lat / 2))
Exemplo n.º 7
0
def interpolated_geometry(coord1, coord2):
    new_geometry = np.linspace(*[(coord.lat, coord.lng)
                                 for coord in (coord1, coord2)],
                               num=5)
    return [GeoCoordinate(point[0], point[1]) for point in new_geometry]
from unittest.mock import Mock

import pytest

from locintel.core.datamodel.geo import Geometry, GeoCoordinate
from locintel.core.datamodel.routing import Route, RoutePlan, Waypoint
from locintel.services.routing import MapboxResponseAdapter, GoogleResponseAdapter
from locintel.services.matching import MapboxMatcherResponseAdapter
"""
Fixtures for Response parsing
"""
lat1, lng1, lat2, lng2 = 10, 20, 15, 25
coord1 = GeoCoordinate(lat=lat1, lng=lng1)
coord2 = GeoCoordinate(lat=lat2, lng=lng2)
expected_geometry = Geometry([coord1, coord2])
geometry_mapbox_translation = [{
    "lat": lat1,
    "lon": lng1
}, {
    "lat": lat2,
    "lon": lng2
}]
geometry_google_translation = "_c`|@_gayB_qo]_qo]"
expected_distance = 100
expected_duration = 50
expected_route = Route(distance=expected_distance,
                       duration=expected_duration,
                       geometry=expected_geometry)
expected_geometry_index1 = Geometry([coord2, coord1, coord2, coord1])
geometry_index1_mapbox_translation = [
    {
nodes:        (1, 2, 3, 4, 5)

ways:         1: (1, 2, 3, {"oneway": true})
              2: (4, 2, 5, {"oneway": true})

restrictions: None

============================================================              
"""

base_nodes = {
    1:
    OsmNode(
        id=1,
        coord=GeoCoordinate(lng=-1.0, lat=0.0),
        ways=[],
        metadata={"hd_edges": "[]"},
    ),
    2:
    OsmNode(
        id=2,
        coord=GeoCoordinate(lng=0.0, lat=0.0),
        ways=[],
        metadata={"hd_edges": "[]"},
    ),
    3:
    OsmNode(
        id=3,
        coord=GeoCoordinate(lng=1.0, lat=0.0),
        ways=[],
Exemplo n.º 10
0
def test_get_angle():
    a = GeoCoordinate(1.0, 1.0)
    b = GeoCoordinate(2.0, 2.0)
    c = GeoCoordinate(1.0, 2.0)
    assert isclose(calculate_angle(a, b, c), 90.0, rel_tol=1e-6)
    assert isclose(calculate_angle(c, b, a), 45.0, rel_tol=1e-6)
Exemplo n.º 11
0
        1---2---3
                |
                4
                |
        7---6---5
        |
        8
            
"""

base_nodes = {
    1:
    OsmNode(
        id=1,
        coord=GeoCoordinate(lng=0, lat=0),
        metadata={
            "version": 1,
            "hd_edges": "[]"
        },
    ),
    2:
    OsmNode(
        id=2,
        coord=GeoCoordinate(lng=1, lat=0),
        metadata={
            "version": 1,
            "hd_edges": "[]"
        },
    ),
    3:
Exemplo n.º 12
0
              5: (4, 10, 13, 12, 11, {})
              6: (5, 15, {})
              7: (11, 14, {})

restrictions: 1: (w5@from, n4@via, w2@to)
              2: (w7@from, w2@via, w5@to)

========================================================

"""
expected_nodes = {
    1: {
        "data":
        Node(
            id=1,
            coord=GeoCoordinate(lng=-1, lat=0),
            metadata={
                "version": 1,
                "hd_edges": []
            },
        )
    },
    2: {
        "data":
        Node(
            id=2,
            coord=GeoCoordinate(lng=0, lat=0),
            metadata={
                "version": 1,
                "hd_edges": []
            },
Exemplo n.º 13
0
graph = graph

expected_paths_edges = [
    [(4, 6), (6, 7), (7, 8), (8, 9), (9, 10), (10, 0)],
    [(6, 7), (7, 8), (8, 9), (9, 10), (10, 0), (0, 1), (1, 2), (2, 3), (3, 4),
     (4, 5)],
    [(0, 1), (1, 2), (2, 3), (3, 4), (4, 6), (6, 15)],
    [(2, 3), (3, 4), (4, 6), (6, 7), (7, 8), (8, 2), (2, 16)],
    [(2, 3), (3, 4), (4, 6), (6, 7), (7, 8), (8, 11), (11, 13)],
    [(14, 12), (12, 9), (9, 10), (10, 0), (0, 1), (1, 2), (2, 3)],
    [(9, 10), (10, 0), (0, 1), (1, 2), (2, 3), (3, 17), (17, 18)],
]

expected_paths = []
for path_edges in expected_paths_edges:
    path = Path(geometry=Geometry([
        GeoCoordinate(lat=coordinates[node_1].lat, lng=coordinates[node_1].lng)
        for node_1, node_2 in path_edges
    ]))

    # Adds the last coordinate for last node
    path.geometry.coords = path.geometry.coords + [
        GeoCoordinate(
            lat=coordinates[path_edges[-1][1]].lat,
            lng=coordinates[path_edges[-1][1]].lng,
        )
    ]

    expected_paths.append(path)
Exemplo n.º 14
0
 def to_geocoordinate(self):
     return GeoCoordinate(self.lat, self.lng, self.alt)