1010import pandas as pd
1111from geopandas import GeoDataFrame as gdf
1212from geopandas .tools import sjoin as spatial_join
13+ from shapely import MultiPolygon
1314
1415import cea .config
1516import cea .inputlocator
@@ -35,7 +36,11 @@ def calc_surrounding_area(zone_gdf, buffer_m):
3536 :param float buffer_m: Buffer to add to zone building geometries
3637 :return: Surrounding area GeoDataFrame
3738 """
38- surrounding_area = gdf (geometry = [zone_gdf .geometry .buffer (buffer_m ).unary_union ], crs = zone_gdf .crs )
39+ merged_zone = zone_gdf .geometry .unary_union
40+ if isinstance (merged_zone , MultiPolygon ):
41+ merged_zone = merged_zone .convex_hull
42+
43+ surrounding_area = gdf (geometry = [merged_zone .buffer (buffer_m )], crs = zone_gdf .crs )
3944 return surrounding_area
4045
4146
@@ -135,7 +140,6 @@ def erase_no_surrounding_areas(all_surroundings, zone, area_with_buffer):
135140 :return: GeoDataFrame with surrounding buildings
136141 """
137142 buffer_polygon = area_with_buffer .to_crs (zone .crs ).geometry .values [0 ]
138- zone_area = gdf (geometry = [zone .geometry .unary_union ], crs = zone .crs )
139143
140144 within_buffer = all_surroundings .geometry .intersects (buffer_polygon )
141145 surroundings = all_surroundings [within_buffer ]
@@ -144,7 +148,7 @@ def erase_no_surrounding_areas(all_surroundings, zone, area_with_buffer):
144148 if not any ([s_building_footprint .intersects (z_building_footprint )
145149 for z_building_footprint in zone .geometry ])]
146150 footprints_gdf = gdf (geometry = footprints_without_overlaps , crs = surroundings .crs )
147- relevant_surroundings = spatial_join (surroundings , footprints_gdf , op = 'within' )
151+ relevant_surroundings = spatial_join (surroundings , footprints_gdf , predicate = 'within' )
148152
149153 return relevant_surroundings .copy ()
150154
@@ -175,8 +179,7 @@ def geometry_extractor_osm(locator, config):
175179 # get footprints of all the surroundings
176180 print ("Getting building footprints" )
177181 area_with_buffer_polygon = area_with_buffer .to_crs (get_geographic_coordinate_system ()).geometry .values [0 ]
178- all_surroundings = osmnx .geometries .geometries_from_polygon (polygon = area_with_buffer_polygon ,
179- tags = {"building" : True })
182+ all_surroundings = osmnx .features_from_polygon (polygon = area_with_buffer_polygon , tags = {"building" : True })
180183 all_surroundings = all_surroundings .to_crs (get_projected_coordinate_system (float (lat ), float (lon )))
181184
182185 # erase overlapping area
0 commit comments