Skip to content

Commit 2db87ed

Browse files
convert crs84 to epsg4326 in DriverVectorCube from_geojson
1 parent 18b4022 commit 2db87ed

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

openeo_driver/datacube.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import shapely.geometry.base
1818
import shapely.ops
1919
import xarray
20+
from geopandas import GeoDataFrame
2021
from openeo.metadata import CollectionMetadata
2122
from openeo.util import ensure_dir, str_truncate
2223
from pyproj import CRS
@@ -413,11 +414,15 @@ def from_parquet(
413414
location = io.BytesIO(resp.raw.read())
414415
df = gpd.read_parquet(location)
415416
log.info(f"Read geoparquet from {location} crs {df.crs} length {len(df)}")
417+
df = DriverVectorCube._convert_crs84(df)
418+
return cls.from_geodataframe(df, columns_for_cube=columns_for_cube)
416419

420+
@staticmethod
421+
def _convert_crs84(df: GeoDataFrame):
417422
if "OGC:CRS84" in str(df.crs) or "WGS 84 (CRS84)" in str(df.crs):
418423
# workaround for not being able to decode ogc:crs84
419424
df.crs = CRS.from_epsg(4326)
420-
return cls.from_geodataframe(df, columns_for_cube=columns_for_cube)
425+
return df
421426

422427
def write_to_parquet(
423428
self, path: str, flatten_prefix: Optional[str] = None, include_properties=True, only_numeric=True
@@ -461,6 +466,7 @@ def from_geojson(
461466
f"Can not construct DriverVectorCube from {geojson.get('type', type(geojson))!r}"
462467
)
463468
gdf = gpd.GeoDataFrame.from_features(features, crs=crs)
469+
gdf = DriverVectorCube._convert_crs84(gdf)
464470
return cls.from_geodataframe(gdf, columns_for_cube=columns_for_cube)
465471

466472
@classmethod

0 commit comments

Comments
 (0)