How to use the osmnx.great_circle_vec function in osmnx

To help you get started, we’ve selected a few osmnx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ppintosilva / anprx / tests / test_core.py View on Github external
candidate_nodes = { edge[0] for edge in candidate_edges } | \
                      { edge[1] for edge in candidate_edges }

    nodes_lvectors, edges_lvectors = \
        core.local_coordinate_system(
            network = network,
            origin = point,
            nodes = candidate_nodes,
            edges = candidate_edges)

    assert len(nodes_lvectors) == len(candidate_nodes)
    assert len(edges_lvectors) == len(candidate_edges)

    for id in candidate_nodes:
        ox_distance = ox.great_circle_vec(
            lat1 = network.node[id]['y'],
            lng1 = network.node[id]['x'],
            lat2 = point.lat,
            lng2 = point.lng)

        lvector = nodes_lvectors[id]
        lvector_distance = math.sqrt(lvector[0] ** 2 + lvector[1] ** 2)

        np.testing.assert_almost_equal(
            ox_distance,
            lvector_distance,
            decimal = 6)
github ppintosilva / anprx / anprx / core.py View on Github external
edge : Edge
        network edge

    point : point
        point

    method : EdgeDistanceMethod
        metric used to compute distance to edge

    Returns
    -------
    float
        distance from point to edge according to distance metric
    """
    distance_node_from = ox.great_circle_vec(
                                lat1 = point.lat,
                                lng1 = point.lng,
                                lat2 = network.node[edge.u]['y'],
                                lng2 = network.node[edge.u]['x'],
                                earth_radius = earth_radius(unit = Units.m))

    distance_node_to = ox.great_circle_vec(
                                lat1 = point.lat,
                                lng1 = point.lng,
                                lat2 = network.node[edge.v]['y'],
                                lng2 = network.node[edge.v]['x'],
                                earth_radius = earth_radius(unit = Units.m))

    distances = [ distance_node_to, distance_node_from ]

    if method == EdgeDistanceMethod.closest_node:
github ppintosilva / anprx / anprx / core.py View on Github external
Parameters
    ----------
    origin : Point
        point used as origin in the new coordinate system

    point : Point
        target Point to be represented in the new coordinate system

    Returns
    -------
    np.ndarray
        vector representing the target Point in the new (local) cartesian coordinate system

    """
    r = ox.great_circle_vec(lat1 = origin.lat,
                            lat2 = point.lat,
                            lng1 = origin.lng,
                            lng2 = point.lng,
                            earth_radius = earth_radius(Units.m))

    phi = ox.get_bearing(origin, point)

    x = r * math.cos(np.deg2rad(90 - phi))
    y = r * math.sin(np.deg2rad(90 - phi))

    return np.array([x,y])
github ppintosilva / anprx / anprx / navigation.py View on Github external
edge : Edge
        network edge

    point : point
        point

    method : EdgeDistanceMethod
        metric used to compute distance to edge

    Returns
    -------
    float
        distance from point to edge according to distance metric
    """
    distance_node_from = ox.great_circle_vec(
                                lat1 = point.lat,
                                lng1 = point.lng,
                                lat2 = network.node[edge.u]['y'],
                                lng2 = network.node[edge.u]['x'],
                                earth_radius = earth_radius(unit = Units.m))

    distance_node_to = ox.great_circle_vec(
                                lat1 = point.lat,
                                lng1 = point.lng,
                                lat2 = network.node[edge.v]['y'],
                                lng2 = network.node[edge.v]['x'],
                                earth_radius = earth_radius(unit = Units.m))

    distances = [ distance_node_to, distance_node_from ]

    if method == EdgeDistanceMethod.closest_node:
github ppintosilva / anprx / anprx / core.py View on Github external
method : EdgeDistanceMethod
        metric used to compute distance to edge

    Returns
    -------
    float
        distance from point to edge according to distance metric
    """
    distance_node_from = ox.great_circle_vec(
                                lat1 = point.lat,
                                lng1 = point.lng,
                                lat2 = network.node[edge.u]['y'],
                                lng2 = network.node[edge.u]['x'],
                                earth_radius = earth_radius(unit = Units.m))

    distance_node_to = ox.great_circle_vec(
                                lat1 = point.lat,
                                lng1 = point.lng,
                                lat2 = network.node[edge.v]['y'],
                                lng2 = network.node[edge.v]['x'],
                                earth_radius = earth_radius(unit = Units.m))

    distances = [ distance_node_to, distance_node_from ]

    if method == EdgeDistanceMethod.closest_node:
        return min(distances)

    elif method == EdgeDistanceMethod.farthest_node:
        return max(distances)

    elif method == EdgeDistanceMethod.sum_of_distances:
        return sum(distances)
github ppintosilva / anprx / anprx / navigation.py View on Github external
method : EdgeDistanceMethod
        metric used to compute distance to edge

    Returns
    -------
    float
        distance from point to edge according to distance metric
    """
    distance_node_from = ox.great_circle_vec(
                                lat1 = point.lat,
                                lng1 = point.lng,
                                lat2 = network.node[edge.u]['y'],
                                lng2 = network.node[edge.u]['x'],
                                earth_radius = earth_radius(unit = Units.m))

    distance_node_to = ox.great_circle_vec(
                                lat1 = point.lat,
                                lng1 = point.lng,
                                lat2 = network.node[edge.v]['y'],
                                lng2 = network.node[edge.v]['x'],
                                earth_radius = earth_radius(unit = Units.m))

    distances = [ distance_node_to, distance_node_from ]

    if method == EdgeDistanceMethod.closest_node:
        return min(distances)

    elif method == EdgeDistanceMethod.farthest_node:
        return max(distances)

    elif method == EdgeDistanceMethod.sum_of_distances:
        return sum(distances)