Transformations between vector and raster formats of data
- class eolearn.geometry.transformations.VectorToRasterTask(vector_input, raster_feature, *, values=None, values_column=None, raster_shape=None, raster_resolution=None, raster_dtype=<class 'numpy.uint8'>, no_data_value=0, write_to_existing=False, overlap_value=None, buffer=0, **rasterio_params)
A task for transforming a vector feature into a raster feature
Vector data can be given as an EOPatch feature or as an independent geopandas GeoDataFrame.
In the background it uses rasterio.features.rasterize, documented in rasterio documentation.
values (list(int or float) or int or float or None) – If values_column parameter is specified then only polygons which have one of these specified values in values_column will be rasterized. It can be also left to None. If values_column parameter is not specified values parameter has to be a single number into which everything will be rasterized.
values_column (str or None) – A column in given dataframe where values, into which polygons will be rasterized, are stored. If it is left to None then values parameter should be a single number into which everything will be rasterized.
raster_shape ((int, int) or (FeatureType, str) or None) – Can be a tuple in form of (height, width) or an existing feature from which the spatial dimensions will be taken. Parameter raster_resolution can be specified instead of raster_shape.
raster_resolution (float or (float, float) or None) – Resolution of raster into which data will be rasterized. Has to be given as a number or a tuple of numbers in meters. Parameter raster_shape can be specified instead or raster_resolution.
raster_dtype (numpy.dtype) – Data type of the obtained raster array, default is numpy.uint8.
write_to_existing (bool) – If True it will write to existing raster array and overwrite parts of its values. If False it will create a new raster array and remove the old one. Default is False.
overlap_value (raster's dtype) – A value to override parts of raster where polygons of different classes overlap. If None, rasterization overlays polygon as it is the default behavior of rasterio.features.rasterize.
buffer (float) – Buffer value passed to vector_data.buffer() before rasterization. If 0, no buffering is done.
rasterio_params: Additional parameters to be passed to rasterio.features.rasterize. Currently, available parameters are all_touched and merge_alg
- rasterize_overlapped(shapes, out, **rasterize_args)
Rasterize overlapped classes.
- class eolearn.geometry.transformations.RasterToVectorTask(features, *, values=None, values_column='VALUE', raster_dtype=None, **rasterio_params)
Task for transforming raster mask feature into vector feature.
Each connected component with the same value on the raster mask is turned into a shapely polygon. Polygon are returned as a geometry column in a
geopandas.GeoDataFramestructure together with a column VALUE with values of each polygon.
If raster mask feature has time component, vector feature will also have a column TIMESTAMP with timestamps to which raster image each polygon belongs to. If raster mask has multiple channels each of them will be vectorized separately but polygons will be in the same vector feature
features (object supported by eolearn.core.utilities.FeatureParser class) –
One or more raster mask features which will be vectorized together with an optional new name of vector feature. If no new name is given the same name will be used.
features=(FeatureType.MASK, ‘CLOUD_MASK’, ‘VECTOR_CLOUD_MASK’)
features=[(FeatureType.MASK_TIMELESS, ‘CLASSIFICATION’), (FeatureType.MASK, ‘TEMPORAL_CLASSIFICATION’)]
values_column (str) – Name of the column in vector feature where raster values will be written
raster_dtype (numpy.dtype or None) – If raster feature mask is of type which is not supported by
numpy.int64) this parameter is used to cast the mask into a different type (
numpy.float32). By default, value of the parameter is
Noneand no casting is done.
rasterio_params: Additional parameters to be passed to rasterio.features.shapes. Currently, available is parameter connectivity.