From e3f5a22cade6641f0fd68422c738ea46686fa2a0 Mon Sep 17 00:00:00 2001 From: Vincent Verelst Date: Tue, 21 Jan 2025 14:18:15 +0100 Subject: [PATCH 1/2] split_job_s2 grid splits geometries based on intersection with voronoi s2grid #192 --- src/openeo_gfmap/manager/job_splitters.py | 19 +++++++++---------- tests/tests_unit/manager/test_managers.py | 6 +++--- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/openeo_gfmap/manager/job_splitters.py b/src/openeo_gfmap/manager/job_splitters.py index 7bd3e1b..873d17b 100644 --- a/src/openeo_gfmap/manager/job_splitters.py +++ b/src/openeo_gfmap/manager/job_splitters.py @@ -17,11 +17,11 @@ def load_s2_grid(web_mercator: bool = False) -> gpd.GeoDataFrame: """Returns a geo data frame from the S2 grid.""" # Builds the path where the geodataframe should be if not web_mercator: - gdf_path = Path.home() / ".openeo-gfmap" / "s2grid_bounds_4326_v2.geoparquet" - url = "https://artifactory.vgt.vito.be/artifactory/auxdata-public/gfmap/s2grid_bounds_4326_v2.geoparquet" + gdf_path = Path.home() / ".openeo-gfmap" / "s2grid_voronoi_4326.parquet.parquet" + url = "https://artifactory.vgt.vito.be/artifactory/auxdata-public/gfmap/s2grid_voronoi_4326.parquet" else: - gdf_path = Path.home() / ".openeo-gfmap" / "s2grid_bounds_3857_v2.geoparquet" - url = "https://artifactory.vgt.vito.be/artifactory/auxdata-public/gfmap/s2grid_bounds_3857_v2.geoparquet" + gdf_path = Path.home() / ".openeo-gfmap" / "s2grid_voronoi_3857parquet" + url = "https://artifactory.vgt.vito.be/artifactory/auxdata-public/gfmap/s2grid_voronoi_3857.parquet" if not gdf_path.exists(): _log.info("S2 grid not found, downloading it from artifactory.") @@ -112,13 +112,12 @@ def split_job_s2grid( polygons["centroid"] = polygons.geometry.centroid - # Dataset containing all the S2 tile centroids, find the nearest S2 tile for each point - s2_grid = load_s2_grid_centroids(web_mercator) + s2_grid = load_s2_grid(web_mercator) - s2_grid = s2_grid[s2_grid.cdse_valid] - - polygons = gpd.sjoin_nearest( - polygons.set_geometry("centroid"), s2_grid[["tile", "geometry"]] + polygons = gpd.sjoin( + polygons.set_geometry("centroid"), + s2_grid[["tile", "geometry"]], + predicate="intersects", ).drop(columns=["index_right", "centroid"]) polygons = polygons.set_geometry("geometry").to_crs(original_crs) diff --git a/tests/tests_unit/manager/test_managers.py b/tests/tests_unit/manager/test_managers.py index dcedc0b..99694fa 100644 --- a/tests/tests_unit/manager/test_managers.py +++ b/tests/tests_unit/manager/test_managers.py @@ -18,9 +18,9 @@ def test_split_job_s2grid(): "geometry": [ Point(60.02, 4.57), Point(59.6, 5.04), - Point(59.92, 3.37), + Point(59.46, 3.71), Point(59.07, 4.11), - Point(58.77, 4.87), + Point(59.1, 3.61), ], } polygons = gpd.GeoDataFrame(data, crs="EPSG:4326") @@ -32,7 +32,7 @@ def test_split_job_s2grid(): result = split_job_s2grid(polygons, max_points) assert ( - len(result) == 3 + len(result) == 4 ), "The number of GeoDataFrames returned should match the number of splits needed." # Check if the geometries are preserved From 5fa101b94091af36ef50d2778804e5aa52693c93 Mon Sep 17 00:00:00 2001 From: Vincent Verelst Date: Wed, 22 Jan 2025 16:05:20 +0100 Subject: [PATCH 2/2] changed local file paths for s2 grids #192 --- src/openeo_gfmap/manager/job_splitters.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openeo_gfmap/manager/job_splitters.py b/src/openeo_gfmap/manager/job_splitters.py index 873d17b..8a7322b 100644 --- a/src/openeo_gfmap/manager/job_splitters.py +++ b/src/openeo_gfmap/manager/job_splitters.py @@ -17,10 +17,10 @@ def load_s2_grid(web_mercator: bool = False) -> gpd.GeoDataFrame: """Returns a geo data frame from the S2 grid.""" # Builds the path where the geodataframe should be if not web_mercator: - gdf_path = Path.home() / ".openeo-gfmap" / "s2grid_voronoi_4326.parquet.parquet" + gdf_path = Path.home() / ".openeo-gfmap" / "s2grid_voronoi_4326.parquet" url = "https://artifactory.vgt.vito.be/artifactory/auxdata-public/gfmap/s2grid_voronoi_4326.parquet" else: - gdf_path = Path.home() / ".openeo-gfmap" / "s2grid_voronoi_3857parquet" + gdf_path = Path.home() / ".openeo-gfmap" / "s2grid_voronoi_3857.parquet" url = "https://artifactory.vgt.vito.be/artifactory/auxdata-public/gfmap/s2grid_voronoi_3857.parquet" if not gdf_path.exists():