def calc_surrounding_area(zone_gdf, buffer_m): geometry_without_holes = zone_gdf.convex_hull geometry_without_holes_gdf = Gdf(geometry=geometry_without_holes.values) geometry_without_holes_gdf["one_class"] = "buildings" geometry_merged = geometry_without_holes_gdf.dissolve(by='one_class', aggfunc='sum') geometry_merged_final = Gdf(geometry=geometry_merged.convex_hull) new_buffer = Gdf(geometry=geometry_merged_final.buffer(buffer_m)) area = overlay(geometry_merged_final, new_buffer, how='symmetric_difference') # THIS IS ANOTHER METHOD, NOT FUNCTIONAL THOUGH # from shapely.ops import Point # # new GeoDataFrame with same columns # points = [] # # Extraction of the polygon nodes and attributes values from polys and integration into the new GeoDataFrame # for index, row in zone_gdf.iterrows(): # for j in list(row['geometry'].exterior.coords): # points.append(Point(j)) # # concave_hull, edge_points = alpha_shape(points, alpha=0.1) # simple_polygons = [x for x in concave_hull] # geometry_merged_final = Gdf(geometry=simple_polygons) # geometry_merged_final.plot() # plt.show() # new_buffer = Gdf(geometry=geometry_merged_final.buffer(buffer_m)) # area = overlay(geometry_merged_final, new_buffer, how='symmetric_difference') # area.plot() return area, geometry_merged_final
def calc_raster_terrain_fixed_elevation(crs, elevation, grid_size, raster_path, locator, x_max, x_min, y_max, y_min): # local variables: temp_shapefile = locator.get_temporary_file("terrain.shp") cols = int((x_max - x_min) / grid_size) rows = int((y_max - y_min) / grid_size) shapes = Polygon([[x_min, y_min], [x_max, y_min], [x_max, y_max], [x_min, y_max], [x_min, y_min]]) geodataframe = Gdf(index=[0], crs=crs, geometry=[shapes]) geodataframe.to_file(temp_shapefile) # 1) opening the shapefile source_ds = ogr.Open(temp_shapefile) source_layer = source_ds.GetLayer() target_ds = gdal.GetDriverByName('GTiff').Create( raster_path, cols, rows, 1, gdal.GDT_Float32) ##COMMENT 2 target_ds.SetGeoTransform( (x_min, grid_size, 0, y_max, 0, -grid_size)) ##COMMENT 3 # 5) Adding a spatial reference ##COMMENT 4 target_dsSRS = osr.SpatialReference() target_dsSRS.ImportFromProj4(crs) target_ds.SetProjection(target_dsSRS.ExportToWkt()) band = target_ds.GetRasterBand(1) band.SetNoDataValue(-9999) ##COMMENT 5 gdal.RasterizeLayer(target_ds, [1], source_layer, burn_values=[elevation]) ##COMMENT 6 target_ds = None # closing the file