EuroCrops#

class torchgeo.datasets.EuroCrops(paths='data', crs=None, res=(1e-05, 1e-05), classes=None, transforms=None, download=False, checksum=False)[source]#

Bases: VectorDataset

EuroCrops Dataset (Version 9).

The EuroCrops dataset combines “all publicly available self-declared crop reporting datasets from countries of the European Union” into a unified format. The dataset is released under CC BY 4.0 Deed.

The dataset consists of shapefiles containing a total of 22M polygons. Each polygon is tagged with a “EC_hcat_n” attribute indicating the harmonized crop name grown within the polygon in the year associated with the shapefile.

If you use this dataset in your research, please follow the citation guidelines at:

Added in version 0.6.

filename_glob = '*_EC*.shp'#

Glob expression used to search for files.

This expression should be specific enough that it will not pick up files from other datasets. It should not include a file extension, as the dataset may be in a different file format than what it was originally downloaded as.

filename_regex = '\n        ^(?P<country>[A-Z]{2})\n        (_(?P<region>[A-Z]+))?\n        _\n        (?P<date>\\d{4})\n        _\n        (?P<suffix>EC(?:21)?)\n        \\.shp$\n    '#

Regular expression used to extract date from filename.

The expression should use named groups. The expression may contain any number of groups. The following groups are specifically searched for by the base class:

  • date: used to calculate mint and maxt for index insertion

date_format = '%Y'#

Date format string used to parse date from filename.

Not used if filename_regex does not contain a date group.

__init__(paths='data', crs=None, res=(1e-05, 1e-05), classes=None, transforms=None, download=False, checksum=False)[source]#

Initialize a new EuroCrops instance.

Parameters:
  • paths (str | PathLike[str] | Iterable[str | PathLike[str]]) – one or more root directories to search for files to load

  • crs (CRS | None) – coordinate reference system (CRS) to warp to (defaults to WGS-84)

  • res (float | tuple[float, float]) – resolution of the dataset in units of CRS in (xres, yres) format. If a single float is provided, it is used for both the x and y resolution.

  • classes (list[str] | None) – list of classes to include (specified by their HCAT code), the rest will be mapped to 0 (defaults to all classes)

  • transforms (Callable[[dict[str, Any]], dict[str, Any]] | None) – a function/transform that takes an input sample and returns a transformed version

  • download (bool) – if True, download dataset and store it in the root directory

  • checksum (bool) – if True, check the MD5 of the downloaded files (may be slow)

Raises:

DatasetNotFoundError – If dataset is not found and download is False.

get_label(feature)[source]#

Get label value to use for rendering a feature.

Parameters:

feature (Series) – the row from the GeoDataFrame from which to extract the label.

Returns:

the integer label, or 0 if the feature should not be rendered.

Return type:

int

plot(sample, show_titles=True, suptitle=None)[source]#

Plot a sample from the dataset.

Parameters:
  • sample (dict[str, Any]) – a sample returned by VectorDataset.__getitem__()

  • show_titles (bool) – flag indicating whether to show titles above each panel

  • suptitle (str | None) – optional string to use as a suptitle

Returns:

a matplotlib Figure with the rendered sample

Return type:

Figure

__annotate_func__()#

The type of the None singleton.