def places_from_point(point, distance, place_type='city_block'): """ Download and create GeoDataFrame of 'place' polygons of the type 'place_type'. use osmnx to download "place" polygons from a center point and distance to edge of bounding box. Filter to retain minimal columns. Create new columns recording perimeter in metres, area in hectares, and the perimeter per unit area. Parameters ---------- point : tuple the (lat, lon) point to create the bounding box around distance : int how many meters the north, south, east, and west sides of the box should each be from the point Returns ------- GeoDataFrame """ # use osmnx to download 'place' polygons places = ox.footprints_from_point(point, distance, footprint_type="place") # filter place polygons to retain only those of 'place_type' places = places.loc[places['place'] == place_type] # write the index into a column places[place_type + '_id'] = places.index # reindex the columns places = places.reindex(columns=[place_type + '_id', 'place', 'geometry']) # name the dataframe places.gdf_name = place_type return places
def 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) 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 _fetch_from_remote(self, type_, cache_path): if type_ == 'graph': graph = ox.graph_from_point(self._center, self._distance, network_type=self._type) self._store_graph_cache(graph, cache_path) return graph elif type_ == 'footprint': gdf = ox.footprints_from_point(self._center, self._distance) self._store_footprint_cache(gdf, cache_path) return 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) # 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"
# -*- 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.footprints_from_point(point=point, dist=dist) # preview image gdf_proj = osmnx.projection.project_gdf(gdf, to_crs={'init': 'epsg:3857'}) gdf_proj = gdf_proj[gdf_proj.geometry.apply( lambda g: g.geom_type != 'MultiPolygon')] fig, ax = osmnx.plot_footprints(gdf_proj, bgcolor='#333333', color='w', figsize=(4, 4), save=True, show=False, close=True, filename='test_buildings_preview', dpi=600)