vectorize
vectorize#
- vectorize(ds: Union[str, tuple, 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 raster 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
Please only use this function on a classified raster.
- 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" # Classified raster, with no data set to 255 >>> vec1 = vectorize(raster_path) >>> # or >>> with rasterio.open(raster_path) as ds: >>> vec2 = vectorize(ds) >>> vec1 == vec2 True
- Parameters
ds (PATH_ARR_DS) – Path to the raster, its dataset, its
xarray
or a tuple containing its array and metadatavalues (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