vectorization
darts_export.vectorization
¶
Module for various tasks during export.
gdal_polygonization
¶
gdal_polygonization(
labels: numpy.ndarray,
rio_georef: xarray.Dataset,
as_gdf=True,
gpkg_path: pathlib.Path | None = None,
) -> typing.Union[gdal.ogr.Layer, geopandas.GeoDataFrame]
Polygonize a numpy array using GDAL.
Detects regions with the same value in the numpy array and converts those
into polygons. Can return the initial gdal result as ogr.Dataset or converts into a geopandas dataframe if
as_gdf is enabled. If gpkg_path
is set, the polsgonization result will be written one go
into a GeoPackage file, otherwise the OGR dataset will reside purely in memory.
Parameters:
-
labels
(numpy.ndarray
) –The input dataset as a ndarray with values designating labels
-
rio_georef
(xarray.Dataset
) –an xarray with the rioxarray accessor to determine the CRS of the dataset
-
as_gdf
(bool
, default:True
) –returns result as geopandas.GeoDataFrame. Defaults to True.
-
gpkg_path
(pathlib.Path | None
, default:None
) –Path where a GPKG file is written backing the OGR dataset. Defaults to None.
Returns:
-
typing.Union[gdal.ogr.Layer, geopandas.GeoDataFrame]
–ogr.Layer | gpd.GeoDataFrame: the polyginization result
Source code in darts-export/src/darts_export/vectorization.py
rasterio_polygonization
¶
rasterio_polygonization(
labels: numpy.ndarray, rio_georef: xarray.Dataset
) -> geopandas.GeoDataFrame
Polygonize a numpy array with rasterio.
Detects regions with the same value in the numpy array and converts those
into polygons. The rio_georef
agrument determines the final CRS of
the returned geopandas GeoDataFrame.
Parameters:
-
labels
(numpy.ndarray
) –the array of regionalizable labels
-
rio_georef
(xarray.Dataset
) –the CRS as an xarray/rioxarray Dataset with rio accessor
Returns:
-
geopandas.GeoDataFrame
–geopandas.GeoDataFrame: the resolut of the polygonization
Source code in darts-export/src/darts_export/vectorization.py
vectorize
¶
vectorize(
xdat: xarray.Dataset,
layername: str = "binarized_segmentation",
polygonization_func: str = "rasterio",
) -> geopandas.GeoDataFrame
Vectorize an inference result dataset.
Detects connected regions in the with the same value binarized_segmentation
layer, polygonizes
this into a vector dataset.
Additionally this function writes zonal statistics of the probabilities
layer to the polygon attributes.
Parameters:
-
xdat
(xarray.Dataset
) –the input dataset augmented with the rioxarray
rio
accessor -
layername
(str
, default:'binarized_segmentation'
) –the name of the layer in
xdat
to polygonize -
polygonization_func
(str
, default:'rasterio'
) –the method to utilize for polygonization, either 'gdal' or 'rasterio', the default.
Returns:
-
_type_
(geopandas.GeoDataFrame
) –description