eolearn.geometry.transformations

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)[source]

Bases: EOTask

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.

Parameters:
  • vector_input (GeoDataFrame | Feature) – Vector data to be used for rasterization. It can be given as a feature in EOPatch or as a geopandas GeoDataFrame.

  • raster_feature (Feature) – New or existing raster feature into which data will be written. If existing raster feature is given it will by default take existing values and write over them.

  • values (None | float | list[float]) – 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 | 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 (None | tuple[int, int] | Feature) – 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 (None | float | tuple[float, float]) – 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 (np.dtype | type) – Data type of the obtained raster array, default is numpy.uint8.

  • no_data_value (float) – Default value of all other raster pixels into which no value will be rasterized.

  • 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 (float | None) – 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 (Any) –

Param:

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)[source]

Rasterize overlapped classes.

Parameters:
  • shapes (Iterator[Tuple[BaseGeometry, float]]) – Shapes to be rasterized.

  • out (ndarray) – A numpy array to which to rasterize polygon classes.

  • rasterize_args (Any) – Keyword arguments to be passed to rasterio.features.rasterize.

Return type:

None

execute(eopatch)[source]

Execute method

Parameters:

eopatch (EOPatch) – input EOPatch

Returns:

New EOPatch with vector data transformed into a raster feature

Return type:

EOPatch

class eolearn.geometry.transformations.RasterToVectorTask(features, *, values=None, values_column='VALUE', raster_dtype=None, **rasterio_params)[source]

Bases: EOTask

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.GeoDataFrame structure 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

Parameters:
  • features (FeaturesSpecification) –

    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.

    Examples:

    • features=(FeatureType.MASK, ‘CLOUD_MASK’, ‘VECTOR_CLOUD_MASK’)

    • features=[(FeatureType.MASK_TIMELESS, ‘CLASSIFICATION’), (FeatureType.MASK, ‘TEMPORAL_CLASSIFICATION’)]

  • values (list[int] | None) – List of values which will be vectorized. By default, is set to None and all values will be vectorized

  • values_column (str) – Name of the column in vector feature where raster values will be written

  • raster_dtype (None | np.dtype | type) – If raster feature mask is of type which is not supported by rasterio.features.shapes (e.g. numpy.int64) this parameter is used to cast the mask into a different type (numpy.int16, numpy.int32, numpy.uint8, numpy.uint16 or numpy.float32). By default, value of the parameter is None and no casting is done.

  • rasterio_params (Any) –

Param:

rasterio_params: Additional parameters to be passed to rasterio.features.shapes. Currently, available is parameter connectivity.

execute(eopatch)[source]

Execute function which adds new vector layer to the EOPatch

Parameters:

eopatch (EOPatch) – input EOPatch

Returns:

New EOPatch with added vector layer

Return type:

EOPatch