eolearn.geometry.transformations

Transformations between vector and raster formats of data

class eolearn.geometry.transformations.VectorToRasterTask(*args, **kwargs)[source]

Bases: eolearn.core.eotask.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 ((FeatureType, str) or GeoDataFrame) – Vector data to be used for rasterization. It can be given as a feature in EOPatch or as a geopandas GeoDataFrame.

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

  • 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 gived 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.

  • no_data_value (int or 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 (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.

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 (an iterable of pairs (rasterio.polygon, int)) – Shapes to be rasterized.

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

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

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(*args, **kwargs)[source]

Bases: eolearn.core.eotask.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 (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.

    Examples:

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

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

  • values (list(int) or 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 (numpy.dtype or None) – 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.

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

class eolearn.geometry.transformations.VectorToRaster(*args, **kwargs)[source]

Bases: eolearn.geometry.transformations.VectorToRasterTask

A deprecated version of VectorToRasterTask

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

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

  • 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 gived 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.

  • no_data_value (int or 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 (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.

Param

rasterio_params: Additional parameters to be passed to rasterio.features.rasterize. Currently available parameters are all_touched and merge_alg

class eolearn.geometry.transformations.RasterToVector(*args, **kwargs)[source]

Bases: eolearn.geometry.transformations.RasterToVectorTask

A deprecated version of RasterToVectorTask

Parameters
  • 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.

    Examples:

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

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

  • values (list(int) or 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 (numpy.dtype or None) – 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.

Param

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