From 223b5797b9f62584c4a144c4d6229a7fd14f44ef Mon Sep 17 00:00:00 2001 From: Emile Sonneveld Date: Tue, 23 Jul 2024 16:24:58 +0200 Subject: [PATCH] Assert sensible extends in UTM zones. https://github.com/Open-EO/openeo-geotrellis-extensions/issues/279 --- .../org/openeo/geotrellis/layers/FileLayerProvider.scala | 6 ++++++ .../openeo/geotrellis/layers/FileLayerProviderTest.scala | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/openeo-geotrellis/src/main/scala/org/openeo/geotrellis/layers/FileLayerProvider.scala b/openeo-geotrellis/src/main/scala/org/openeo/geotrellis/layers/FileLayerProvider.scala index 9ab0332d..259e65c3 100644 --- a/openeo-geotrellis/src/main/scala/org/openeo/geotrellis/layers/FileLayerProvider.scala +++ b/openeo-geotrellis/src/main/scala/org/openeo/geotrellis/layers/FileLayerProvider.scala @@ -886,6 +886,12 @@ class FileLayerProvider private(openSearch: OpenSearchClient, openSearchCollecti val reprojectedBoundingBox: ProjectedExtent = DatacubeSupport.targetBoundingBox(fullBBox, layoutScheme) val alignedExtent = worldLayout.createAlignedRasterExtent(reprojectedBoundingBox.extent) + val polygonIsUTM = polygons_crs.proj4jCrs.getProjection.getName == "utm" + if (polygonIsUTM) { + // This is an extend that has the highest sensible values for northern and/or southern hemisphere UTM zones + val utmProjectedBounds = Extent(166021.44, 0000000.00, 833978.56, 10000000) + assert(alignedExtent.extent.intersects(utmProjectedBounds), "Extend should be in valid values of UTM zone to avoid distortion when reprojecting.") + } logger.info(s"Loading ${openSearchCollectionId} with params ${datacubeParams.getOrElse(new DataCubeParameters)} and bands ${openSearchLinkTitles.toList.mkString(";")} initial layout: ${worldLayout}") diff --git a/openeo-geotrellis/src/test/scala/org/openeo/geotrellis/layers/FileLayerProviderTest.scala b/openeo-geotrellis/src/test/scala/org/openeo/geotrellis/layers/FileLayerProviderTest.scala index 3f133ff4..952714c2 100644 --- a/openeo-geotrellis/src/test/scala/org/openeo/geotrellis/layers/FileLayerProviderTest.scala +++ b/openeo-geotrellis/src/test/scala/org/openeo/geotrellis/layers/FileLayerProviderTest.scala @@ -1165,6 +1165,11 @@ class FileLayerProviderTest extends RasterMatchers{ cubeSpatial.writeGeoTiff(outDir + "/testMissingS2DateLine_" + crsName.replace(":", "_") + ".tiff") } + @Test + def testMissingS2DateLineOutside(): Unit = { + assertThrows[AssertionError](testMissingS2DateLine("EPSG:32631")) + } + private def keysForLargeArea(useBBox:Boolean=false) = { val date = LocalDate.of(2022, 2, 11).atStartOfDay(UTC) val crs = CRS.fromEpsgCode(32630)