Exemple #1
0
def get_osm_network(geodataframe, maxdist=5000, quiet=True, **kwargs):
    """Download a street network from OSM.

    Parameters
    ----------
    geodataframe : geopandas.GeoDataFrame
        geopandas.GeoDataFrame of the study area.
        Coordinate system should be in WGS84
    maxdist : int
        Total distance (in meters) of the network queries you may need.
        This is used to buffer the network to ensure theres enough to satisfy
        your largest query, otherwise there may be edge effects.
    quiet: bool
        If True, diagnostic messages from urbanaccess will be suppressed
    **kwargs : dict
        additional kwargs passed through to
        urbanaccess.ua_network_from_bbox

    Returns
    -------
    pandana.Network
        A pandana Network instance for use in accessibility calculations or
        spatial segregation measures that include a distance decay

    """
    try:
        import pandana as pdna
        from urbanaccess.osm.load import ua_network_from_bbox
    except ImportError:
        raise ImportError(
            "You need pandana and urbanaccess to work with segregation's network module\n"
            "You can install them with  `pip install urbanaccess pandana` "
            "or `conda install -c udst pandana urbanaccess`")

    gdf = geodataframe.copy()
    gdf = gdf.to_crs(gdf.estimate_utm_crs())
    gdf = gdf.buffer(maxdist)
    bounds = gdf.to_crs(epsg=4326).total_bounds

    if quiet:
        print('Downloading data from OSM. This may take awhile.')
        with _HiddenPrints():
            net = ua_network_from_bbox(bounds[1], bounds[0], bounds[3],
                                       bounds[2], **kwargs)
    else:
        net = ua_network_from_bbox(bounds[1], bounds[0], bounds[3], bounds[2],
                                   **kwargs)
    print("Building network")
    network = pdna.Network(net[0]["x"], net[0]["y"], net[1]["from"],
                           net[1]["to"], net[1][["distance"]])

    return network
Exemple #2
0
def get_network(geodataframe, maxdist=5000, quiet=True, **kwargs):
    """Download a street network from OSM.

    Parameters
    ----------
    geodataframe : geopandas.GeoDataFrame
        geopandas.GeoDataFrame of the study area.
    maxdist : int
        Total distance (in meters) of the network queries you may need.
        This is used to buffer the network to ensure theres enough to satisfy
        your largest query, otherwise there may be edge effects.
    **kwargs : dict
        additional kwargs passed through to
        urbanaccess.ua_network_from_bbox

    Returns
    -------
    pandana.Network
        A pandana Network instance for use in accessibility calculations or
        spatial segregation measures that include a distance decay

    Examples
    -------
    Examples should be written in doctest format, and
    should illustrate how to use the function/class.
    >>>

    """
    gdf = geodataframe.copy()

    assert gdf.crs == {
        'init': 'epsg:4326'
    }, "geodataframe must be in epsg 4326"

    gdf = project_gdf(gdf)
    gdf = gdf.buffer(maxdist)
    bounds = gdf.to_crs(epsg=4326).total_bounds

    if quiet:
        print('Downloading data from OSM. This may take awhile.')
        with _HiddenPrints():
            net = ua_network_from_bbox(bounds[1], bounds[0], bounds[3],
                                       bounds[2], **kwargs)
    else:
        net = ua_network_from_bbox(bounds[1], bounds[0], bounds[3], bounds[2],
                                   **kwargs)
    print("Building network")
    network = pdna.Network(net[0]["x"], net[0]["y"], net[1]["from"],
                           net[1]["to"], net[1][["distance"]])

    return network
def test_column_names(bbox1):
    nodes, edges = ua_network_from_bbox(bbox=bbox1,
                                        network_type='walk',
                                        timeout=180,
                                        memory=None,
                                        max_query_area_size=50 * 1000 * 50 *
                                        1000,
                                        remove_lcn=False)
    col_list = ['x', 'y', 'id']
    for col in col_list:
        assert col in nodes.columns

    col_list = ['distance', 'from', 'to']
    for col in col_list:
        assert col in edges.columns
Exemple #4
0
def get_osm_network(geodataframe, maxdist=5000, quiet=True, output_crs=None, **kwargs):
    """Download a street network from OSM.

    Parameters
    ----------
    geodataframe : geopandas.GeoDataFrame
        geopandas.GeoDataFrame of the study area.
        Coordinate system should be in WGS84
    maxdist : int
        Maximum distance of the network queries you may need (this is used to buffer the
        network to ensure there's enough to satisfy your largest query, otherwise there
        may be edge effects. Distance is measured in the units of the geodataframe CRS. If
        the CRS is geographic, a UTM approximation is used, so the units are meters.
    quiet: bool
        If True, diagnostic messages from urbanaccess will be suppressed
    **kwargs : dict
        additional kwargs passed through to
        urbanaccess.ua_network_from_bbox

    Returns
    -------
    pandana.Network
        A pandana Network instance for use in accessibility calculations or
        spatial segregation measures that include a distance decay

    """
    assert geodataframe.crs, "The input geodataframe must have a valid CRS set"
    if not output_crs:
        output_crs = geodataframe.crs
    try:
        import pandana as pdna
        from urbanaccess.osm.load import ua_network_from_bbox
    except ImportError:
        raise ImportError(
            "You need pandana and urbanaccess to work with segregation's network module\n"
            "You can install them with  `pip install urbanaccess pandana` "
            "or `conda install -c udst pandana urbanaccess`"
        )

    gdf = geodataframe.copy()

    #  Need coordinates in 4326 to request from OSM, but need projected for measuring distance
    if geodataframe.crs.is_geographic:
        # this is lazy because UTM can be inaccurate in some places on the earth, but generally works fine
        warn(
            "The geodataframe passed into the function is stored in a geographic CRS."
            "Estimating maximum distance threshold using a UTM transformation"
        )
        gdf = gdf.to_crs(gdf.estimate_utm_crs())
        gdf = gdf.buffer(maxdist)
        bounds = gdf.to_crs(epsg=4326).total_bounds
    else:
        bounds = gdf.total_bounds

    nodes, edges = ua_network_from_bbox(
        bounds[1], bounds[0], bounds[3], bounds[2], **kwargs
    )
    nodes = _reproject_osm_nodes(nodes, 4326, output_crs)

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

    return network