def test_footprints(): import json import pytest from shapely.geometry import Polygon # download footprints and plot them gdf = ox.footprints_from_place(place='Emeryville, California, USA') gdf = ox.footprints_from_polygon( Polygon([(17.574, -4.145), (17.575, -4.144), (17.576, -4.145)])) gdf = ox.footprints_from_address( address='600 Montgomery St, San Francisco, California, USA', distance=300) fig, ax = ox.plot_footprints(gdf) # new_river_head.json contains a relation with 1 outer closed way and 2 inner closed ways # inner way 665593284 is directly tagged as a building and should create its own polygon with open("tests/input_data/new_river_head.json", "r") as read_file: new_river_head_responses = [json.load(read_file)] new_river_head_gdf = ox.create_footprints_gdf( responses=new_river_head_responses) assert 665593284 in new_river_head_gdf.index assert new_river_head_gdf.loc[9246394]['geometry'].type == 'Polygon' assert len(new_river_head_gdf.loc[9246394, 'geometry'].interiors) == 2 # clapham_common.json contains a relation with 5 outer rings and 1 inner ring. One of the outer rings is a chain of open ways with open("tests/input_data/clapham_common.json", "r") as read_file: clapham_common_responses = [json.load(read_file)] clapham_common_gdf = ox.create_footprints_gdf( footprint_type='leisure', responses=clapham_common_responses) assert clapham_common_gdf.loc[1290065]['geometry'].type == 'MultiPolygon' # relation_no_outer.json contains a relation with 0 outer rings and 1 inner ring with open("tests/input_data/relation_no_outer.json", "r") as read_file: relation_no_outer_responses = [json.load(read_file)] ox.create_footprints_gdf(responses=relation_no_outer_responses) # inner_chain.json contains a relation with 1 outer rings and several inner rings one of which is a chain of open ways with open("tests/input_data/inner_chain.json", "r") as read_file: inner_chain_responses = [json.load(read_file)] ox.create_footprints_gdf(responses=inner_chain_responses) # mis_tagged_bus_route.json contains a relation with out 'inner' or 'inner' rings with open("tests/input_data/mis_tagged_bus_route.json", "r") as read_file: mis_tagged_bus_route_responses = [json.load(read_file)] ox.create_footprints_gdf(responses=mis_tagged_bus_route_responses) # test plotting multipolygon fig, ax = ox.plot_footprints(clapham_common_gdf) # should raise an exception # polygon or -north, south, east, west- should be provided with pytest.raises(ValueError): ox.create_footprints_gdf(polygon=None, north=None, south=None, east=None, west=None) gdf = ox.footprints_from_place(place='kusatsu, shiga, japan', which_result=2)
def test_footprints(): # download footprints and plot them gdf = ox.footprints_from_place(place2) gdf = ox.footprints_from_polygon(polygon) gdf = ox.footprints_from_address(address, dist=300) fig, ax = ox.plot_footprints(gdf)
def test_footprints(): # download footprints and plot them gdf = ox.footprints_from_place(place='Emeryville, California, USA') gdf = ox.footprints_from_address( address='600 Montgomery St, San Francisco, California, USA', distance=300) fig, ax = ox.plot_footprints(gdf)
def test_footprints(): # download footprints and plot them cs = '[out:json][timeout:180][date:"2019-10-28T19:20:00Z"]' gdf = ox.footprints_from_place(place2, custom_settings=cs) gdf = ox.footprints_from_polygon(polygon) gdf = ox.footprints_from_address(address, dist=300) fig, ax = ox.plot_footprints(gdf) # new_river_head.json contains a relation with 1 outer closed way and 2 # inner closed ways inner way 665593284 is directly tagged as a building # and should create its own polygon with open("tests/input_data/new_river_head.json", "r") as read_file: new_river_head_responses = [json.load(read_file)] new_river_head_gdf = ox.footprints._create_footprints_gdf( responses=new_river_head_responses) assert 665593284 in new_river_head_gdf.index assert new_river_head_gdf.loc[9246394]["geometry"].type == "Polygon" assert len(new_river_head_gdf.loc[9246394, "geometry"].interiors) == 2 # clapham_common.json contains a relation with 5 outer rings and 1 # inner ring. One of the outer rings is a chain of open ways with open("tests/input_data/clapham_common.json", "r") as read_file: clapham_common_responses = [json.load(read_file)] clapham_common_gdf = ox.footprints._create_footprints_gdf( footprint_type="leisure", responses=clapham_common_responses) assert clapham_common_gdf.loc[1290065]["geometry"].type == "MultiPolygon" # relation_no_outer.json contains a relation with 0 outer rings and 1 # inner ring with open("tests/input_data/relation_no_outer.json", "r") as read_file: relation_no_outer_responses = [json.load(read_file)] ox.footprints._create_footprints_gdf(responses=relation_no_outer_responses) # inner_chain.json contains a relation with 1 outer rings and several # inner rings one of which is a chain of open ways with open("tests/input_data/inner_chain.json", "r") as read_file: inner_chain_responses = [json.load(read_file)] ox.footprints._create_footprints_gdf(responses=inner_chain_responses) # mis_tagged_bus_route.json contains a relation with out 'inner' or # 'inner' rings with open("tests/input_data/mis_tagged_bus_route.json", "r") as read_file: mis_tagged_bus_route_responses = [json.load(read_file)] ox.footprints._create_footprints_gdf( responses=mis_tagged_bus_route_responses) # test plotting multipolygon fig, ax = ox.plot_footprints(clapham_common_gdf) # should raise an exception # polygon or -north, south, east, west- should be provided with pytest.raises(ValueError): ox.footprints._create_footprints_gdf(polygon=None, north=None, south=None, east=None, west=None)
def test_footprints(): # download footprints and plot them gdf = ox.footprints_from_place(place='Emeryville, California, USA') gdf = ox.footprints_from_address(address='600 Montgomery St, San Francisco, California, USA', distance=300) fig, ax = ox.plot_footprints(gdf) # test multipolygon footprint # point is the location of known multipolygon building, relation id 1767022 point = (51.5276, -0.11) gdf = ox.footprints_from_point(point=point, distance=20, footprint_type='building') assert 1767022 in gdf.index, "relation 1767022 was not returned in the geodataframe" assert gdf.loc[1767022]['geometry'].type=='MultiPolygon', "relation 1767022 is not a multipolygon"
def test_footprints(): # download footprints and plot them gdf = ox.footprints_from_place(place='Emeryville, California, USA') gdf = ox.footprints_from_address( address='600 Montgomery St, San Francisco, California, USA', distance=300) fig, ax = ox.plot_footprints(gdf) # test multipolygon footprint # point is the location of known multipolygon building, relation id 1767022 point = (51.5276, -0.11) gdf = ox.footprints_from_point(point=point, distance=20, footprint_type='building') assert 1767022 in gdf.index, "relation 1767022 was not returned in the geodataframe" assert gdf.loc[1767022][ 'geometry'].type == 'MultiPolygon', "relation 1767022 is not a multipolygon"
def park_barriers(place, download_method, distance=None, epsg=None, min_area=100000): """ The function downloads parks areas with a certain extent and converts them to LineString features. Parks may break continuity in the urban structure, besides being attractive areas for pedestrians. Parameters ---------- place: string name of cities or areas in OSM: when using "OSMpolygon" please provide the name of a "relation" in OSM as an argument of "place"; when using "distance_from_address" provide an existing OSM address; when using "OSMplace" provide an OSM place name download_method: string, {"polygon", "distance_from_address", "OSMplace"} it indicates the method that should be used for downloading the data. distance: float it is used only if download_method == "distance from address" epsg: int epsg of the area considered; if None OSMNx is used for the projection min_area: double parks with an extension smaller that this parameter are disregarded Returns ------- LineString GeoDataFrame """ crs = {'init': 'epsg:' + str(epsg)} if download_method == 'distance_from_address': parks_polygon = ox.footprints_from_address(place, distance=distance, footprint_type="leisure", retain_invalid=True) elif download_method == 'OSMplace': parks_polygon = ox.footprints_from_place(place, footprint_type="leisure", retain_invalid=True) else: parks_polygon = ox.footprints_from_polygon(place, footprint_type="leisure", retain_invalid=True) parks_polygon = parks_polygon[parks_polygon.leisure == 'park'] ix_geo = parks_polygon.columns.get_loc("geometry") + 1 to_drop = [] for row in parks_polygon.itertuples(): type_geo = None try: type_geo = row[ix_geo].geom_type except: to_drop.append(row.Index) parks_polygon.drop(to_drop, axis=0, inplace=True) parks_polygon = parks_polygon.to_crs(crs) parks_polygon.area = parks_polygon.geometry.area parks_polygon = parks_polygon[parks_polygon.area >= min_area] pp = parks_polygon['geometry'].unary_union pp = polygonize_full(pp) parks = unary_union(pp).buffer(10).boundary # to simpify a bit parks = linemerge(parks) if parks.type != "LineString": features = [i for i in parks] else: features = [parks] features = [i for i in parks] df = pd.DataFrame({'geometry': features, 'type': ['park'] * len(features)}) park_barriers = gpd.GeoDataFrame(df, geometry=df['geometry'], crs=crs) return park_barriers