How to use the osmnx.config 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
# Searching on public nominatim should work even if a key was provided
    ox.config(
        nominatim_key="NOT_A_KEY"
    )
    response_json = ox.nominatim_request(params=params,
                                         type="search")

    # Test changing the endpoint. It should fail because we didn't provide a valid key
    ox.config(
        nominatim_endpoint="http://open.mapquestapi.com/nominatim/v1/"
    )
    with pytest.raises(Exception):
        response_json = ox.nominatim_request(params=params,
                                             type="search")

    ox.config(log_console=True, log_file=True, use_cache=True,
              data_folder='.temp/data', logs_folder='.temp/logs',
              imgs_folder='.temp/imgs', cache_folder='.temp/cache')
github gboeing / osmnx / tests / test_osmnx.py View on Github external
params = OrderedDict()
    params['format'] = "json"
    params['address_details'] = 0
    params['osm_ids'] = "W68876073"

    response_json = ox.nominatim_request(params=params,
                                         type="lookup")

    # Invalid nominatim query type
    with pytest.raises(ValueError):
        response_json = ox.nominatim_request(
            params=params,
            type="transfer")

    # Searching on public nominatim should work even if a key was provided
    ox.config(
        nominatim_key="NOT_A_KEY"
    )
    response_json = ox.nominatim_request(params=params,
                                         type="search")

    # Test changing the endpoint. It should fail because we didn't provide a valid key
    ox.config(
        nominatim_endpoint="http://open.mapquestapi.com/nominatim/v1/"
    )
    with pytest.raises(Exception):
        response_json = ox.nominatim_request(params=params,
                                             type="search")

    ox.config(log_console=True, log_file=True, use_cache=True,
              data_folder='.temp/data', logs_folder='.temp/logs',
              imgs_folder='.temp/imgs', cache_folder='.temp/cache')
github gboeing / osmnx / tests / test_osmnx.py View on Github external
import matplotlib as mpl
import warnings

mpl.use('Agg')  # use agg backend so you don't need a display on travis-ci

# remove the .temp folder if it already exists so we start fresh with tests
import os, shutil

if os.path.exists('.temp'):
    shutil.rmtree('.temp')

import osmnx as ox
from networkx.exception import NetworkXNotImplemented

# configure OSMnx
ox.config(log_console=True, log_file=True, use_cache=True,
          data_folder='.temp/data', logs_folder='.temp/logs',
          imgs_folder='.temp/imgs', cache_folder='.temp/cache')


def test_imports():
    # test all of OSMnx's module imports
    import ast
    import datetime
    import geopandas
    import hashlib
    import io
    import json
    import logging
    import math
    import matplotlib.cm
    import matplotlib.pyplot
github tomalrussell / colouring-london / etl / get_test_polygons.py View on Github external
"""Download and load a small open dataset for testing

Run this to create a CSV of buildings geometries.

Then run:
- load_geometries.sh (loading geometries to the database)
- create_buildings.sh (creating empty building records for each geometry)
"""
# -*- coding: utf-8 -*-
import os
import subprocess

import osmnx

# configure logging/caching
osmnx.config(log_console=True, use_cache=True)

# configure the image display
size = 256

# load buildings from about 1.5km² around UCL
point = (51.524498, -0.133874)
dist = 612
gdf = osmnx.buildings_from_point(point=point, distance=dist)

# preview image
gdf_proj = osmnx.project_gdf(gdf, to_crs={'init': 'epsg:3857'})
fig, ax = osmnx.plot_buildings(gdf_proj, bgcolor='#333333', color='w', figsize=(4,4),
                               save=True, show=False, close=True,
                               filename='test_buildings_preview', dpi=600)

# save
github gboeing / osmnx / tests / test_osmnx.py View on Github external
def test_overpass():
    import pytest

    # Test changing the endpoint. This should fail because we didn't provide a valid endpoint
    ox.config(
        overpass_endpoint="http://NOT_A_VALID_ENDPOINT/api/"
    )
    with pytest.raises(Exception):
        G = ox.graph_from_place('Piedmont, California, USA')

    ox.config(overpass_endpoint="http://overpass-api.de/api")
github ppintosilva / anprx / anprx / utils.py View on Github external
def init_osmnx():
    """
    Configure osmnx's settings to match anprx's settings.
    """

    osmnx_folder = os.path.join(settings["app_folder"], "osmnx")
    if not os.path.exists(osmnx_folder):
        os.makedirs(osmnx_folder)

    ox.config(
        data_folder = os.path.join(osmnx_folder, "data"),
        logs_folder = os.path.join(osmnx_folder, "logs"),
        imgs_folder = os.path.join(osmnx_folder, "images"),
        cache_folder = os.path.join(osmnx_folder, "cache"),
        use_cache = True,
        log_file = True,
        log_console = False)
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({
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({
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']