Python geopandas.overlay() Examples
The following are 3
code examples of geopandas.overlay().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
geopandas
, or try the search function
.
Example #1
Source File: surroundings_helper.py From CityEnergyAnalyst with MIT License | 5 votes |
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
Example #2
Source File: vector.py From OpenSarToolkit with MIT License | 5 votes |
def difference(infile1, infile2, outfile): gdf1 = gpd.read_file(infile1) gdf2 = gpd.read_file(infile2) gdf3 = gpd.overlay(gdf1, gdf2, how='symmetric_difference') gdf3.to_file(outfile)
Example #3
Source File: geometries.py From deeposlandia with MIT License | 4 votes |
def extract_tile_items( raster_features, labels, min_x, min_y, tile_width, tile_height ): """Extract label items that belong to the tile defined by the minimum horizontal pixel `min_x` (left tile limit), the minimum vertical pixel `min_y` (upper tile limit) and the sizes ̀€tile_width` and `tile_height` measured as a pixel amount. The tile is cropped from the original image raster as follows: - horizontally, between `min_x` and `min_x+tile_width` - vertically, between `min_y` and `min_y+tile_height` This method takes care of original data projection (UTM 37S, Tanzania area), however this parameter may be changed if similar data on another projection is used. Parameters ---------- raster_features : dict Raw image raster geographical features (`north`, `south`, `east` and `west` coordinates, `weight` and `height` measured in pixels) labels : geopandas.GeoDataFrame Raw image labels, as a set of geometries min_x : int Left tile limit, as a horizontal pixel index min_y : int Upper tile limit, as a vertical pixel index tile_width : int Tile width, measured in pixel tile_height : int Tile height, measured in pixel Returns ------- geopandas.GeoDataFrame Set of ground-truth labels contained into the tile, characterized by their type (complete, unfinished or foundation) and their geometry """ area = get_tile_footprint( raster_features, min_x, min_y, tile_width, tile_height ) bdf = gpd.GeoDataFrame( crs=from_epsg(raster_features["srid"]), geometry=[area] ) reproj_labels = labels.to_crs(epsg=raster_features["srid"]) tile_items = gpd.sjoin(reproj_labels, bdf) if tile_items.shape[0] == 0: return tile_items[["condition", "geometry"]] tile_items = gpd.overlay(tile_items, bdf) tile_items = tile_items.explode() # Manage MultiPolygons return tile_items[["condition", "geometry"]]