From 11367c80341aedb0e42cba877b4c483e29eb641b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20K=C3=BCpper?= Date: Mon, 4 Nov 2024 15:07:43 +0100 Subject: [PATCH] export: layer name to vectorize as parameter --- darts-export/src/darts_export/vectorization.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/darts-export/src/darts_export/vectorization.py b/darts-export/src/darts_export/vectorization.py index 8337274..bc22d17 100644 --- a/darts-export/src/darts_export/vectorization.py +++ b/darts-export/src/darts_export/vectorization.py @@ -109,7 +109,12 @@ def rasterio_polygonization(labels: np.ndarray, rio_georef: xarray.Dataset) -> g return gdf -def vectorize(xdat: xarray.Dataset, polygonization_func: str = "rasterio", minimum_mapping_unit=32) -> gpd.GeoDataFrame: +def vectorize( + xdat: xarray.Dataset, + layername: str = "binarized_segmentation", + polygonization_func: str = "rasterio", + minimum_mapping_unit=32, +) -> gpd.GeoDataFrame: """Vectorize an inference result dataset. Detects connected regions in the with the same value `binarized_segmentation` layer, polygonizes @@ -118,14 +123,16 @@ def vectorize(xdat: xarray.Dataset, polygonization_func: str = "rasterio", minim Args: xdat (xarray.Dataset): the input dataset augmented with the rioxarray `rio` accessor - polygonization_func (str): the method to utilize for polygonization, either 'gdal' or 'rasterio', the default. + layername (str, optional): the name of the layer in `xdat` to polygonize + polygonization_func (str, optional): the method to utilize for polygonization, either 'gdal' or 'rasterio', + the default. minimum_mapping_unit (int, optional): polygons smaller than this number are removed. Defaults to 32. Returns: _type_: _description_ """ - layer = xdat.binarized_segmentation + layer = xdat[layername] # MIN POLYGON for sieving if minimum_mapping_unit > 0: