How to use the osmnx.graph_from_bbox 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 gboeing / osmnx / tests / test_osmnx.py View on Github external
def test_nearest_edges():
    from pyproj import Proj

    # test in closest edge section
    sheik_sayed_dubai = [25.09, 25.06, 55.16, 55.11]
    location_coordinates = (25.071764, 55.138978)
    G = ox.graph_from_bbox(*sheik_sayed_dubai, simplify=False, retain_all=True, network_type='drive')

    # Unprojected
    ne1 = ox.get_nearest_edges(G, X=[location_coordinates[1], location_coordinates[1]],
                               Y=[location_coordinates[0], location_coordinates[0]], method='balltree', dist=0.0001)

    # Projected
    G2 = ox.project_graph(G)
    crs = Proj(G2.graph['crs'])

    projected_point = crs(location_coordinates[1], location_coordinates[0])
    ne2 = ox.get_nearest_edges(G2, X=[projected_point[0], projected_point[0]],
                               Y=[projected_point[1], projected_point[1]], method='kdtree', dist=10)
    assert (ne1 == ne2).all()
github gboeing / osmnx / tests / test_osmnx.py View on Github external
def test_nearest_edge():
    # test in closest edge section
    sheik_sayed_dubai = [25.09, 25.06, 55.16, 55.11]
    location_coordinates = (25.071764, 55.138978)
    G = ox.graph_from_bbox(*sheik_sayed_dubai, simplify=False, retain_all=True, network_type='drive')
    geometry, u, v = ox.get_nearest_edge(G, location_coordinates)
github ppintosilva / anprx / anprx / navigation.py View on Github external
Returns
    -------
    nx.MultiDiGraph
        a graph representing the street network
    """

    bbox = bbox_from_points(
        points = points,
        rel_margins = rel_margins,
        min_area = min_area,
        max_area = max_area,
        unit = unit)


    street_network = \
        ox.graph_from_bbox(
            north = bbox.north,
            south = bbox.south,
            east = bbox.east,
            west = bbox.west,
            network_type = "drive_service",
            simplify = True,
            retain_all = False,
            truncate_by_edge = False,
            name = graph_name,
            timeout = 180,
            memory = None,
            clean_periphery = True,
            infrastructure = 'way["highway"]',
            custom_filter = None)

    return street_network
github nismod / digital_comms / scripts / network_preprocess_input_files.py View on Github external
def estimate_asset_locations_on_road_network(origins, area):
    '''
    Put a cabinet in the representative center of the set of premises served by it
    '''
    ox.config(log_file=False, log_console=False, use_cache=True)

    projUTM = Proj(init='epsg:27700')
    projWGS84 = Proj(init='epsg:4326')

    new_asset_locations = []

    try:
        east, north = transform(projUTM, projWGS84, shape(area['geometry']).bounds[2], shape(area['geometry']).bounds[3])
        west, south = transform(projUTM, projWGS84, shape(area['geometry']).bounds[0], shape(area['geometry']).bounds[1])
        G = ox.graph_from_bbox(north, south, east, west, network_type='all', truncate_by_edge=True, retain_all=True)
        for origin in origins:
            x_utm, y_utm = tuple(origin['geometry']['coordinates'])
            x_wgs, y_wgs = transform(projUTM, projWGS84, x_utm, y_utm)
            snapped_x_wgs, snapped_y_wgs = snap_point_to_graph(x_wgs, y_wgs, G)
            snapped_coords = transform(projWGS84, projUTM, snapped_x_wgs, snapped_y_wgs)
            new_asset_locations.append({
                'type': "Feature",
                'geometry': {
                    "type": "Point",
                    "coordinates": snapped_coords
                },
                'properties': {
                    "id": origin['properties']['id']
                }
            })
    except (nx.exception.NetworkXPointlessConcept, ValueError):
github nismod / digital_comms / scripts / network_preprocess_input_files.py View on Github external
def generate_link_shortest_path(origin_points, dest_points, area):
    ox.config(log_file=False, log_console=False, use_cache=True)

    projUTM = Proj(init='epsg:27700')
    projWGS84 = Proj(init='epsg:4326')

    east, north = transform(projUTM, projWGS84, shape(area['geometry']).bounds[2], shape(area['geometry']).bounds[3])
    west, south = transform(projUTM, projWGS84, shape(area['geometry']).bounds[0], shape(area['geometry']).bounds[1])
    G = ox.graph_from_bbox(north, south, east, west, network_type='all', truncate_by_edge=True)

    links = []

    for destination in dest_points:

        origins = [
            point
            for point in origin_points
            if point['properties']['connection'] == destination['properties']['id']
        ]

        for origin in origins:

            dest_x, dest_y = return_object_coordinates(destination)
            origin_x, origin_y = return_object_coordinates(origin)
github ppintosilva / anprx / anprx / core.py View on Github external
Returns
    -------
    nx.MultiDiGraph
        a graph representing the street network
    """

    bbox = bbox_from_points(
        points = points,
        rel_margins = rel_margins,
        min_area = min_area,
        max_area = max_area,
        unit = unit)


    street_network = \
        ox.graph_from_bbox(
            north = bbox.north,
            south = bbox.south,
            east = bbox.east,
            west = bbox.west,
            network_type = "drive_service",
            simplify = True,
            retain_all = False,
            truncate_by_edge = False,
            name = graph_name,
            timeout = 180,
            memory = None,
            clean_periphery = True,
            infrastructure = 'way["highway"]',
            custom_filter = None)

    return street_network
github nismod / digital_comms / scripts / network_preprocess_input_files.py View on Github external
def estimate_asset_locations_on_road_network(origins, area):
    '''
    Put a cabinet in the representative center of the set of premises served by it
    '''
    ox.config(log_file=False, log_console=False, use_cache=True)

    projUTM = Proj(init='epsg:27700')
    projWGS84 = Proj(init='epsg:4326')

    new_asset_locations = []

    try:
        east, north = transform(projUTM, projWGS84, shape(area['geometry']).bounds[2], shape(area['geometry']).bounds[3])
        west, south = transform(projUTM, projWGS84, shape(area['geometry']).bounds[0], shape(area['geometry']).bounds[1])
        G = ox.graph_from_bbox(north, south, east, west, network_type='all', truncate_by_edge=True, retain_all=True)
        for origin in origins:
            x_utm, y_utm = tuple(origin['geometry']['coordinates'])
            x_wgs, y_wgs = transform(projUTM, projWGS84, x_utm, y_utm)
            snapped_x_wgs, snapped_y_wgs = snap_point_to_graph(x_wgs, y_wgs, G)
            snapped_coords = transform(projWGS84, projUTM, snapped_x_wgs, snapped_y_wgs)
            new_asset_locations.append({
                'type': "Feature",
                'geometry': {
                    "type": "Point",
                    "coordinates": snapped_coords
                },
                'properties': {
                    "id": origin['properties']['id']
                }
            })
    except (nx.exception.NetworkXPointlessConcept, ValueError):