geodata.Mask.extract_shapes

geodata.Mask.extract_shapes#

geodata.Mask.extract_shapes(shapes: dict[str, shapely.Geometry] | geopandas.GeoDataFrame, layer: str | None = None, combine_shape: bool = False, combine_name: str | None = None, show_raster: bool = False, attribute_save: bool = True, src_crs: str = 'EPSG:4326', dst_crs: str = 'EPSG:4326', **kwargs) dict[str, rasterio.DatasetReader]#

Extract the shapes on the (by default) merged_mask layer, and save the result shape rasters as a dictionary in shape_mask attribute.

Parameters:
  • shapes (dict or GeoDataFrame) – A dictionary or GeoPanda’s dataframe of shapes

  • layer (str) – The layer to extract shape from. If unspecified, this method will extract the shapes from the merged_mask layer.

  • combine_shape (bool) – Whether combine the shapes as one shape, and only one layer will be added as a result. This option is set to False by default.

  • combine_name (str) – The name of the combined shape if combine_shape is True.

  • show_raster (bool) – Whether to plot the result shapes. True by default.

  • attribute_save (bool) – if the program will want to save the shapes to the shape_mask attributes. True by default.

  • src_crs (str) – The source tif CRS, by default it is ‘EPSG:4326’ lat lon coordinate system.

  • dst_crs (str) – The destination CRS, by default it is ‘EPSG:4326’ lat lon coordinate system.

  • **kwargs – Additional arguments passed to the rasterio.mask.mask method.

Returns:

A dictionary of extracted shapes with shape names as keys and shape rasters as values.

Return type:

dict

Raises:
  • ValueError – If the shapes input is not a dictionary or GeoDataFrame.

  • ValueError – If the layer is not specified and the merged_mask is not ready.