diff --git a/docs/installation.rst b/docs/installation.rst index 4a79144f3..58ffd3ced 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -91,6 +91,8 @@ For example: - ``pyarrow`` for (read/write) support of Parquet files (e.g. with :py:class:`~openeo.extra.job_management.MultiBackendJobManager`) - ``rioxarray`` for GeoTIFF support in the assert helpers from ``openeo.testing.results`` +- ``geopandas`` for working with dataframes with geospatial support, + (e.g. with :py:class:`~openeo.extra.job_management.MultiBackendJobManager`) Enabling additional features diff --git a/openeo/extra/job_management.py b/openeo/extra/job_management.py index daa15e3e9..2820a1a12 100644 --- a/openeo/extra/job_management.py +++ b/openeo/extra/job_management.py @@ -8,7 +8,6 @@ from pathlib import Path from typing import Callable, Dict, NamedTuple, Optional, Union -import geopandas import pandas as pd import requests import shapely.errors @@ -540,6 +539,10 @@ class CsvJobDatabase(JobDatabaseInterface): :implements: :py:class:`JobDatabaseInterface` :param path: Path to local CSV file. + .. note:: + Support for GeoPandas dataframes depends on the ``geopandas`` package + as :ref:`optional dependency `. + .. versionadded:: 0.31.0 """ def __init__(self, path: Union[str, Path]): @@ -562,6 +565,8 @@ def read(self) -> pd.DataFrame: and df["geometry"].dtype.name != "geometry" and self._is_valid_wkt(df["geometry"].iloc[0]) ): + import geopandas + # `df.to_csv()` in `persist()` has encoded geometries as WKT, so we decode that here. df = geopandas.GeoDataFrame(df, geometry=geopandas.GeoSeries.from_wkt(df["geometry"])) return df @@ -578,11 +583,14 @@ class ParquetJobDatabase(JobDatabaseInterface): :implements: :py:class:`JobDatabaseInterface` :param path: Path to the Parquet file. - .. versionadded:: 0.31.0 - .. note:: Support for Parquet files depends on the ``pyarrow`` package as :ref:`optional dependency `. + + Support for GeoPandas dataframes depends on the ``geopandas`` package + as :ref:`optional dependency `. + + .. versionadded:: 0.31.0 """ def __init__(self, path: Union[str, Path]): self.path = Path(path) @@ -601,6 +609,7 @@ def read(self) -> pd.DataFrame: metadata = pyarrow.parquet.read_metadata(self.path) if b"geo" in metadata.metadata: + import geopandas return geopandas.read_parquet(self.path) else: return pd.read_parquet(self.path)