sertit.rasters.vectorize¶
- vectorize(xds: Union[str, xarray.core.dataarray.DataArray, xarray.core.dataset.Dataset, rasterio.io.DatasetReader], values: Union[None, int, list] = None, keep_values: bool = True, dissolve: bool = False, default_nodata: int = 0) geopandas.geodataframe.GeoDataFrame [source]¶
Vectorize a xarray to get the class vectors.
If dissolved is False, it returns a GeoDataFrame with a GeoSeries per cluster of pixel value, with the value as an attribute. Else it returns a GeoDataFrame with a unique polygon.
Warning
Your data is casted by force into np.uint8, so be sure that your data is classified.
- This could take a while as the computing time directly depends on the number of polygons to vectorize.
Please be careful.
>>> raster_path = "path\to\raster.tif" >>> vec1 = vectorize(raster_path) >>> # or >>> with rasterio.open(raster_path) as dst: >>> vec2 = vectorize(dst) >>> vec1 == vec2 True
- Parameters
xds (PATH_XARR_DS) – Path to the raster or a rasterio dataset or a xarray
values (Union[None, int, list]) – Get only the polygons concerning this/these particular values
keep_values (bool) – Keep the passed values. If False, discard them and keep the others.
dissolve (bool) – Dissolve all the polygons into one unique. Only works if values are given.
default_nodata (int) – Default values for nodata in case of non existing in file
- Returns
Classes Vector
- Return type
gpd.GeoDataFrame