def h5_from_bbox(lat_min, lng_min, lat_max, lng_max, filename, rm_nodes=None,
                network_type='walk', two_way=True):
    """
    Save an HDF5 file with 'nodes' and 'edges' panels from a bounding lat/lon box.

    Parameters
    ----------
    lat_min, lng_min, lat_max, lng_max : float
    filename : string
    rm_nodes : array_like
        A list, array, Index, or Series of node IDs that should *not*
        be saved as part of the Network.
    network_type : {'walk', 'drive'}, optional
        Specify whether the network will be used for walking or driving.
        A value of 'walk' attempts to exclude things like freeways,
        while a value of 'drive' attempts to exclude things like
        bike and walking paths.
    two_way : bool, optional
        Whether the routes are two-way. If True, node pairs will only
        occur once.

    Returns
    -------
    Nothing. Writes an HDF5 file to the current directory.

    """
    net =  pdosm.network_from_bbox(lat_min, lng_min, lat_max, 
                        lng_max, network_type, two_way)
    pandana.loaders.pandash5.network_to_pandas_hdf5(net, filename, rm_nodes)
示例#2
0
def get_osm_network(zone_data, settings):
    """
    Retrieve Pandana network from Open Street Maps
    """

    logger.info('getting osm network')
    zones_df = zone_data.to_frame()

    miles = settings.get('distance_units') == 'miles'
    # distance to degrees: 111 km = 69 miles = 1 degree of long (y), 3mi = 0.043
    conversion = 69 if miles else 111 * 1000
    buffer = settings.get('max_dist') / conversion
    xmin = min(zones_df[settings['zones_lon']]) - buffer
    xmax = max(zones_df[settings['zones_lon']]) + buffer
    ymin = min(zones_df[settings['zones_lat']]) - buffer
    ymax = max(zones_df[settings['zones_lat']]) + buffer
    logger.debug('bounding box: %s, %s, %s, %s' %
                 (str(ymin), str(xmin), str(ymax), str(xmax)))

    # default type=walk, which excludes freeways
    nodes, edges = osm.network_from_bbox(lat_min=ymin,
                                         lng_min=xmin,
                                         lat_max=ymax,
                                         lng_max=xmax,
                                         two_way=True,
                                         network_type='walk')

    if miles:
        logger.info('converting network distance units to miles...')
        edges[['distance']] = edges[['distance']] / 1609.34

    network = pdna.Network(nodes['x'], nodes['y'], edges['from'], edges['to'],
                           edges[['distance']])

    print(edges.head())
    print(edges[['distance']])
    network.save_hdf5(config.output_file_path('pandana_network.h5'))

    return network
    # using the '"amenity"~"school"' returns preschools etc, so drop any that aren't just 'school' then save to CSV
    pois = pois[pois['amenity'].isin(amenities)]
    pois.to_csv(poi_filename, index=False, encoding='utf-8')
    method = 'downloaded from OSM'

print('{:,} POIs {} in {:,.2f} seconds'.format(len(pois), method, time.time() - start_time))

start_time = time.time()
if os.path.isfile(net_filename):
    # if a street network file already exists, just load the dataset from that
    network = pandana.network.Network.from_hdf5(net_filename)
    method = 'loaded from HDF5'
else:
    # otherwise, query the OSM API for the street network within the specified bounding box
    network = osm.network_from_bbox(bbox[0], bbox[1], bbox[2], bbox[3])
    method = 'downloaded from OSM'

    # identify nodes that are connected to fewer than some threshold of other nodes within a given distance
    lcn = network.low_connectivity_nodes(impedance=1000, count=10, imp_name='distance')
    network.save_hdf5(net_filename, rm_nodes=lcn)  # remove low-connectivity nodes and save to h5

print('Network with {:,} nodes {} in {:,.2f} secs'.format(len(network.node_ids), method, time.time() - start_time))

# precomputes the range queries (the reachable nodes within this maximum distance)
# so, as long as you use a smaller distance, cached results will be used
network.precompute(distance + 1)

# initialize the underlying C++ points-of-interest engine
network.init_pois(num_categories=num_categories, max_dist=distance, max_pois=num_pois)
示例#4
0
def test_network_from_bbox(bbox2):
    net = osm.network_from_bbox(*bbox2)
    assert isinstance(net, pandana.Network)
示例#5
0
def create_osm_base_network(outputfile, bbox, network_type="drive"):
    network = osm.network_from_bbox(*bbox, network_type=network_type)
    network.save_hdf5(outputfile)
    return network