From c5745417c9277ae94794727d1577d00a2c6b9f7d Mon Sep 17 00:00:00 2001 From: jesspav Date: Tue, 20 May 2025 21:57:56 -0700 Subject: [PATCH 01/10] Upgrade to geotools33 --- .github/workflows/r.yml | 4 +- R/tests/testthat/test-data-interface-raster.R | 6 +- .../sedona/common/FunctionsGeoTools.java | 14 ++-- .../common/raster/GeometryFunctions.java | 8 +-- .../common/raster/PixelFunctionEditors.java | 4 +- .../sedona/common/raster/PixelFunctions.java | 12 ++-- .../sedona/common/raster/RasterAccessors.java | 8 +-- .../common/raster/RasterBandAccessors.java | 2 +- .../common/raster/RasterBandEditors.java | 12 ++-- .../common/raster/RasterConstructors.java | 14 ++-- .../raster/RasterConstructorsForTesting.java | 6 +- .../sedona/common/raster/RasterEditors.java | 22 +++--- .../sedona/common/raster/RasterOutputs.java | 6 +- .../common/raster/RasterPredicates.java | 12 ++-- .../sedona/common/raster/Rasterization.java | 40 +++++------ .../common/raster/netcdf/NetCdfReader.java | 4 +- .../common/raster/serde/CRSSerializer.java | 4 +- .../sedona/common/raster/serde/Serde.java | 2 +- .../utils/CachedCRSTransformFinder.java | 6 +- .../sedona/common/utils/RasterUtils.java | 31 +++++---- .../apache/sedona/common/FunctionsTest.java | 67 +++++++++---------- .../common/raster/FunctionEditorsTest.java | 4 +- .../sedona/common/raster/FunctionsTest.java | 10 ++- .../common/raster/GeometryFunctionsTest.java | 4 +- .../sedona/common/raster/MapAlgebraTest.java | 2 +- .../common/raster/RasterAccessorsTest.java | 4 +- .../raster/RasterBandAccessorsTest.java | 2 +- .../common/raster/RasterBandEditorsTest.java | 4 +- .../common/raster/RasterConstructorsTest.java | 22 +++--- .../common/raster/RasterEditorsTest.java | 24 +++---- .../common/raster/RasterOutputTest.java | 2 +- .../common/raster/RasterPredicatesTest.java | 8 +-- .../sedona/common/raster/RasterTestBase.java | 30 ++++----- .../raster/serde/CRSSerializerTest.java | 4 +- .../sedona/common/raster/serde/SerdeTest.java | 2 +- examples/flink-sql/pom.xml | 2 +- .../sedona/flink/expressions/Functions.java | 4 +- .../flink/expressions/FunctionsGeoTools.java | 4 +- .../org/apache/sedona/flink/FunctionTest.java | 4 +- pom.xml | 2 +- .../snowflake/snowsql/GeoToolsWrapper.java | 4 +- .../sedona/core/spatialOperator/KNNQuery.java | 4 +- .../geopackage/model/TileMetadata.scala | 2 +- .../geopackage/transform/Image.scala | 12 ++-- .../strategy/join/JoinedGeometryRaster.scala | 12 ++-- .../shapes/ShapefileRDDTest.java | 12 ++-- .../shapes/ShapefileReaderTest.java | 14 ++-- .../apache/sedona/sql/functionTestScala.scala | 4 +- .../apache/sedona/sql/rasteralgebraTest.scala | 6 +- 49 files changed, 239 insertions(+), 253 deletions(-) diff --git a/.github/workflows/r.yml b/.github/workflows/r.yml index dcd48743cb6..351cd3f7309 100644 --- a/.github/workflows/r.yml +++ b/.github/workflows/r.yml @@ -56,7 +56,7 @@ jobs: spark: [3.4.0, 3.5.0] hadoop: [3] scala: [2.12.15] - r: [oldrel, release] + r: [oldrel] env: SPARK_VERSION: ${{ matrix.spark }} HADOOP_VERSION: ${{ matrix.hadoop }} @@ -124,7 +124,7 @@ jobs: - name: Build Sedona libraries run: | SPARK_COMPAT_VERSION=${SPARK_VERSION:0:3} - mvn -q clean install -DskipTests -Dspark=${SPARK_COMPAT_VERSION} -Dscala=${SCALA_VERSION:0:4} + mvn -q clean install -DskipTests -Dspark=${SPARK_COMPAT_VERSION} -Dscala=${SCALA_VERSION:0:4} -Dgeotools - name: Run tests run: | if [[ "${SPARK_VERSION:0:3}" < "3.3" ]]; then diff --git a/R/tests/testthat/test-data-interface-raster.R b/R/tests/testthat/test-data-interface-raster.R index 96275d4a6ae..b4c235f85b4 100644 --- a/R/tests/testthat/test-data-interface-raster.R +++ b/R/tests/testthat/test-data-interface-raster.R @@ -26,7 +26,7 @@ sc <- testthat_spark_connection() test_that("Passed RS_FromGeoTiff from binary", { ## Load sdf_name <- random_string("spatial_sdf") - binary_sdf <- spark_read_binary(sc, dir = test_data("raster/test1.tiff"), name = sdf_name) + binary_sdf <- spark_read_binary(sc, dir = test_data("raster"), name = sdf_name) raster_sdf <- binary_sdf %>% @@ -91,7 +91,7 @@ test_that("Passed RS_FromArcInfoAsciiGrid from binary", { test_that("Passed RS_Envelope with raster", { ## Load sdf_name <- random_string("spatial_sdf") - binary_sdf <- spark_read_binary(sc, dir = test_data("raster/test1.tiff"), name = sdf_name) + binary_sdf <- spark_read_binary(sc, dir = test_data("raster"), name = sdf_name) raster_sdf <- binary_sdf %>% @@ -182,7 +182,7 @@ test_that("Passed RS_Value with raster", { test_that("Passed RS_Values with raster", { ## Load sdf_name <- random_string("spatial_sdf") - binary_sdf <- spark_read_binary(sc, dir = test_data("raster/test1.tiff"), name = sdf_name) + binary_sdf <- spark_read_binary(sc, dir = test_data("raster"), name = sdf_name) a <- binary_sdf %>% diff --git a/common/src/main/java/org/apache/sedona/common/FunctionsGeoTools.java b/common/src/main/java/org/apache/sedona/common/FunctionsGeoTools.java index 0fa390023e0..3ae6f5b1051 100644 --- a/common/src/main/java/org/apache/sedona/common/FunctionsGeoTools.java +++ b/common/src/main/java/org/apache/sedona/common/FunctionsGeoTools.java @@ -19,6 +19,12 @@ package org.apache.sedona.common; import java.util.Set; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.NoSuchAuthorityCodeException; +import org.geotools.api.referencing.ReferenceIdentifier; +import org.geotools.api.referencing.crs.CoordinateReferenceSystem; +import org.geotools.api.referencing.operation.MathTransform; +import org.geotools.api.referencing.operation.TransformException; import org.geotools.geometry.jts.JTS; import org.geotools.referencing.CRS; import org.geotools.referencing.ReferencingFactoryFinder; @@ -28,12 +34,6 @@ import org.locationtech.jts.operation.buffer.BufferOp; import org.locationtech.jts.operation.buffer.BufferParameters; import org.locationtech.jts.triangulate.VoronoiDiagramBuilder; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.NoSuchAuthorityCodeException; -import org.opengis.referencing.ReferenceIdentifier; -import org.opengis.referencing.crs.CoordinateReferenceSystem; -import org.opengis.referencing.operation.MathTransform; -import org.opengis.referencing.operation.TransformException; public class FunctionsGeoTools { @@ -202,8 +202,6 @@ public static Geometry bufferSpheroid(Geometry geometry, double radius, BufferPa if (Functions.crossesDateLine(geometry)) { Functions.shiftLongitude(geometry); } - // geometry = (Predicates.crossesDateLine(geometry)) ? Functions.shiftLongitude(geometry) - // : geometry; // If originalCRS is not set, use WGS84 as the originalCRS for transformation String sourceCRSCode = (originalCRS == 0) ? "EPSG:" + WGS84CRS : "EPSG:" + originalCRS; diff --git a/common/src/main/java/org/apache/sedona/common/raster/GeometryFunctions.java b/common/src/main/java/org/apache/sedona/common/raster/GeometryFunctions.java index 19e0ef1fd89..15221c7158c 100644 --- a/common/src/main/java/org/apache/sedona/common/raster/GeometryFunctions.java +++ b/common/src/main/java/org/apache/sedona/common/raster/GeometryFunctions.java @@ -20,12 +20,12 @@ import java.awt.geom.Point2D; import org.apache.sedona.common.utils.RasterUtils; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.operation.TransformException; import org.geotools.coverage.grid.GridCoordinates2D; import org.geotools.coverage.grid.GridCoverage2D; -import org.geotools.geometry.Envelope2D; +import org.geotools.geometry.jts.ReferencedEnvelope; import org.locationtech.jts.geom.*; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.operation.TransformException; public class GeometryFunctions { @@ -140,7 +140,7 @@ public static void ensureSafeBand(GridCoverage2D raster, int band) } public static Geometry envelope(GridCoverage2D raster) throws FactoryException { - Envelope2D envelope2D = raster.getEnvelope2D(); + ReferencedEnvelope envelope2D = raster.getEnvelope2D(); Envelope envelope = new Envelope( diff --git a/common/src/main/java/org/apache/sedona/common/raster/PixelFunctionEditors.java b/common/src/main/java/org/apache/sedona/common/raster/PixelFunctionEditors.java index 5a5db76cf75..ea88350049c 100644 --- a/common/src/main/java/org/apache/sedona/common/raster/PixelFunctionEditors.java +++ b/common/src/main/java/org/apache/sedona/common/raster/PixelFunctionEditors.java @@ -25,10 +25,10 @@ import javax.media.jai.RasterFactory; import org.apache.commons.lang3.tuple.Pair; import org.apache.sedona.common.utils.RasterUtils; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.operation.TransformException; import org.geotools.coverage.grid.GridCoverage2D; import org.locationtech.jts.geom.Geometry; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.operation.TransformException; public class PixelFunctionEditors { diff --git a/common/src/main/java/org/apache/sedona/common/raster/PixelFunctions.java b/common/src/main/java/org/apache/sedona/common/raster/PixelFunctions.java index 867f041187a..148431f009f 100644 --- a/common/src/main/java/org/apache/sedona/common/raster/PixelFunctions.java +++ b/common/src/main/java/org/apache/sedona/common/raster/PixelFunctions.java @@ -25,15 +25,15 @@ import java.util.List; import org.apache.commons.lang3.tuple.Pair; import org.apache.sedona.common.utils.RasterUtils; +import org.geotools.api.coverage.PointOutsideCoverageException; +import org.geotools.api.geometry.Position; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.operation.TransformException; import org.geotools.coverage.grid.GridCoordinates2D; import org.geotools.coverage.grid.GridCoverage2D; -import org.geotools.geometry.DirectPosition2D; +import org.geotools.geometry.Position2D; import org.geotools.referencing.operation.transform.AffineTransform2D; import org.locationtech.jts.geom.*; -import org.opengis.coverage.PointOutsideCoverageException; -import org.opengis.geometry.DirectPosition; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.operation.TransformException; public class PixelFunctions { private static GeometryFactory GEOMETRY_FACTORY = new GeometryFactory(); @@ -289,7 +289,7 @@ public static List values(GridCoverage2D rasterGeom, List geom result.add(null); } else { Point point = ensurePoint(geom); - DirectPosition directPosition2D = new DirectPosition2D(point.getX(), point.getY()); + Position directPosition2D = new Position2D(point.getX(), point.getY()); try { rasterGeom.evaluate(directPosition2D, pixelBuffer); double pixel = pixelBuffer[band - 1]; diff --git a/common/src/main/java/org/apache/sedona/common/raster/RasterAccessors.java b/common/src/main/java/org/apache/sedona/common/raster/RasterAccessors.java index cdf08d56a23..49a9223908d 100644 --- a/common/src/main/java/org/apache/sedona/common/raster/RasterAccessors.java +++ b/common/src/main/java/org/apache/sedona/common/raster/RasterAccessors.java @@ -23,6 +23,10 @@ import java.util.Arrays; import java.util.Set; import org.apache.sedona.common.utils.RasterUtils; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.ReferenceIdentifier; +import org.geotools.api.referencing.crs.CoordinateReferenceSystem; +import org.geotools.api.referencing.operation.TransformException; import org.geotools.coverage.grid.GridCoverage2D; import org.geotools.coverage.grid.GridEnvelope2D; import org.geotools.referencing.crs.DefaultEngineeringCRS; @@ -31,10 +35,6 @@ import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.Point; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.ReferenceIdentifier; -import org.opengis.referencing.crs.CoordinateReferenceSystem; -import org.opengis.referencing.operation.TransformException; public class RasterAccessors { public static int srid(GridCoverage2D raster) throws FactoryException { diff --git a/common/src/main/java/org/apache/sedona/common/raster/RasterBandAccessors.java b/common/src/main/java/org/apache/sedona/common/raster/RasterBandAccessors.java index f5011d5a1cd..94746f9f785 100644 --- a/common/src/main/java/org/apache/sedona/common/raster/RasterBandAccessors.java +++ b/common/src/main/java/org/apache/sedona/common/raster/RasterBandAccessors.java @@ -30,10 +30,10 @@ import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation; import org.apache.sedona.common.Functions; import org.apache.sedona.common.utils.RasterUtils; +import org.geotools.api.referencing.FactoryException; import org.geotools.coverage.GridSampleDimension; import org.geotools.coverage.grid.GridCoverage2D; import org.locationtech.jts.geom.Geometry; -import org.opengis.referencing.FactoryException; public class RasterBandAccessors { diff --git a/common/src/main/java/org/apache/sedona/common/raster/RasterBandEditors.java b/common/src/main/java/org/apache/sedona/common/raster/RasterBandEditors.java index 3abd56869eb..51c906429f3 100644 --- a/common/src/main/java/org/apache/sedona/common/raster/RasterBandEditors.java +++ b/common/src/main/java/org/apache/sedona/common/raster/RasterBandEditors.java @@ -27,17 +27,17 @@ import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.tuple.Pair; import org.apache.sedona.common.utils.RasterUtils; +import org.geotools.api.geometry.BoundingBox; +import org.geotools.api.parameter.ParameterValueGroup; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.operation.TransformException; import org.geotools.coverage.GridSampleDimension; import org.geotools.coverage.grid.GridCoverage2D; import org.geotools.coverage.processing.CannotCropException; import org.geotools.coverage.processing.operation.Crop; -import org.geotools.geometry.Envelope2D; import org.geotools.geometry.jts.JTS; +import org.geotools.geometry.jts.ReferencedEnvelope; import org.locationtech.jts.geom.Geometry; -import org.opengis.geometry.BoundingBox; -import org.opengis.parameter.ParameterValueGroup; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.operation.TransformException; public class RasterBandEditors { /** @@ -303,7 +303,7 @@ public static GridCoverage2D clip( // Use rasterizeGeomExtent for AOI geometries smaller than a pixel double[] metadata = RasterAccessors.metadata(singleBandRaster); - Envelope2D geomEnvelope = + ReferencedEnvelope geomEnvelope = Rasterization.rasterizeGeomExtent(geometry, singleBandRaster, metadata, allTouched); Geometry geomExtent = JTS.toGeometry((BoundingBox) geomEnvelope); diff --git a/common/src/main/java/org/apache/sedona/common/raster/RasterConstructors.java b/common/src/main/java/org/apache/sedona/common/raster/RasterConstructors.java index c43596c6dde..e379b246485 100644 --- a/common/src/main/java/org/apache/sedona/common/raster/RasterConstructors.java +++ b/common/src/main/java/org/apache/sedona/common/raster/RasterConstructors.java @@ -32,6 +32,13 @@ import org.apache.sedona.common.raster.netcdf.NetCdfReader; import org.apache.sedona.common.utils.ImageUtils; import org.apache.sedona.common.utils.RasterUtils; +import org.geotools.api.feature.simple.SimpleFeature; +import org.geotools.api.feature.simple.SimpleFeatureType; +import org.geotools.api.metadata.spatial.PixelOrientation; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.crs.CoordinateReferenceSystem; +import org.geotools.api.referencing.datum.PixelInCell; +import org.geotools.api.referencing.operation.MathTransform; import org.geotools.coverage.GridSampleDimension; import org.geotools.coverage.grid.GridCoverage2D; import org.geotools.coverage.grid.GridEnvelope2D; @@ -46,13 +53,6 @@ import org.geotools.referencing.operation.transform.AffineTransform2D; import org.geotools.util.factory.Hints; import org.locationtech.jts.geom.Geometry; -import org.opengis.feature.simple.SimpleFeature; -import org.opengis.feature.simple.SimpleFeatureType; -import org.opengis.metadata.spatial.PixelOrientation; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.crs.CoordinateReferenceSystem; -import org.opengis.referencing.datum.PixelInCell; -import org.opengis.referencing.operation.MathTransform; import ucar.nc2.NetcdfFile; import ucar.nc2.NetcdfFiles; diff --git a/common/src/main/java/org/apache/sedona/common/raster/RasterConstructorsForTesting.java b/common/src/main/java/org/apache/sedona/common/raster/RasterConstructorsForTesting.java index b9d2a047b77..e9af594ea8e 100644 --- a/common/src/main/java/org/apache/sedona/common/raster/RasterConstructorsForTesting.java +++ b/common/src/main/java/org/apache/sedona/common/raster/RasterConstructorsForTesting.java @@ -39,6 +39,9 @@ import org.apache.commons.lang3.ArrayUtils; import org.apache.sedona.common.FunctionsGeoTools; import org.apache.sedona.common.utils.RasterUtils; +import org.geotools.api.referencing.crs.CoordinateReferenceSystem; +import org.geotools.api.referencing.datum.PixelInCell; +import org.geotools.api.referencing.operation.MathTransform; import org.geotools.coverage.CoverageFactoryFinder; import org.geotools.coverage.grid.GridCoverage2D; import org.geotools.coverage.grid.GridCoverageFactory; @@ -46,9 +49,6 @@ import org.geotools.coverage.grid.GridGeometry2D; import org.geotools.referencing.crs.DefaultEngineeringCRS; import org.geotools.referencing.operation.transform.AffineTransform2D; -import org.opengis.referencing.crs.CoordinateReferenceSystem; -import org.opengis.referencing.datum.PixelInCell; -import org.opengis.referencing.operation.MathTransform; /** Raster constructor for testing the Python implementation of raster deserializer. */ public class RasterConstructorsForTesting { diff --git a/common/src/main/java/org/apache/sedona/common/raster/RasterEditors.java b/common/src/main/java/org/apache/sedona/common/raster/RasterEditors.java index eab88525bc6..f28fd77c6a1 100644 --- a/common/src/main/java/org/apache/sedona/common/raster/RasterEditors.java +++ b/common/src/main/java/org/apache/sedona/common/raster/RasterEditors.java @@ -31,6 +31,15 @@ import org.apache.sedona.common.FunctionsGeoTools; import org.apache.sedona.common.utils.RasterInterpolate; import org.apache.sedona.common.utils.RasterUtils; +import org.geotools.api.coverage.grid.GridCoverage; +import org.geotools.api.coverage.grid.GridGeometry; +import org.geotools.api.metadata.spatial.PixelOrientation; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.crs.CoordinateReferenceSystem; +import org.geotools.api.referencing.datum.PixelInCell; +import org.geotools.api.referencing.operation.MathTransform; +import org.geotools.api.referencing.operation.MathTransform2D; +import org.geotools.api.referencing.operation.TransformException; import org.geotools.coverage.CoverageFactoryFinder; import org.geotools.coverage.GridSampleDimension; import org.geotools.coverage.grid.GridCoverage2D; @@ -38,19 +47,10 @@ import org.geotools.coverage.grid.GridEnvelope2D; import org.geotools.coverage.grid.GridGeometry2D; import org.geotools.coverage.processing.Operations; -import org.geotools.geometry.Envelope2D; +import org.geotools.geometry.jts.ReferencedEnvelope; import org.geotools.referencing.crs.DefaultEngineeringCRS; import org.geotools.referencing.operation.transform.AffineTransform2D; import org.locationtech.jts.index.strtree.STRtree; -import org.opengis.coverage.grid.GridCoverage; -import org.opengis.coverage.grid.GridGeometry; -import org.opengis.metadata.spatial.PixelOrientation; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.crs.CoordinateReferenceSystem; -import org.opengis.referencing.datum.PixelInCell; -import org.opengis.referencing.operation.MathTransform; -import org.opengis.referencing.operation.MathTransform2D; -import org.opengis.referencing.operation.TransformException; public class RasterEditors { @@ -224,7 +224,7 @@ public static GridCoverage2D resample( return raster; } - Envelope2D envelope2D = raster.getEnvelope2D(); + ReferencedEnvelope envelope2D = raster.getEnvelope2D(); // process scale changes due to changes in widthOrScale and heightOrScale if (!useScale) { newScaleX = (Math.abs(envelope2D.getMaxX() - envelope2D.getMinX())) / newWidth; diff --git a/common/src/main/java/org/apache/sedona/common/raster/RasterOutputs.java b/common/src/main/java/org/apache/sedona/common/raster/RasterOutputs.java index 6a1a9d191f1..77d115352f0 100644 --- a/common/src/main/java/org/apache/sedona/common/raster/RasterOutputs.java +++ b/common/src/main/java/org/apache/sedona/common/raster/RasterOutputs.java @@ -36,15 +36,15 @@ import javax.media.jai.JAI; import javax.media.jai.RenderedOp; import org.apache.sedona.common.utils.RasterUtils; +import org.geotools.api.coverage.grid.GridCoverageWriter; +import org.geotools.api.parameter.GeneralParameterValue; +import org.geotools.api.parameter.ParameterValueGroup; import org.geotools.coverage.grid.GridCoverage2D; import org.geotools.coverage.grid.io.AbstractGridFormat; import org.geotools.gce.arcgrid.ArcGridWriteParams; import org.geotools.gce.arcgrid.ArcGridWriter; import org.geotools.gce.geotiff.GeoTiffWriteParams; import org.geotools.gce.geotiff.GeoTiffWriter; -import org.opengis.coverage.grid.GridCoverageWriter; -import org.opengis.parameter.GeneralParameterValue; -import org.opengis.parameter.ParameterValueGroup; public class RasterOutputs { public static byte[] asGeoTiff( diff --git a/common/src/main/java/org/apache/sedona/common/raster/RasterPredicates.java b/common/src/main/java/org/apache/sedona/common/raster/RasterPredicates.java index 41efb3a778f..3bceb34de3e 100644 --- a/common/src/main/java/org/apache/sedona/common/raster/RasterPredicates.java +++ b/common/src/main/java/org/apache/sedona/common/raster/RasterPredicates.java @@ -23,18 +23,18 @@ import org.apache.sedona.common.FunctionsGeoTools; import org.apache.sedona.common.utils.CachedCRSTransformFinder; import org.apache.sedona.common.utils.GeomUtils; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.ReferenceIdentifier; +import org.geotools.api.referencing.crs.CoordinateReferenceSystem; +import org.geotools.api.referencing.crs.GeographicCRS; +import org.geotools.api.referencing.operation.MathTransform; +import org.geotools.api.referencing.operation.TransformException; import org.geotools.coverage.grid.GridCoverage2D; import org.geotools.geometry.jts.JTS; import org.geotools.referencing.CRS; import org.geotools.referencing.crs.DefaultEngineeringCRS; import org.geotools.referencing.crs.DefaultGeographicCRS; import org.locationtech.jts.geom.Geometry; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.ReferenceIdentifier; -import org.opengis.referencing.crs.CoordinateReferenceSystem; -import org.opengis.referencing.crs.GeographicCRS; -import org.opengis.referencing.operation.MathTransform; -import org.opengis.referencing.operation.TransformException; public class RasterPredicates { /** diff --git a/common/src/main/java/org/apache/sedona/common/raster/Rasterization.java b/common/src/main/java/org/apache/sedona/common/raster/Rasterization.java index 5d15990d6fe..b62a615b1cd 100644 --- a/common/src/main/java/org/apache/sedona/common/raster/Rasterization.java +++ b/common/src/main/java/org/apache/sedona/common/raster/Rasterization.java @@ -25,13 +25,13 @@ import javax.media.jai.RasterFactory; import org.apache.sedona.common.Functions; import org.apache.sedona.common.utils.RasterUtils; +import org.geotools.api.geometry.BoundingBox; +import org.geotools.api.referencing.FactoryException; import org.geotools.coverage.grid.GridCoverage2D; import org.geotools.coverage.grid.GridCoverageFactory; -import org.geotools.geometry.Envelope2D; import org.geotools.geometry.jts.JTS; +import org.geotools.geometry.jts.ReferencedEnvelope; import org.locationtech.jts.geom.*; -import org.opengis.geometry.BoundingBox; -import org.opengis.referencing.FactoryException; public class Rasterization { protected static List rasterize( @@ -50,9 +50,9 @@ protected static List rasterize( throw new IllegalArgumentException("Geometry does not intersect Raster."); } - Envelope2D rasterExtent = raster.getEnvelope2D(); + ReferencedEnvelope rasterExtent = raster.getEnvelope2D(); - Envelope2D geomExtent = rasterizeGeomExtent(geom, raster, metadata, allTouched); + ReferencedEnvelope geomExtent = rasterizeGeomExtent(geom, raster, metadata, allTouched); RasterizationParams params = calculateRasterizationParams(raster, useGeometryExtent, metadata, geomExtent, pixelType); @@ -82,7 +82,7 @@ private static void rasterizeGeometry( double[] metadata, Geometry geom, RasterizationParams params, - Envelope2D geomExtent, + ReferencedEnvelope geomExtent, double value, boolean allTouched) throws FactoryException { @@ -118,13 +118,13 @@ private static void rasterizeGeometryCollection( for (int i = 0; i < geom.getNumGeometries(); i++) { Geometry subGeom = geom.getGeometryN(i); - Envelope2D subGeomExtent = rasterizeGeomExtent(subGeom, raster, metadata, allTouched); + ReferencedEnvelope subGeomExtent = rasterizeGeomExtent(subGeom, raster, metadata, allTouched); rasterizeGeometry(raster, metadata, subGeom, params, subGeomExtent, value, allTouched); } } private static void rasterizePoint( - Geometry geom, RasterizationParams params, Envelope2D geomExtent, double value) { + Geometry geom, RasterizationParams params, ReferencedEnvelope geomExtent, double value) { int startX = (int) Math.round(((geomExtent.getMinX() - params.upperLeftX) / params.scaleX)); int startY = (int) Math.round(((geomExtent.getMinY() - params.upperLeftY) / params.scaleY)); @@ -157,7 +157,7 @@ private static void rasterizePoint( } private static void rasterizeLineString( - Geometry geom, RasterizationParams params, double value, Envelope2D geomExtent) { + Geometry geom, RasterizationParams params, double value, ReferencedEnvelope geomExtent) { for (int i = 0; i < geom.getNumGeometries(); i++) { LineString line = (LineString) geom.getGeometryN(i); Coordinate[] coords = line.getCoordinates(); @@ -231,7 +231,7 @@ private static void drawLineBresenham( } private static LineSegment clipSegmentToRasterBounds( - Coordinate p1, Coordinate p2, Envelope2D geomExtent) { + Coordinate p1, Coordinate p2, ReferencedEnvelope geomExtent) { double minX = geomExtent.getMinX(); double maxX = geomExtent.getMaxX(); double minY = geomExtent.getMinY(); @@ -303,7 +303,7 @@ private static boolean isInsideBounds( return x >= minX && x <= maxX && y >= minY && y <= maxY; } - protected static Envelope2D rasterizeGeomExtent( + protected static ReferencedEnvelope rasterizeGeomExtent( Geometry geom, GridCoverage2D raster, double[] metadata, boolean allTouched) { if (Objects.equals(geom.getGeometryType(), "MultiLineString")) { @@ -313,8 +313,8 @@ protected static Envelope2D rasterizeGeomExtent( allTouched = true; } - Envelope2D rasterExtent = - JTS.getEnvelope2D(geom.getEnvelopeInternal(), raster.getCoordinateReferenceSystem2D()); + ReferencedEnvelope rasterExtent = + new ReferencedEnvelope(geom.getEnvelopeInternal(), raster.getCoordinateReferenceSystem2D()); // Using BigDecimal to avoid floating point errors BigDecimal upperLeftX = BigDecimal.valueOf(metadata[0]); @@ -387,13 +387,13 @@ protected static Envelope2D rasterizeGeomExtent( alignedMaxY = Math.min(alignedMaxY, originalMaxY); // Create the aligned raster extent - Envelope2D alignedRasterExtent = - new Envelope2D( - rasterExtent.getCoordinateReferenceSystem(), + ReferencedEnvelope alignedRasterExtent = + ReferencedEnvelope.rect( alignedMinX, alignedMinY, alignedMaxX - alignedMinX, - alignedMaxY - alignedMinY); + alignedMaxY - alignedMinY, + rasterExtent.getCoordinateReferenceSystem()); return alignedRasterExtent; } @@ -402,7 +402,7 @@ private static RasterizationParams calculateRasterizationParams( GridCoverage2D raster, boolean useGeometryExtent, double[] metadata, - Envelope2D geomExtent, + ReferencedEnvelope geomExtent, String pixelType) { double upperLeftX = 0; @@ -474,7 +474,7 @@ private static class RasterizationParams { public static void rasterizePolygon( Geometry geom, RasterizationParams params, - Envelope2D geomExtent, + ReferencedEnvelope geomExtent, double value, boolean allTouched) { if (!(geom instanceof Polygon)) { @@ -512,7 +512,7 @@ private static Map> computeScanlineIntersections( Polygon polygon, RasterizationParams params, double value, - Envelope2D geomExtent, + ReferencedEnvelope geomExtent, boolean allTouched) { Map> scanlineIntersections = new HashMap<>(); diff --git a/common/src/main/java/org/apache/sedona/common/raster/netcdf/NetCdfReader.java b/common/src/main/java/org/apache/sedona/common/raster/netcdf/NetCdfReader.java index 945e57618f0..7ca8c164caa 100644 --- a/common/src/main/java/org/apache/sedona/common/raster/netcdf/NetCdfReader.java +++ b/common/src/main/java/org/apache/sedona/common/raster/netcdf/NetCdfReader.java @@ -22,9 +22,9 @@ import java.io.IOException; import java.util.*; import org.apache.sedona.common.raster.RasterConstructors; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.datum.PixelInCell; import org.geotools.coverage.grid.GridCoverage2D; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.datum.PixelInCell; import ucar.ma2.Array; import ucar.nc2.*; diff --git a/common/src/main/java/org/apache/sedona/common/raster/serde/CRSSerializer.java b/common/src/main/java/org/apache/sedona/common/raster/serde/CRSSerializer.java index 26d52ac737a..81c98bd7223 100644 --- a/common/src/main/java/org/apache/sedona/common/raster/serde/CRSSerializer.java +++ b/common/src/main/java/org/apache/sedona/common/raster/serde/CRSSerializer.java @@ -29,10 +29,10 @@ import java.util.zip.InflaterInputStream; import javax.measure.IncommensurableException; import org.apache.commons.io.IOUtils; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.crs.CoordinateReferenceSystem; import org.geotools.referencing.CRS; import org.geotools.referencing.wkt.Formattable; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.crs.CoordinateReferenceSystem; import si.uom.NonSI; import si.uom.SI; diff --git a/common/src/main/java/org/apache/sedona/common/raster/serde/Serde.java b/common/src/main/java/org/apache/sedona/common/raster/serde/Serde.java index 5125e64532d..d085f191f08 100644 --- a/common/src/main/java/org/apache/sedona/common/raster/serde/Serde.java +++ b/common/src/main/java/org/apache/sedona/common/raster/serde/Serde.java @@ -31,6 +31,7 @@ import java.net.URI; import javax.media.jai.RenderedImageAdapter; import org.apache.sedona.common.raster.DeepCopiedRenderedImage; +import org.geotools.api.referencing.operation.MathTransform; import org.geotools.coverage.GridSampleDimension; import org.geotools.coverage.grid.GridCoverage2D; import org.geotools.coverage.grid.GridCoverageFactory; @@ -38,7 +39,6 @@ import org.geotools.coverage.grid.GridGeometry2D; import org.geotools.referencing.operation.transform.AffineTransform2D; import org.objenesis.strategy.StdInstantiatorStrategy; -import org.opengis.referencing.operation.MathTransform; public class Serde { private Serde() {} diff --git a/common/src/main/java/org/apache/sedona/common/utils/CachedCRSTransformFinder.java b/common/src/main/java/org/apache/sedona/common/utils/CachedCRSTransformFinder.java index 1d125cf9d61..bb98cfa483e 100644 --- a/common/src/main/java/org/apache/sedona/common/utils/CachedCRSTransformFinder.java +++ b/common/src/main/java/org/apache/sedona/common/utils/CachedCRSTransformFinder.java @@ -20,10 +20,10 @@ import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.LoadingCache; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.crs.CoordinateReferenceSystem; +import org.geotools.api.referencing.operation.MathTransform; import org.geotools.referencing.CRS; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.crs.CoordinateReferenceSystem; -import org.opengis.referencing.operation.MathTransform; /** * A utility class for finding CRS transforms. It avoids the expensive equals() call on CRS objects diff --git a/common/src/main/java/org/apache/sedona/common/utils/RasterUtils.java b/common/src/main/java/org/apache/sedona/common/utils/RasterUtils.java index f1425ca8e95..f962bb92605 100644 --- a/common/src/main/java/org/apache/sedona/common/utils/RasterUtils.java +++ b/common/src/main/java/org/apache/sedona/common/utils/RasterUtils.java @@ -41,6 +41,13 @@ import org.apache.sedona.common.FunctionsGeoTools; import org.apache.sedona.common.raster.RasterAccessors; import org.apache.sedona.common.raster.RasterEditors; +import org.geotools.api.coverage.grid.GridEnvelope; +import org.geotools.api.metadata.spatial.PixelOrientation; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.crs.CoordinateReferenceSystem; +import org.geotools.api.referencing.operation.MathTransform; +import org.geotools.api.referencing.operation.TransformException; +import org.geotools.api.util.InternationalString; import org.geotools.coverage.Category; import org.geotools.coverage.CoverageFactoryFinder; import org.geotools.coverage.GridSampleDimension; @@ -49,20 +56,12 @@ import org.geotools.coverage.grid.GridCoverageFactory; import org.geotools.coverage.grid.GridEnvelope2D; import org.geotools.coverage.grid.GridGeometry2D; -import org.geotools.geometry.DirectPosition2D; +import org.geotools.geometry.Position2D; import org.geotools.referencing.crs.DefaultEngineeringCRS; import org.geotools.referencing.operation.transform.AffineTransform2D; import org.geotools.util.ClassChanger; import org.geotools.util.NumberRange; import org.locationtech.jts.geom.Geometry; -import org.opengis.coverage.grid.GridEnvelope; -import org.opengis.geometry.DirectPosition; -import org.opengis.metadata.spatial.PixelOrientation; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.crs.CoordinateReferenceSystem; -import org.opengis.referencing.operation.MathTransform; -import org.opengis.referencing.operation.TransformException; -import org.opengis.util.InternationalString; /** Utility functions for working with GridCoverage2D objects. */ public class RasterUtils { @@ -466,7 +465,7 @@ public static AffineTransform2D translateAffineTransform( public static Point2D getWorldCornerCoordinates(GridCoverage2D raster, int colX, int rowY) throws TransformException { - Point2D.Double gridCoord = new DirectPosition2D(colX - 1, rowY - 1); + Point2D.Double gridCoord = new Position2D(colX - 1, rowY - 1); return raster .getGridGeometry() .getGridToCRS2D(PixelOrientation.UPPER_LEFT) @@ -488,7 +487,7 @@ public static Point2D getWorldCornerCoordinates(GridCoverage2D raster, int colX, public static Point2D getWorldCornerCoordinatesWithRangeCheck( GridCoverage2D raster, int colX, int rowY) throws IndexOutOfBoundsException, TransformException { - Point2D.Double gridCoordinates2D = new DirectPosition2D(colX - 1, rowY - 1); + Point2D.Double gridCoordinates2D = new Position2D(colX - 1, rowY - 1); if (!(raster.getGridGeometry().getGridRange2D().contains(gridCoordinates2D))) throw new IndexOutOfBoundsException( String.format( @@ -501,14 +500,14 @@ public static Point2D getWorldCornerCoordinatesWithRangeCheck( public static int[] getGridCoordinatesFromWorld( GridCoverage2D raster, double longitude, double latitude) throws TransformException { - DirectPosition2D directPosition2D = - new DirectPosition2D(raster.getCoordinateReferenceSystem2D(), longitude, latitude); - DirectPosition worldCoord = + Point2D directPosition2D = + new Position2D(raster.getCoordinateReferenceSystem2D(), longitude, latitude); + Point2D worldCoord = raster .getGridGeometry() .getCRSToGrid2D(PixelOrientation.UPPER_LEFT) - .transform((DirectPosition) directPosition2D, null); - double[] coords = worldCoord.getCoordinate(); + .transform(directPosition2D, null); + double[] coords = new double[] {worldCoord.getX(), worldCoord.getY()}; int[] gridCoords = new int[] {(int) Math.floor(coords[0]), (int) Math.floor(coords[1])}; return gridCoords; } diff --git a/common/src/test/java/org/apache/sedona/common/FunctionsTest.java b/common/src/test/java/org/apache/sedona/common/FunctionsTest.java index 8cafb9c6486..1c682a4e0ce 100644 --- a/common/src/test/java/org/apache/sedona/common/FunctionsTest.java +++ b/common/src/test/java/org/apache/sedona/common/FunctionsTest.java @@ -29,6 +29,8 @@ import org.apache.sedona.common.sphere.Haversine; import org.apache.sedona.common.sphere.Spheroid; import org.apache.sedona.common.utils.*; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.operation.TransformException; import org.geotools.referencing.CRS; import org.geotools.referencing.operation.projection.ProjectionException; import org.junit.Test; @@ -38,14 +40,13 @@ import org.locationtech.jts.io.ParseException; import org.locationtech.jts.io.WKTReader; import org.locationtech.jts.io.WKTWriter; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.operation.TransformException; public class FunctionsTest extends TestBase { public static final GeometryFactory GEOMETRY_FACTORY = new GeometryFactory(); protected static final double FP_TOLERANCE = 1e-12; protected static final double FP_TOLERANCE2 = 1e-4; + protected static final double IOU_TOLERANCE = 1E-8; protected static final CoordinateSequenceComparator COORDINATE_SEQUENCE_COMPARATOR = new CoordinateSequenceComparator(2) { @Override @@ -2965,7 +2966,8 @@ public void testBufferSpheroidal() throws ParseException { "POLYGON((-120.00898315284118 29.999999999999993,-120.00898315284118 49.99999999999999,-120.00881054407824 50.00112962562472,-120.0082993510474 50.00221581519921,-120.00746921861011 50.003216831392564,-120.00635204829044 50.004094212187034,-120.00499077231723 50.00481424796622,-120.00343770376273 50.00534927579437,-120.00175252618051 50.00567874132504,-119.99999999999999 50.00578998770771,-80 50.00578998770771,-79.99824747381949 50.00567874132504,-79.99656229623727 50.00534927579437,-79.99500922768276 50.00481424796622,-79.99364795170956 50.004094212187034,-79.99253078138987 50.003216831392564,-79.9917006489526 50.00221581519921,-79.99118945592174 50.00112962562472,-79.9910168471588 49.99999999999999,-79.9910168471588 29.999999999999993,-79.99118945592174 29.99847458440221,-79.9917006489526 29.997007767335962,-79.99253078138987 29.99565592159683,-79.99364795170956 29.99447100360229,-79.99500922768276 29.993498555861333,-79.99656229623727 29.992775955769954,-79.99824747381949 29.992330978187542,-80 29.992180727190387,-119.99999999999999 29.992180727190387,-120.00175252618051 29.992330978187542,-120.00343770376273 29.992775955769954,-120.00499077231723 29.993498555861333,-120.00635204829044 29.99447100360229,-120.00746921861011 29.99565592159683,-120.0082993510474 29.997007767335962,-120.00881054407824 29.99847458440221,-120.00898315284118 29.999999999999993))"); Geometry postgis_result3 = geomFromEWKT( - "POLYGON((-179.99820962883618 59.99995929000264,-179.99825989222717 59.999785136194745,-179.9983770256619 59.99961923984817,-179.99855652693947 59.99946797609105,-179.99879149742534 59.99933715766465,-179.999072907238 59.99923181157932,-179.99938994227725 59.9991559859705,-179.99973041975517 59.999112594569745,179.9999187437317 59.999103304762926,179.99957102955932 59.999128473531854,179.9992397991585 59.99918713373882,179.99893778069907 59.999277031280386,179.99867658007986 59.99939471168456,179.99846623499656 59.99953565282769,179.99831482921377 59.99969443867636,179.99822818186144 59.999864967383445,179.998209623704 60.00004068574784,179.9982598689955 60.00021484103153,179.9983769878675 60.000380740460706,179.99855648033625 60.00053200843791,179.99879144910815 60.000662831579476,179.99907286456278 60.00076818215714,179.99938991174088 60.00084401135155,179.99973040600648 60.00088740488531,-179.9999187385995 60.0008966950478,-179.99957100632759 60.00087152480308,-179.9992397613641 60.0008128615135,-179.99893773409582 60.000722959751855,-179.99867653176275 60.00060527463255,-179.99846619232136 60.00046432899707,-179.99831479867737 60.00030553956281,-179.99822816811277 60.000135008722694,-179.99820962883618 59.99995929000264))"); + "POLYGON((-179.99820962883618 59.99995929000264,-179.99825989222717 59.999785136194745,-179.9983770256619 59.99961923984817,-179.99855652693947 59.99946797609105,-179.99879149742534 59.99933715766465,-179.999072907238 59.99923181157932,-179.99938994227725 59.9991559859705,-179.99973041975517 59.99911259456973,179.9999187437317 59.999103304762926,179.99957102955932 59.999128473531854,179.9992397991585 59.99918713373882,179.99893778069907 59.999277031280386,179.99867658007986 59.99939471168456,179.99846623499656 59.99953565282769,179.99831482921377 59.99969443867636,179.99822818186144 59.99986496738346,179.998209623704 60.00004068574784,179.9982598689955 60.00021484103153,179.9983769878675 60.000380740460706,179.99855648033625 60.00053200843791,179.99879144910815 60.000662831579476,179.99907286456278 60.00076818215714,179.99938991174088 60.00084401135155,179.99973040600648 60.00088740488531,-179.9999187385995 60.000896695047814,-179.99957100632759 60.00087152480308,-179.9992397613641 60.0008128615135,-179.99893773409582 60.00072295975184,-179.99867653176275 60.00060527463255,-179.99846619232136 60.00046432899707,-179.99831479867737 60.00030553956281,-179.99822816811277 60.000135008722694,-179.99820962883618 59.99995929000264))"); + Geometry postgis_result4 = geomFromEWKT( "POLYGON((-91.18706814560713 30.45193179814003,-91.1890681473133 30.453431798552806,-91.18908219578012 30.453444627151963,-91.18909308551447 30.453459583698564,-91.18910039802891 30.453476093421752,-91.18910385230598 30.453493521862622,-91.1891033155977 30.453511199256216,-91.18909880852735 30.453528446270074,-91.18909050429724 30.453544600110646,-91.18907872203292 30.453559039994175,-91.18906391451956 30.453571211003144,-91.18904665080186 30.453580645411602,-91.18902759431575 30.453586980659722,-91.189007477393 30.45358997328696,-91.1889870731177 30.453589508288072,-91.18896716561683 30.45358560353286,-91.18894851992636 30.453578409079352,-91.18893185259108 30.453568201407066,-91.18693185325601 30.45206820103894,-91.1849318540605 30.450568200775386,-91.18491780618884 30.450555372062745,-91.18490691698447 30.450540415432766,-91.18489960491243 30.45052390566114,-91.18489615096986 30.450506477209665,-91.18489668788781 30.450488799844198,-91.1849011950307 30.45047155289582,-91.18490949918969 30.45045539915463,-91.18492128123923 30.450440959399103,-91.18493608840117 30.45042878854006,-91.18495335164478 30.45041935429591,-91.18497240755428 30.450413019218534,-91.18499252382345 30.450410026760903,-91.18501292739734 30.450410491921236,-91.1850328341802 30.450414396823803,-91.18505147916741 30.450421591405906,-91.1850681458439 30.450431799184482,-91.18706814560713 30.45193179814003))"); @@ -2973,42 +2975,38 @@ public void testBufferSpheroidal() throws ParseException { geomFromEWKT( "POLYGON((-120.08983152841193 29.999999999999993,-120.08983152841193 49.99999999999999,-120.08810544078257 50.011295055230505,-120.082993510474 50.02215353089088,-120.07469218610122 50.032158574496115,-120.06352048290445 50.040926345165026,-120.04990772317234 50.04812066585569,-120.03437703762728 50.0534658262464,-120.01752526180509 50.05675706194147,-119.99999999999999 50.05786832496988,-80 50.05786832496988,-79.98247473819491 50.05675706194147,-79.9656229623727 50.0534658262464,-79.95009227682766 50.04812066585569,-79.93647951709556 50.040926345165026,-79.92530781389875 50.032158574496115,-79.91700648952599 50.02215353089088,-79.91189455921743 50.011295055230505,-79.91016847158805 49.99999999999999,-79.91016847158805 29.999999999999993,-79.91189455921743 29.984744778414523,-79.91700648952599 29.970073573593833,-79.92530781389875 29.956550575941442,-79.93647951709556 29.944696041122494,-79.95009227682766 29.934966209462644,-79.9656229623727 29.927735669850765,-79.98247473819491 29.923282861557286,-80 29.921779286758486,-119.99999999999999 29.921779286758486,-120.01752526180509 29.923282861557286,-120.03437703762728 29.927735669850765,-120.04990772317234 29.934966209462644,-120.06352048290445 29.944696041122494,-120.07469218610122 29.956550575941442,-120.082993510474 29.970073573593833,-120.08810544078257 29.984744778414523,-120.08983152841193 29.999999999999993))"); - assertEquals(Functions.reducePrecision(expected1, 8), Functions.reducePrecision(result1, 8)); assertEquals(4326, Functions.getSRID(result1)); - assertEquals(7.424558176442617E-8, comparePolygons(postgis_result1, result1), FP_TOLERANCE2); - assertEquals(Spheroid.area(postgis_result1), Spheroid.area(result1), FP_TOLERANCE2); + assertEquals(1.0, intersectionOverUnion(expected1, result1), IOU_TOLERANCE); + assertEquals(1.0, intersectionOverUnion(postgis_result1, result1), IOU_TOLERANCE); - assertEquals(Functions.reducePrecision(expected2, 8), Functions.reducePrecision(result2, 8)); assertEquals(4269, Functions.getSRID(result2)); - assertEquals(Spheroid.area(postgis_result2), Spheroid.area(result2), 10); - assertEquals(7.424558176442617E-8, comparePolygons(postgis_result2, result2), FP_TOLERANCE2); + assertEquals(1.0, intersectionOverUnion(expected2, result2), IOU_TOLERANCE); + assertEquals(1.0, intersectionOverUnion(postgis_result2, result2), IOU_TOLERANCE); - assertEquals(Functions.reducePrecision(expected3, 8), Functions.reducePrecision(result3, 8)); + // Note tolerance for error higher for points due to algorithmic differences assertEquals(4269, Functions.getSRID(result3)); - assertEquals(Spheroid.area(postgis_result3), Spheroid.area(result3), FP_TOLERANCE2); - assertEquals(7.424558176442617E-8, comparePolygons(postgis_result3, result3), FP_TOLERANCE2); + assertEquals(1.0, intersectionOverUnion(expected3, result3), 1e-4); + assertEquals(1.0, intersectionOverUnion(postgis_result3, result3), 1e-4); - assertEquals(Functions.reducePrecision(expected4, 8), Functions.reducePrecision(result4, 8)); assertEquals(4326, Functions.getSRID(result4)); - assertEquals(Spheroid.area(postgis_result4), Spheroid.area(result4), FP_TOLERANCE2); - assertEquals(7.424558176442617E-8, comparePolygons(postgis_result4, result4), FP_TOLERANCE2); + assertEquals(1.0, intersectionOverUnion(expected4, result4), IOU_TOLERANCE); + assertEquals(1.0, intersectionOverUnion(postgis_result4, result4), IOU_TOLERANCE); - assertEquals(Functions.reducePrecision(expected5, 8), Functions.reducePrecision(result5, 8)); assertEquals(4269, Functions.getSRID(result5)); - assertEquals(Spheroid.area(postgis_result5), Spheroid.area(result5), 10); - assertEquals(7.424558176442617E-8, comparePolygons(postgis_result5, result5), FP_TOLERANCE2); + assertEquals(1.0, intersectionOverUnion(expected5, result5), IOU_TOLERANCE); + assertEquals(1.0, intersectionOverUnion(postgis_result5, result5), IOU_TOLERANCE); - assertEquals(Functions.reducePrecision(expected6, 8), Functions.reducePrecision(result6, 8)); assertEquals(4326, Functions.getSRID(result6)); + assertEquals(1.0, intersectionOverUnion(expected6, result6), IOU_TOLERANCE); - assertEquals(Functions.reducePrecision(expected7, 8), Functions.reducePrecision(result7, 8)); assertEquals(4326, Functions.getSRID(result6)); + assertEquals(1.0, intersectionOverUnion(expected7, result7), IOU_TOLERANCE); - assertEquals(Functions.reducePrecision(expected8, 8), Functions.reducePrecision(result8, 8)); assertEquals(4326, Functions.getSRID(result6)); + assertEquals(1.0, intersectionOverUnion(expected8, result8), IOU_TOLERANCE); - assertEquals(Functions.reducePrecision(expected9, 8), Functions.reducePrecision(result9, 8)); assertEquals(4326, Functions.getSRID(result6)); + assertEquals(1.0, intersectionOverUnion(expected9, result9), IOU_TOLERANCE); } @Test @@ -3047,20 +3045,6 @@ public void testShiftLongitude() throws ParseException { assertEquals(expected8, Functions.shiftLongitude(geomCollection)); } - private static double comparePolygons(Geometry p1, Geometry p2) { - Coordinate[] coords1 = p1.getCoordinates(); - Coordinate[] coords2 = p2.getCoordinates(); - - double maxDistance = 0.0; - for (int i = 0; i < Math.min(coords1.length, coords2.length); i++) { - Geometry point1 = GEOMETRY_FACTORY.createPoint(coords1[i]); - Geometry point2 = GEOMETRY_FACTORY.createPoint(coords2[i]); - double distance = Spheroid.distance(point1, point2); - maxDistance = Math.max(maxDistance, distance); - } - return maxDistance; - } - @Test public void testBestSRID() throws ParseException { int[][] testCases_special = { @@ -4428,4 +4412,15 @@ public void subdivideInvalidMaxVertices() { assertThrows(IllegalArgumentException.class, () -> Functions.subDivide(lineString, 4)); assertEquals("ST_Subdivide needs 5 or more max vertices", e.getMessage()); } + + /** + * Computes the intersection over union (IoU) between two geometries. - Algorithm: + * area(intersection(a,b)) / area(b) - 1.0 indicates a perfect match, while 0.0 indicates no + * overlap. + */ + private double intersectionOverUnion(Geometry expected, Geometry actual) { + double intersectionArea = expected.intersection(actual).getArea(); + double actualArea = actual.getArea(); + return intersectionArea / actualArea; + } } diff --git a/common/src/test/java/org/apache/sedona/common/raster/FunctionEditorsTest.java b/common/src/test/java/org/apache/sedona/common/raster/FunctionEditorsTest.java index 93aa474588a..679c4c29206 100644 --- a/common/src/test/java/org/apache/sedona/common/raster/FunctionEditorsTest.java +++ b/common/src/test/java/org/apache/sedona/common/raster/FunctionEditorsTest.java @@ -22,12 +22,12 @@ import java.io.IOException; import org.apache.sedona.common.Constructors; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.operation.TransformException; import org.geotools.coverage.grid.GridCoverage2D; import org.junit.Test; import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.io.ParseException; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.operation.TransformException; public class FunctionEditorsTest extends RasterTestBase { diff --git a/common/src/test/java/org/apache/sedona/common/raster/FunctionsTest.java b/common/src/test/java/org/apache/sedona/common/raster/FunctionsTest.java index cd8f54621ec..dca3f149487 100644 --- a/common/src/test/java/org/apache/sedona/common/raster/FunctionsTest.java +++ b/common/src/test/java/org/apache/sedona/common/raster/FunctionsTest.java @@ -27,6 +27,8 @@ import org.apache.sedona.common.Constructors; import org.apache.sedona.common.Functions; import org.apache.sedona.common.utils.RasterUtils; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.operation.TransformException; import org.geotools.coverage.grid.GridCoverage2D; import org.geotools.referencing.operation.transform.AffineTransform2D; import org.junit.Assert; @@ -36,8 +38,6 @@ import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.Point; import org.locationtech.jts.io.ParseException; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.operation.TransformException; public class FunctionsTest extends RasterTestBase { @@ -88,10 +88,8 @@ public void valueImplicitTransform() GridCoverage2D raster = rasterFromGeoTiff(resourceFolder + "raster_geotiff_color/FAA_UTM18N_NAD83.tif"); - Geometry point = Constructors.geomFromWKT("POINT (-100 100)", 0); - assertNull( - "Points outside of the envelope should return null.", - PixelFunctions.value(raster, point, 1)); + Geometry point = Constructors.geomFromWKT("POINT (-90 50)", 0); + assertNull(PixelFunctions.value(raster, point, 1)); point = Constructors.geomFromWKT("POINT (-77.9146 37.8916)", 0); Double value = PixelFunctions.value(raster, point, 1); diff --git a/common/src/test/java/org/apache/sedona/common/raster/GeometryFunctionsTest.java b/common/src/test/java/org/apache/sedona/common/raster/GeometryFunctionsTest.java index 7b3dbb48348..a609cd5ddc1 100644 --- a/common/src/test/java/org/apache/sedona/common/raster/GeometryFunctionsTest.java +++ b/common/src/test/java/org/apache/sedona/common/raster/GeometryFunctionsTest.java @@ -23,13 +23,13 @@ import java.io.IOException; import org.apache.sedona.common.Functions; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.operation.TransformException; import org.geotools.coverage.grid.GridCoverage2D; import org.junit.Test; import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.Envelope; import org.locationtech.jts.geom.Geometry; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.operation.TransformException; public class GeometryFunctionsTest extends RasterTestBase { diff --git a/common/src/test/java/org/apache/sedona/common/raster/MapAlgebraTest.java b/common/src/test/java/org/apache/sedona/common/raster/MapAlgebraTest.java index 3caa4ede65d..3ae9111bc84 100644 --- a/common/src/test/java/org/apache/sedona/common/raster/MapAlgebraTest.java +++ b/common/src/test/java/org/apache/sedona/common/raster/MapAlgebraTest.java @@ -23,10 +23,10 @@ import java.awt.image.DataBuffer; import java.util.Random; import org.apache.sedona.common.utils.RasterUtils; +import org.geotools.api.referencing.FactoryException; import org.geotools.coverage.grid.GridCoverage2D; import org.junit.Assert; import org.junit.Test; -import org.opengis.referencing.FactoryException; public class MapAlgebraTest extends RasterTestBase { @Test diff --git a/common/src/test/java/org/apache/sedona/common/raster/RasterAccessorsTest.java b/common/src/test/java/org/apache/sedona/common/raster/RasterAccessorsTest.java index f1a256d2c42..347309cf004 100644 --- a/common/src/test/java/org/apache/sedona/common/raster/RasterAccessorsTest.java +++ b/common/src/test/java/org/apache/sedona/common/raster/RasterAccessorsTest.java @@ -21,14 +21,14 @@ import static org.junit.Assert.*; import java.io.IOException; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.operation.TransformException; import org.geotools.coverage.grid.GridCoordinates2D; import org.geotools.coverage.grid.GridCoverage2D; import org.geotools.geometry.jts.JTS; import org.geotools.referencing.CRS; import org.junit.Test; import org.locationtech.jts.geom.*; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.operation.TransformException; public class RasterAccessorsTest extends RasterTestBase { @Test diff --git a/common/src/test/java/org/apache/sedona/common/raster/RasterBandAccessorsTest.java b/common/src/test/java/org/apache/sedona/common/raster/RasterBandAccessorsTest.java index e0efb21897f..54613223ddd 100644 --- a/common/src/test/java/org/apache/sedona/common/raster/RasterBandAccessorsTest.java +++ b/common/src/test/java/org/apache/sedona/common/raster/RasterBandAccessorsTest.java @@ -23,11 +23,11 @@ import java.io.IOException; import java.util.Arrays; import org.apache.sedona.common.Constructors; +import org.geotools.api.referencing.FactoryException; import org.geotools.coverage.grid.GridCoverage2D; import org.junit.Test; import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.io.ParseException; -import org.opengis.referencing.FactoryException; public class RasterBandAccessorsTest extends RasterTestBase { diff --git a/common/src/test/java/org/apache/sedona/common/raster/RasterBandEditorsTest.java b/common/src/test/java/org/apache/sedona/common/raster/RasterBandEditorsTest.java index 45de7c7e305..c46dd601b00 100644 --- a/common/src/test/java/org/apache/sedona/common/raster/RasterBandEditorsTest.java +++ b/common/src/test/java/org/apache/sedona/common/raster/RasterBandEditorsTest.java @@ -31,13 +31,13 @@ import java.util.stream.Collectors; import org.apache.sedona.common.Constructors; import org.apache.sedona.common.raster.serde.Serde; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.operation.TransformException; import org.geotools.coverage.grid.GridCoverage2D; import org.geotools.coverage.processing.CannotCropException; import org.junit.Test; import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.io.ParseException; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.operation.TransformException; public class RasterBandEditorsTest extends RasterTestBase { diff --git a/common/src/test/java/org/apache/sedona/common/raster/RasterConstructorsTest.java b/common/src/test/java/org/apache/sedona/common/raster/RasterConstructorsTest.java index e5b7c2d2bf5..bff8261d48a 100644 --- a/common/src/test/java/org/apache/sedona/common/raster/RasterConstructorsTest.java +++ b/common/src/test/java/org/apache/sedona/common/raster/RasterConstructorsTest.java @@ -32,16 +32,16 @@ import org.apache.commons.lang3.tuple.Pair; import org.apache.sedona.common.Constructors; import org.apache.sedona.common.utils.RasterUtils; +import org.geotools.api.coverage.SampleDimensionType; +import org.geotools.api.geometry.Position; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.operation.TransformException; import org.geotools.coverage.grid.GridCoordinates2D; import org.geotools.coverage.grid.GridCoverage2D; import org.junit.Assert; import org.junit.Test; import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.io.ParseException; -import org.opengis.coverage.SampleDimensionType; -import org.opengis.geometry.DirectPosition; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.operation.TransformException; public class RasterConstructorsTest extends RasterTestBase { @@ -324,10 +324,10 @@ public void testAsRasterWithRasterExtent2() throws FactoryException, ParseExcept Constructors.geomFromWKT("POLYGON((0.1 0.1, 0.1 0.4, 0.4 0.4, 0.4 0.1, 0.1 0.1))", 0); GridCoverage2D rasterized = RasterConstructors.asRasterWithRasterExtent(geom, raster, "d", false, 100d, 0d); - assertEquals(0, rasterized.getEnvelope2D().x, 1e-6); - assertEquals(0, rasterized.getEnvelope2D().y, 1e-6); - assertEquals(0.5, rasterized.getEnvelope2D().width, 1e-6); - assertEquals(0.5, rasterized.getEnvelope2D().height, 1e-6); + assertEquals(0, rasterized.getEnvelope2D().getMinX(), 1e-6); + assertEquals(0, rasterized.getEnvelope2D().getMinY(), 1e-6); + assertEquals(0.5, rasterized.getEnvelope2D().getWidth(), 1e-6); + assertEquals(0.5, rasterized.getEnvelope2D().getHeight(), 1e-6); assertEquals(5, RasterAccessors.getWidth(rasterized)); assertEquals(5, RasterAccessors.getHeight(rasterized)); double sum = Arrays.stream(MapAlgebra.bandAsArray(rasterized, 1)).sum(); @@ -624,10 +624,8 @@ private void assertTilesSameWithGridCoverage( // corresponding // pixel in the grid coverage try { - DirectPosition actualWorldCoord = - tileRaster.getGridGeometry().gridToWorld(tileGridCoord); - DirectPosition expectedWorldCoord = - gridCoverage2D.getGridGeometry().gridToWorld(gridCoord); + Position actualWorldCoord = tileRaster.getGridGeometry().gridToWorld(tileGridCoord); + Position expectedWorldCoord = gridCoverage2D.getGridGeometry().gridToWorld(gridCoord); Assert.assertEquals(expectedWorldCoord, actualWorldCoord); } catch (TransformException e) { throw new RuntimeException(e); diff --git a/common/src/test/java/org/apache/sedona/common/raster/RasterEditorsTest.java b/common/src/test/java/org/apache/sedona/common/raster/RasterEditorsTest.java index 809052d3f27..8022ed734ca 100644 --- a/common/src/test/java/org/apache/sedona/common/raster/RasterEditorsTest.java +++ b/common/src/test/java/org/apache/sedona/common/raster/RasterEditorsTest.java @@ -25,20 +25,20 @@ import java.io.IOException; import java.util.Arrays; import org.apache.sedona.common.utils.RasterUtils; +import org.geotools.api.geometry.Bounds; +import org.geotools.api.geometry.Position; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.crs.CoordinateReferenceSystem; +import org.geotools.api.referencing.operation.MathTransform; +import org.geotools.api.referencing.operation.TransformException; import org.geotools.coverage.grid.GridCoordinates2D; import org.geotools.coverage.grid.GridCoverage2D; import org.geotools.coverage.grid.GridEnvelope2D; -import org.geotools.geometry.DirectPosition2D; +import org.geotools.geometry.Position2D; import org.geotools.referencing.CRS; import org.geotools.referencing.operation.transform.AffineTransform2D; import org.junit.Assert; import org.junit.Test; -import org.opengis.geometry.DirectPosition; -import org.opengis.geometry.Envelope; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.crs.CoordinateReferenceSystem; -import org.opengis.referencing.operation.MathTransform; -import org.opengis.referencing.operation.TransformException; public class RasterEditorsTest extends RasterTestBase { @@ -4140,9 +4140,9 @@ private void verifyReprojectMatchResult( GridCoverage2D source, GridCoverage2D target, GridCoverage2D transformed) throws TransformException, FactoryException { // Check the envelope and CRS - Envelope expectedEnvelope = target.getEnvelope(); - Envelope actualEnvelope = transformed.getEnvelope(); - assertSameEnvelope(expectedEnvelope, actualEnvelope, 1e-6); + Bounds expectedEnvelope = target.getEnvelope(); + Bounds actualEnvelope = transformed.getEnvelope(); + assertSameBounds(expectedEnvelope, actualEnvelope, 1e-6); CoordinateReferenceSystem expectedCrs = target.getCoordinateReferenceSystem(); CoordinateReferenceSystem actualCrs = transformed.getCoordinateReferenceSystem(); Assert.assertTrue(CRS.equalsIgnoreMetadata(expectedCrs, actualCrs)); @@ -4170,11 +4170,11 @@ private void verifyReprojectMatchResult( for (double worldY = ipY; worldY > expectedEnvelope.getMinimum(1); worldY += scaleY) { for (double worldX = ipX; worldX < expectedEnvelope.getMaximum(0); worldX += scaleX) { // Fetch the pixel values from the transformed raster - DirectPosition worldPos = new DirectPosition2D(worldX, worldY); + Position worldPos = new Position2D(worldX, worldY); transformed.evaluate(worldPos, values); // Find the corresponding grid coordinates on the source raster - DirectPosition srcWorldPos = crsTrans.transform(worldPos, null); + Position srcWorldPos = crsTrans.transform(worldPos, null); GridCoordinates2D sourceGridPos = source.getGridGeometry().worldToGrid(srcWorldPos); GridEnvelope2D sourceGridRange = source.getGridGeometry().getGridRange2D(); diff --git a/common/src/test/java/org/apache/sedona/common/raster/RasterOutputTest.java b/common/src/test/java/org/apache/sedona/common/raster/RasterOutputTest.java index dcc2a28dd79..846414ab1b8 100644 --- a/common/src/test/java/org/apache/sedona/common/raster/RasterOutputTest.java +++ b/common/src/test/java/org/apache/sedona/common/raster/RasterOutputTest.java @@ -23,9 +23,9 @@ import java.io.File; import java.io.IOException; import java.net.URLConnection; +import org.geotools.api.referencing.FactoryException; import org.geotools.coverage.grid.GridCoverage2D; import org.junit.Test; -import org.opengis.referencing.FactoryException; public class RasterOutputTest extends RasterTestBase { diff --git a/common/src/test/java/org/apache/sedona/common/raster/RasterPredicatesTest.java b/common/src/test/java/org/apache/sedona/common/raster/RasterPredicatesTest.java index ee243d71242..0b1f79ca7cf 100644 --- a/common/src/test/java/org/apache/sedona/common/raster/RasterPredicatesTest.java +++ b/common/src/test/java/org/apache/sedona/common/raster/RasterPredicatesTest.java @@ -20,6 +20,10 @@ import java.awt.image.DataBuffer; import java.io.IOException; +import org.geotools.api.geometry.BoundingBox; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.crs.CoordinateReferenceSystem; +import org.geotools.api.referencing.operation.TransformException; import org.geotools.coverage.grid.GridCoverage2D; import org.geotools.geometry.jts.JTS; import org.geotools.referencing.CRS; @@ -32,10 +36,6 @@ import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.PrecisionModel; import org.locationtech.jts.io.ParseException; -import org.opengis.geometry.BoundingBox; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.crs.CoordinateReferenceSystem; -import org.opengis.referencing.operation.TransformException; public class RasterPredicatesTest extends RasterTestBase { private static final GeometryFactory GEOMETRY_FACTORY = new GeometryFactory(); diff --git a/common/src/test/java/org/apache/sedona/common/raster/RasterTestBase.java b/common/src/test/java/org/apache/sedona/common/raster/RasterTestBase.java index 3bbcd50d64e..fb8d9eaf22e 100644 --- a/common/src/test/java/org/apache/sedona/common/raster/RasterTestBase.java +++ b/common/src/test/java/org/apache/sedona/common/raster/RasterTestBase.java @@ -27,24 +27,23 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import javax.media.jai.RasterFactory; +import org.geotools.api.geometry.Bounds; +import org.geotools.api.geometry.Position; +import org.geotools.api.parameter.GeneralParameterValue; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.crs.CoordinateReferenceSystem; +import org.geotools.api.referencing.operation.TransformException; import org.geotools.coverage.grid.GridCoordinates2D; import org.geotools.coverage.grid.GridCoverage2D; import org.geotools.coverage.grid.GridCoverageFactory; import org.geotools.gce.geotiff.GeoTiffReader; import org.geotools.gce.geotiff.GeoTiffWriter; -import org.geotools.geometry.DirectPosition2D; -import org.geotools.geometry.Envelope2D; +import org.geotools.geometry.Position2D; import org.geotools.geometry.jts.ReferencedEnvelope; import org.geotools.referencing.CRS; import org.geotools.referencing.crs.DefaultGeographicCRS; import org.junit.Assert; import org.junit.Before; -import org.opengis.geometry.DirectPosition; -import org.opengis.geometry.Envelope; -import org.opengis.parameter.GeneralParameterValue; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.crs.CoordinateReferenceSystem; -import org.opengis.referencing.operation.TransformException; public class RasterTestBase { String arc = @@ -128,7 +127,8 @@ GridCoverage2D createMultibandRaster() throws IOException { image.setRGB(i, j, new Color(color, color, color).getRGB()); } } - return factory.create("test", image, new Envelope2D(DefaultGeographicCRS.WGS84, 0, 0, 10, 10)); + return factory.create( + "test", image, ReferencedEnvelope.rect(0, 0, 10, 10, DefaultGeographicCRS.WGS84)); } protected void assertSameCoverage(GridCoverage2D expected, GridCoverage2D actual) { @@ -137,16 +137,16 @@ protected void assertSameCoverage(GridCoverage2D expected, GridCoverage2D actual protected void assertSameCoverage(GridCoverage2D expected, GridCoverage2D actual, int density) { Assert.assertEquals(expected.getNumSampleDimensions(), actual.getNumSampleDimensions()); - Envelope expectedEnvelope = expected.getEnvelope(); - Envelope actualEnvelope = actual.getEnvelope(); - assertSameEnvelope(expectedEnvelope, actualEnvelope, 1e-6); + Bounds expectedEnvelope = expected.getEnvelope(); + Bounds actualEnvelope = actual.getEnvelope(); + assertSameBounds(expectedEnvelope, actualEnvelope, 1e-6); CoordinateReferenceSystem expectedCrs = expected.getCoordinateReferenceSystem(); CoordinateReferenceSystem actualCrs = actual.getCoordinateReferenceSystem(); Assert.assertTrue(CRS.equalsIgnoreMetadata(expectedCrs, actualCrs)); assertSameValues(expected, actual, density); } - protected void assertSameEnvelope(Envelope expected, Envelope actual, double epsilon) { + protected void assertSameBounds(Bounds expected, Bounds actual, double epsilon) { Assert.assertEquals(expected.getMinimum(0), actual.getMinimum(0), epsilon); Assert.assertEquals(expected.getMinimum(1), actual.getMinimum(1), epsilon); Assert.assertEquals(expected.getMaximum(0), actual.getMaximum(0), epsilon); @@ -154,7 +154,7 @@ protected void assertSameEnvelope(Envelope expected, Envelope actual, double eps } protected void assertSameValues(GridCoverage2D expected, GridCoverage2D actual, int density) { - Envelope expectedEnvelope = expected.getEnvelope(); + Bounds expectedEnvelope = expected.getEnvelope(); double x0 = expectedEnvelope.getMinimum(0); double y0 = expectedEnvelope.getMinimum(1); double xStep = (expectedEnvelope.getMaximum(0) - x0) / density; @@ -166,7 +166,7 @@ protected void assertSameValues(GridCoverage2D expected, GridCoverage2D actual, for (int j = 0; j < density; j++) { double x = x0 + j * xStep; double y = y0 + i * yStep; - DirectPosition position = new DirectPosition2D(x, y); + Position position = new Position2D(x, y); try { GridCoordinates2D gridPosition = expected.getGridGeometry().worldToGrid(position); if (Double.isNaN(gridPosition.getX()) || Double.isNaN(gridPosition.getY())) { diff --git a/common/src/test/java/org/apache/sedona/common/raster/serde/CRSSerializerTest.java b/common/src/test/java/org/apache/sedona/common/raster/serde/CRSSerializerTest.java index 469be91b146..abed63aafba 100644 --- a/common/src/test/java/org/apache/sedona/common/raster/serde/CRSSerializerTest.java +++ b/common/src/test/java/org/apache/sedona/common/raster/serde/CRSSerializerTest.java @@ -18,11 +18,11 @@ */ package org.apache.sedona.common.raster.serde; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.crs.CoordinateReferenceSystem; import org.geotools.referencing.CRS; import org.junit.Assert; import org.junit.Test; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.crs.CoordinateReferenceSystem; public class CRSSerializerTest { @Test diff --git a/common/src/test/java/org/apache/sedona/common/raster/serde/SerdeTest.java b/common/src/test/java/org/apache/sedona/common/raster/serde/SerdeTest.java index 63975d9e8ae..fc734105a7b 100644 --- a/common/src/test/java/org/apache/sedona/common/raster/serde/SerdeTest.java +++ b/common/src/test/java/org/apache/sedona/common/raster/serde/SerdeTest.java @@ -24,10 +24,10 @@ import java.io.IOException; import org.apache.sedona.common.raster.RasterConstructors; import org.apache.sedona.common.raster.RasterTestBase; +import org.geotools.api.referencing.FactoryException; import org.geotools.coverage.grid.GridCoverage2D; import org.geotools.gce.geotiff.GeoTiffReader; import org.junit.Test; -import org.opengis.referencing.FactoryException; public class SerdeTest extends RasterTestBase { diff --git a/examples/flink-sql/pom.xml b/examples/flink-sql/pom.xml index 6c7c2121c9a..452ea972c8c 100644 --- a/examples/flink-sql/pom.xml +++ b/examples/flink-sql/pom.xml @@ -33,7 +33,7 @@ 1.19.0 compile 2.12 - 28.2 + 33.1 2.17.2 diff --git a/flink/src/main/java/org/apache/sedona/flink/expressions/Functions.java b/flink/src/main/java/org/apache/sedona/flink/expressions/Functions.java index af90fabbe68..7a4fe38853f 100644 --- a/flink/src/main/java/org/apache/sedona/flink/expressions/Functions.java +++ b/flink/src/main/java/org/apache/sedona/flink/expressions/Functions.java @@ -24,10 +24,10 @@ import org.apache.flink.table.annotation.InputGroup; import org.apache.flink.table.functions.ScalarFunction; import org.apache.sedona.common.FunctionsGeoTools; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.operation.TransformException; import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.operation.buffer.BufferParameters; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.operation.TransformException; public class Functions { public static class GeometryType extends ScalarFunction { diff --git a/flink/src/main/java/org/apache/sedona/flink/expressions/FunctionsGeoTools.java b/flink/src/main/java/org/apache/sedona/flink/expressions/FunctionsGeoTools.java index f93053f7e0e..1085bc6656f 100644 --- a/flink/src/main/java/org/apache/sedona/flink/expressions/FunctionsGeoTools.java +++ b/flink/src/main/java/org/apache/sedona/flink/expressions/FunctionsGeoTools.java @@ -20,9 +20,9 @@ import org.apache.flink.table.annotation.DataTypeHint; import org.apache.flink.table.functions.ScalarFunction; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.operation.TransformException; import org.locationtech.jts.geom.Geometry; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.operation.TransformException; public class FunctionsGeoTools { public static class ST_Transform extends ScalarFunction { diff --git a/flink/src/test/java/org/apache/sedona/flink/FunctionTest.java b/flink/src/test/java/org/apache/sedona/flink/FunctionTest.java index b85a9f0ae5e..0c9cae9920d 100644 --- a/flink/src/test/java/org/apache/sedona/flink/FunctionTest.java +++ b/flink/src/test/java/org/apache/sedona/flink/FunctionTest.java @@ -31,6 +31,8 @@ import org.apache.flink.table.api.Table; import org.apache.sedona.flink.expressions.Functions; import org.apache.sedona.flink.expressions.FunctionsGeoTools; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.crs.CoordinateReferenceSystem; import org.geotools.referencing.CRS; import org.junit.Assert; import org.junit.BeforeClass; @@ -38,8 +40,6 @@ import org.locationtech.jts.geom.*; import org.locationtech.jts.io.ParseException; import org.locationtech.jts.operation.buffer.BufferParameters; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.crs.CoordinateReferenceSystem; public class FunctionTest extends TestBase { diff --git a/pom.xml b/pom.xml index ffe64586fab..1b7ab17cce9 100644 --- a/pom.xml +++ b/pom.xml @@ -68,7 +68,7 @@ 3.10.1 5.4.2 - 28.5 + 33.1 3.2.4 2.13.4 1.20.0 diff --git a/snowflake/src/main/java/org/apache/sedona/snowflake/snowsql/GeoToolsWrapper.java b/snowflake/src/main/java/org/apache/sedona/snowflake/snowsql/GeoToolsWrapper.java index 94388bf90b0..fbb7963b612 100644 --- a/snowflake/src/main/java/org/apache/sedona/snowflake/snowsql/GeoToolsWrapper.java +++ b/snowflake/src/main/java/org/apache/sedona/snowflake/snowsql/GeoToolsWrapper.java @@ -19,9 +19,9 @@ package org.apache.sedona.snowflake.snowsql; import org.apache.sedona.common.FunctionsGeoTools; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.operation.TransformException; import org.locationtech.jts.geom.Geometry; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.operation.TransformException; public class GeoToolsWrapper { public static Geometry transform( diff --git a/spark/common/src/main/java/org/apache/sedona/core/spatialOperator/KNNQuery.java b/spark/common/src/main/java/org/apache/sedona/core/spatialOperator/KNNQuery.java index c23d049f159..5b4e0d248ad 100644 --- a/spark/common/src/main/java/org/apache/sedona/core/spatialOperator/KNNQuery.java +++ b/spark/common/src/main/java/org/apache/sedona/core/spatialOperator/KNNQuery.java @@ -26,9 +26,9 @@ import org.apache.sedona.core.knnJudgement.KnnJudgementUsingIndex; import org.apache.sedona.core.spatialRDD.SpatialRDD; import org.apache.spark.api.java.JavaRDD; +import org.geotools.api.referencing.FactoryException; +import org.geotools.api.referencing.operation.TransformException; import org.locationtech.jts.geom.Geometry; -import org.opengis.referencing.FactoryException; -import org.opengis.referencing.operation.TransformException; // TODO: Auto-generated Javadoc diff --git a/spark/common/src/main/scala/org/apache/sedona/sql/datasources/geopackage/model/TileMetadata.scala b/spark/common/src/main/scala/org/apache/sedona/sql/datasources/geopackage/model/TileMetadata.scala index 278f513cd1f..88fdd3ca2fb 100644 --- a/spark/common/src/main/scala/org/apache/sedona/sql/datasources/geopackage/model/TileMetadata.scala +++ b/spark/common/src/main/scala/org/apache/sedona/sql/datasources/geopackage/model/TileMetadata.scala @@ -19,7 +19,7 @@ package org.apache.sedona.sql.datasources.geopackage.model import org.geotools.referencing.CRS -import org.opengis.referencing.crs.CoordinateReferenceSystem +import org.geotools.api.referencing.crs.CoordinateReferenceSystem import scala.collection.mutable diff --git a/spark/common/src/main/scala/org/apache/sedona/sql/datasources/geopackage/transform/Image.scala b/spark/common/src/main/scala/org/apache/sedona/sql/datasources/geopackage/transform/Image.scala index 40daf0d4601..0ee662ad097 100644 --- a/spark/common/src/main/scala/org/apache/sedona/sql/datasources/geopackage/transform/Image.scala +++ b/spark/common/src/main/scala/org/apache/sedona/sql/datasources/geopackage/transform/Image.scala @@ -22,8 +22,7 @@ import org.apache.sedona.sql.datasources.geopackage.model.ImageFileFormat.ImageF import org.apache.sedona.sql.datasources.geopackage.model.{ImageFileFormat, TileMetadata, TileRowMetadata} import org.geotools.coverage.grid.{GridCoverage2D, GridCoverageFactory} import org.geotools.gce.geotiff.GeoTiffReader -import org.geotools.geometry.GeneralEnvelope - +import org.geotools.geometry.GeneralBounds import java.awt.image.BufferedImage import java.io.ByteArrayInputStream import javax.imageio.ImageIO @@ -92,14 +91,13 @@ object Image { tileRowMetadata: TileRowMetadata): GridCoverage2D = { val envelope = tileMetadata.getEnvelope(tileRowMetadata) - val genevelope = new GeneralEnvelope( - Array(envelope.minX, envelope.minY), - Array(envelope.maxX, envelope.maxY)) + val genEnvelope = + new GeneralBounds(Array(envelope.minX, envelope.minY), Array(envelope.maxX, envelope.maxY)) - genevelope.setCoordinateReferenceSystem(tileMetadata.getSRID()) val coverageFactory = new GridCoverageFactory() - coverageFactory.create("coverage", image, genevelope) + genEnvelope.setCoordinateReferenceSystem(tileMetadata.getSRID()) + coverageFactory.create("coverage", image, genEnvelope) } def readImageFromBinary(imageBinary: Array[Byte]): BufferedImage = { diff --git a/spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/strategy/join/JoinedGeometryRaster.scala b/spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/strategy/join/JoinedGeometryRaster.scala index bc9570fcb03..dd98888b277 100644 --- a/spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/strategy/join/JoinedGeometryRaster.scala +++ b/spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/strategy/join/JoinedGeometryRaster.scala @@ -20,14 +20,13 @@ package org.apache.spark.sql.sedona_sql.strategy.join import org.apache.sedona.common.FunctionsGeoTools import org.apache.sedona.common.utils.{CachedCRSTransformFinder, GeomUtils} +import org.geotools.api.geometry.BoundingBox +import org.geotools.api.referencing.crs.{CoordinateReferenceSystem, GeographicCRS} import org.geotools.coverage.grid.GridCoverage2D -import org.geotools.geometry.Envelope2D -import org.geotools.geometry.jts.JTS +import org.geotools.geometry.jts.{JTS, ReferencedEnvelope} import org.geotools.referencing.CRS import org.geotools.referencing.crs.{DefaultEngineeringCRS, DefaultGeographicCRS} import org.locationtech.jts.geom.{Envelope, Geometry} -import org.opengis.geometry.BoundingBox -import org.opengis.referencing.crs.{CoordinateReferenceSystem, GeographicCRS} object JoinedGeometryRaster { @@ -63,14 +62,15 @@ object JoinedGeometryRaster { geom } else { val env = geom.getEnvelopeInternal - val envelope = new Envelope2D(null, env.getMinX, env.getMinY, env.getWidth, env.getHeight) val crs = FunctionsGeoTools.sridToCRS(srid) + val envelope = + new ReferencedEnvelope(env.getMinX, env.getMaxX, env.getMinY, env.getMaxY, null) transformToWGS84Envelope(envelope, crs) } } private def transformToWGS84Envelope( - envelope: org.opengis.geometry.Envelope, + envelope: ReferencedEnvelope, crs: CoordinateReferenceSystem): Geometry = { // We use CRS.transform for envelopes to transform envelopes between different CRSs. This transformation function // could handle envelope crossing the anti-meridian and envelope near or covering poles correctly. We won't have diff --git a/spark/common/src/test/java/org/apache/sedona/core/formatMapper/shapefileParser/shapes/ShapefileRDDTest.java b/spark/common/src/test/java/org/apache/sedona/core/formatMapper/shapefileParser/shapes/ShapefileRDDTest.java index 05ac0b1252f..16a85fc2f1e 100644 --- a/spark/common/src/test/java/org/apache/sedona/core/formatMapper/shapefileParser/shapes/ShapefileRDDTest.java +++ b/spark/common/src/test/java/org/apache/sedona/core/formatMapper/shapefileParser/shapes/ShapefileRDDTest.java @@ -36,9 +36,12 @@ import org.apache.sedona.core.spatialRDD.PolygonRDD; import org.apache.spark.SparkConf; import org.apache.spark.api.java.JavaSparkContext; -import org.geotools.data.DataStore; -import org.geotools.data.DataStoreFinder; -import org.geotools.data.FeatureSource; +import org.geotools.api.data.DataStore; +import org.geotools.api.data.DataStoreFinder; +import org.geotools.api.data.FeatureSource; +import org.geotools.api.feature.simple.SimpleFeature; +import org.geotools.api.feature.simple.SimpleFeatureType; +import org.geotools.api.filter.Filter; import org.geotools.data.shapefile.files.ShpFiles; import org.geotools.data.shapefile.shp.ShapefileReader; import org.geotools.feature.FeatureCollection; @@ -51,9 +54,6 @@ import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.MultiPolygon; -import org.opengis.feature.simple.SimpleFeature; -import org.opengis.feature.simple.SimpleFeatureType; -import org.opengis.filter.Filter; public class ShapefileRDDTest implements Serializable { diff --git a/spark/common/src/test/java/org/apache/sedona/core/formatMapper/shapefileParser/shapes/ShapefileReaderTest.java b/spark/common/src/test/java/org/apache/sedona/core/formatMapper/shapefileParser/shapes/ShapefileReaderTest.java index 4a7654aa2da..0e721084d55 100644 --- a/spark/common/src/test/java/org/apache/sedona/core/formatMapper/shapefileParser/shapes/ShapefileReaderTest.java +++ b/spark/common/src/test/java/org/apache/sedona/core/formatMapper/shapefileParser/shapes/ShapefileReaderTest.java @@ -47,9 +47,13 @@ import org.apache.sedona.core.spatialRDD.PolygonRDD; import org.apache.sedona.core.spatialRDD.SpatialRDD; import org.apache.spark.SparkException; -import org.geotools.data.DataStore; -import org.geotools.data.DataStoreFinder; -import org.geotools.data.FeatureSource; +import org.geotools.api.data.DataStore; +import org.geotools.api.data.DataStoreFinder; +import org.geotools.api.data.FeatureSource; +import org.geotools.api.feature.Property; +import org.geotools.api.feature.simple.SimpleFeature; +import org.geotools.api.feature.simple.SimpleFeatureType; +import org.geotools.api.filter.Filter; import org.geotools.data.shapefile.files.ShpFiles; import org.geotools.feature.FeatureCollection; import org.geotools.feature.FeatureIterator; @@ -60,10 +64,6 @@ import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.MultiPolygon; -import org.opengis.feature.Property; -import org.opengis.feature.simple.SimpleFeature; -import org.opengis.feature.simple.SimpleFeatureType; -import org.opengis.filter.Filter; public class ShapefileReaderTest extends TestBase { diff --git a/spark/common/src/test/scala/org/apache/sedona/sql/functionTestScala.scala b/spark/common/src/test/scala/org/apache/sedona/sql/functionTestScala.scala index 1f6140e991c..303966722da 100644 --- a/spark/common/src/test/scala/org/apache/sedona/sql/functionTestScala.scala +++ b/spark/common/src/test/scala/org/apache/sedona/sql/functionTestScala.scala @@ -31,7 +31,7 @@ import org.locationtech.jts.geom.{Coordinate, Geometry, GeometryFactory, Polygon import org.locationtech.jts.io.WKTWriter import org.locationtech.jts.linearref.LengthIndexedLine import org.locationtech.jts.operation.distance3d.Distance3DOp -import org.opengis.referencing.FactoryException +import org.geotools.api.referencing.FactoryException import org.scalatest.{GivenWhenThen, Matchers} import org.xml.sax.InputSource @@ -449,7 +449,7 @@ class functionTestScala val EPSG_TGT_WKT = EPSG_TGT_CRS.toWKT() val epsgFactoryErrorString = EPSG_TGT_WKT.substring(0, EPSG_TGT_WKT.length() - 1) val epsgString = "EPSG:4326" - val epsgNoSuchAuthorityString = "EPSG:9377" + val epsgNoSuchAuthorityString = "EPSG:11111" val polygon = "POLYGON ((110.54671 55.818002, 110.54671 55.143743, 110.940494 55.143743, 110.940494 55.818002, 110.54671 55.818002))" import org.locationtech.jts.io.WKTReader diff --git a/spark/common/src/test/scala/org/apache/sedona/sql/rasteralgebraTest.scala b/spark/common/src/test/scala/org/apache/sedona/sql/rasteralgebraTest.scala index ff5dc7109b2..be0c69a7228 100644 --- a/spark/common/src/test/scala/org/apache/sedona/sql/rasteralgebraTest.scala +++ b/spark/common/src/test/scala/org/apache/sedona/sql/rasteralgebraTest.scala @@ -21,9 +21,9 @@ package org.apache.sedona.sql import org.apache.sedona.common.raster.MapAlgebra import org.apache.sedona.common.utils.RasterUtils import org.apache.spark.sql.expressions.Window -import org.apache.spark.sql.{DataFrame, Row, SaveMode} -import org.apache.spark.sql.functions.{col, collect_list, expr, lit, row_number} +import org.apache.spark.sql.functions._ import org.apache.spark.sql.types.{DoubleType, IntegerType, StructField, StructType} +import org.apache.spark.sql.{DataFrame, Row, SaveMode} import org.geotools.coverage.grid.GridCoverage2D import org.junit.Assert.{assertEquals, assertNotNull, assertNull, assertTrue} import org.locationtech.jts.geom.{Coordinate, Geometry} @@ -1039,7 +1039,7 @@ class rasteralgebraTest extends TestBaseScala with BeforeAndAfter with GivenWhen // Test with a polygon that does not intersect the raster in lenient mode val actual = df .selectExpr( - "RS_Clip(raster, 1, ST_GeomFromWKT('POLYGON((274157 4174899,263510 4174947,269859 4183348,274157 4174899))'))") + "RS_Clip(raster, 1, ST_GeomFromWKT('POLYGON((274157 4174899,263510 4174947,269859 4183348,274157 4174899))', 26918))") .first() .get(0) assertNull(actual) From 4eaeb54ba5e435640ee2305cfb4f256dc690c857 Mon Sep 17 00:00:00 2001 From: jesspav Date: Tue, 3 Jun 2025 13:26:46 -0700 Subject: [PATCH 02/10] update geotools in examples --- .github/workflows/pyflink.yml | 4 ++-- R/tests/testthat/test-data-interface-raster.R | 1 + .../test/java/org/apache/sedona/common/FunctionsTest.java | 5 ++--- examples/spark-sql/pom.xml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pyflink.yml b/.github/workflows/pyflink.yml index d93e4315448..2afc52c40ce 100644 --- a/.github/workflows/pyflink.yml +++ b/.github/workflows/pyflink.yml @@ -71,6 +71,6 @@ jobs: - run: uv add apache-flink==1.20.1 shapely attr setuptools - run: uv add pytest --dev - run: | - wget https://repo1.maven.org/maven2/org/datasyslab/geotools-wrapper/1.7.1-28.5/geotools-wrapper-1.7.1-28.5.jar - export SEDONA_PYFLINK_EXTRA_JARS=${PWD}/$(find flink-shaded/target -name sedona-flink*.jar),${PWD}/geotools-wrapper-1.7.1-28.5.jar + wget https://repo1.maven.org/maven2/org/datasyslab/geotools-wrapper/1.6.0-31.0/geotools-wrapper-1.6.0-31.0.jar + export SEDONA_PYFLINK_EXTRA_JARS=${PWD}/$(find flink-shaded/target -name sedona-flink*.jar),${PWD}/geotools-wrapper-1.6.0-31.0.jar (cd python; PYTHONPATH=$(pwd) uv run pytest -v -s ./tests/flink) diff --git a/R/tests/testthat/test-data-interface-raster.R b/R/tests/testthat/test-data-interface-raster.R index b4c235f85b4..ee8b8b19073 100644 --- a/R/tests/testthat/test-data-interface-raster.R +++ b/R/tests/testthat/test-data-interface-raster.R @@ -192,6 +192,7 @@ test_that("Passed RS_Values with raster", { ) %>% select(val) %>% collect() + print(a) ## FIXME: delete after debugging expect_equal( a %>% as.list(), list(val = list(c(255, NA_real_))) diff --git a/common/src/test/java/org/apache/sedona/common/FunctionsTest.java b/common/src/test/java/org/apache/sedona/common/FunctionsTest.java index 1c682a4e0ce..fedc0d58618 100644 --- a/common/src/test/java/org/apache/sedona/common/FunctionsTest.java +++ b/common/src/test/java/org/apache/sedona/common/FunctionsTest.java @@ -4414,9 +4414,8 @@ public void subdivideInvalidMaxVertices() { } /** - * Computes the intersection over union (IoU) between two geometries. - Algorithm: - * area(intersection(a,b)) / area(b) - 1.0 indicates a perfect match, while 0.0 indicates no - * overlap. + * Computes the intersection over union (IoU) between two geometries. 1.0 indicates a perfect match, + * while 0.0 indicates no overlap. */ private double intersectionOverUnion(Geometry expected, Geometry actual) { double intersectionArea = expected.intersection(actual).getArea(); diff --git a/examples/spark-sql/pom.xml b/examples/spark-sql/pom.xml index b15f209b083..6298d2a4ea6 100644 --- a/examples/spark-sql/pom.xml +++ b/examples/spark-sql/pom.xml @@ -34,7 +34,7 @@ compile compile - 28.2 + ${geotools.version} 1.1.24 3.4.0 3.4 From 62ae90ef3b07e3a8be2f800c77997c10461311c2 Mon Sep 17 00:00:00 2001 From: jesspav Date: Tue, 3 Jun 2025 15:13:30 -0700 Subject: [PATCH 03/10] ran spotless --- .../src/test/java/org/apache/sedona/common/FunctionsTest.java | 4 ++-- examples/spark-sql/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/common/src/test/java/org/apache/sedona/common/FunctionsTest.java b/common/src/test/java/org/apache/sedona/common/FunctionsTest.java index fedc0d58618..65a294ad313 100644 --- a/common/src/test/java/org/apache/sedona/common/FunctionsTest.java +++ b/common/src/test/java/org/apache/sedona/common/FunctionsTest.java @@ -4414,8 +4414,8 @@ public void subdivideInvalidMaxVertices() { } /** - * Computes the intersection over union (IoU) between two geometries. 1.0 indicates a perfect match, - * while 0.0 indicates no overlap. + * Computes the intersection over union (IoU) between two geometries. 1.0 indicates a perfect + * match, while 0.0 indicates no overlap. */ private double intersectionOverUnion(Geometry expected, Geometry actual) { double intersectionArea = expected.intersection(actual).getArea(); diff --git a/examples/spark-sql/pom.xml b/examples/spark-sql/pom.xml index 6298d2a4ea6..0ac5695ac9e 100644 --- a/examples/spark-sql/pom.xml +++ b/examples/spark-sql/pom.xml @@ -34,7 +34,7 @@ compile compile - ${geotools.version} + 33.1 1.1.24 3.4.0 3.4 From 496bb676d10ea34c3bd2f5507e3b1ca3f4d9a36e Mon Sep 17 00:00:00 2001 From: jesspav Date: Tue, 3 Jun 2025 17:23:12 -0700 Subject: [PATCH 04/10] revert changes that are out of the main run --- R/tests/testthat/test-data-interface-raster.R | 7 +++---- examples/flink-sql/pom.xml | 2 +- examples/spark-sql/pom.xml | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/R/tests/testthat/test-data-interface-raster.R b/R/tests/testthat/test-data-interface-raster.R index ee8b8b19073..96275d4a6ae 100644 --- a/R/tests/testthat/test-data-interface-raster.R +++ b/R/tests/testthat/test-data-interface-raster.R @@ -26,7 +26,7 @@ sc <- testthat_spark_connection() test_that("Passed RS_FromGeoTiff from binary", { ## Load sdf_name <- random_string("spatial_sdf") - binary_sdf <- spark_read_binary(sc, dir = test_data("raster"), name = sdf_name) + binary_sdf <- spark_read_binary(sc, dir = test_data("raster/test1.tiff"), name = sdf_name) raster_sdf <- binary_sdf %>% @@ -91,7 +91,7 @@ test_that("Passed RS_FromArcInfoAsciiGrid from binary", { test_that("Passed RS_Envelope with raster", { ## Load sdf_name <- random_string("spatial_sdf") - binary_sdf <- spark_read_binary(sc, dir = test_data("raster"), name = sdf_name) + binary_sdf <- spark_read_binary(sc, dir = test_data("raster/test1.tiff"), name = sdf_name) raster_sdf <- binary_sdf %>% @@ -182,7 +182,7 @@ test_that("Passed RS_Value with raster", { test_that("Passed RS_Values with raster", { ## Load sdf_name <- random_string("spatial_sdf") - binary_sdf <- spark_read_binary(sc, dir = test_data("raster"), name = sdf_name) + binary_sdf <- spark_read_binary(sc, dir = test_data("raster/test1.tiff"), name = sdf_name) a <- binary_sdf %>% @@ -192,7 +192,6 @@ test_that("Passed RS_Values with raster", { ) %>% select(val) %>% collect() - print(a) ## FIXME: delete after debugging expect_equal( a %>% as.list(), list(val = list(c(255, NA_real_))) diff --git a/examples/flink-sql/pom.xml b/examples/flink-sql/pom.xml index 452ea972c8c..6c7c2121c9a 100644 --- a/examples/flink-sql/pom.xml +++ b/examples/flink-sql/pom.xml @@ -33,7 +33,7 @@ 1.19.0 compile 2.12 - 33.1 + 28.2 2.17.2 diff --git a/examples/spark-sql/pom.xml b/examples/spark-sql/pom.xml index 0ac5695ac9e..b15f209b083 100644 --- a/examples/spark-sql/pom.xml +++ b/examples/spark-sql/pom.xml @@ -34,7 +34,7 @@ compile compile - 33.1 + 28.2 1.1.24 3.4.0 3.4 From 33805fdbacf6f0010605e76601b120eb98f28497 Mon Sep 17 00:00:00 2001 From: jesspav <202656197+jesspav@users.noreply.github.com> Date: Wed, 4 Jun 2025 18:57:03 -0700 Subject: [PATCH 05/10] Update workflows to use geotools 33 --- .github/workflows/docker-build.yml | 7 ++----- .github/workflows/example.yml | 3 --- .github/workflows/pyflink.yml | 2 +- examples/spark-sql/pom.xml | 2 +- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 2d083a918f9..07f76d7bb16 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -46,17 +46,14 @@ jobs: fail-fast: true matrix: os: ['ubuntu-latest'] - spark: ['3.5.1', '3.4.3', '3.3.4'] + spark: ['3.5.1', '3.4.3'] include: - spark: 3.5.1 sedona: 'latest' geotools: 'auto' - spark: 3.4.3 sedona: 1.6.0 - geotools: 28.2 - - spark: 3.3.4 - sedona: 1.6.0 - geotools: 28.2 + geotools: 33.1 runs-on: ${{ matrix.os }} defaults: run: diff --git a/.github/workflows/example.yml b/.github/workflows/example.yml index 9b0f8e84a67..733d457cd7e 100644 --- a/.github/workflows/example.yml +++ b/.github/workflows/example.yml @@ -50,9 +50,6 @@ jobs: - spark: 3.4.2 spark-compat: '3.4' sedona: 1.5.1 - - spark: 3.3.4 - spark-compat: '3.0' - sedona: 1.5.1 steps: - uses: actions/checkout@v4 - uses: actions/setup-java@v4 diff --git a/.github/workflows/pyflink.yml b/.github/workflows/pyflink.yml index 2afc52c40ce..6d604895621 100644 --- a/.github/workflows/pyflink.yml +++ b/.github/workflows/pyflink.yml @@ -71,6 +71,6 @@ jobs: - run: uv add apache-flink==1.20.1 shapely attr setuptools - run: uv add pytest --dev - run: | - wget https://repo1.maven.org/maven2/org/datasyslab/geotools-wrapper/1.6.0-31.0/geotools-wrapper-1.6.0-31.0.jar + wget https://repo1.maven.org/maven2/org/datasyslab/geotools-wrapper/1.8.0-33.1-rc1/geotools-wrapper-1.8.0-33.1-rc1.jar export SEDONA_PYFLINK_EXTRA_JARS=${PWD}/$(find flink-shaded/target -name sedona-flink*.jar),${PWD}/geotools-wrapper-1.6.0-31.0.jar (cd python; PYTHONPATH=$(pwd) uv run pytest -v -s ./tests/flink) diff --git a/examples/spark-sql/pom.xml b/examples/spark-sql/pom.xml index b15f209b083..0ac5695ac9e 100644 --- a/examples/spark-sql/pom.xml +++ b/examples/spark-sql/pom.xml @@ -34,7 +34,7 @@ compile compile - 28.2 + 33.1 1.1.24 3.4.0 3.4 From cbc12dd6e51664393feecee7aa52e4d7fa6963e5 Mon Sep 17 00:00:00 2001 From: Jia Yu Date: Wed, 4 Jun 2025 21:48:09 -0700 Subject: [PATCH 06/10] Update .github/workflows/pyflink.yml --- .github/workflows/pyflink.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pyflink.yml b/.github/workflows/pyflink.yml index 6d604895621..572fec4051c 100644 --- a/.github/workflows/pyflink.yml +++ b/.github/workflows/pyflink.yml @@ -72,5 +72,5 @@ jobs: - run: uv add pytest --dev - run: | wget https://repo1.maven.org/maven2/org/datasyslab/geotools-wrapper/1.8.0-33.1-rc1/geotools-wrapper-1.8.0-33.1-rc1.jar - export SEDONA_PYFLINK_EXTRA_JARS=${PWD}/$(find flink-shaded/target -name sedona-flink*.jar),${PWD}/geotools-wrapper-1.6.0-31.0.jar + export SEDONA_PYFLINK_EXTRA_JARS=${PWD}/$(find flink-shaded/target -name sedona-flink*.jar),${PWD}/geotools-wrapper-1.8.0-33.1-rc1.jar (cd python; PYTHONPATH=$(pwd) uv run pytest -v -s ./tests/flink) From 48fc8a5817b048962b4fe13ba5a774e3dc7f6ecc Mon Sep 17 00:00:00 2001 From: Jia Yu Date: Wed, 4 Jun 2025 21:48:22 -0700 Subject: [PATCH 07/10] Update examples/spark-sql/pom.xml --- examples/spark-sql/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/spark-sql/pom.xml b/examples/spark-sql/pom.xml index 0ac5695ac9e..b15f209b083 100644 --- a/examples/spark-sql/pom.xml +++ b/examples/spark-sql/pom.xml @@ -34,7 +34,7 @@ compile compile - 33.1 + 28.2 1.1.24 3.4.0 3.4 From 109cd0f8b9d3e93360f6981e80221338ba53317c Mon Sep 17 00:00:00 2001 From: Jia Yu Date: Wed, 4 Jun 2025 21:50:04 -0700 Subject: [PATCH 08/10] Update .github/workflows/docker-build.yml --- .github/workflows/docker-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 07f76d7bb16..a5beb0e6796 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -53,7 +53,7 @@ jobs: geotools: 'auto' - spark: 3.4.3 sedona: 1.6.0 - geotools: 33.1 + geotools: 28.2 runs-on: ${{ matrix.os }} defaults: run: From 3c9e44cbacec74f9f9d3e37aee454d555627cea5 Mon Sep 17 00:00:00 2001 From: jesspav <202656197+jesspav@users.noreply.github.com> Date: Thu, 5 Jun 2025 06:34:24 -0700 Subject: [PATCH 09/10] update r workflow --- .github/workflows/r.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/r.yml b/.github/workflows/r.yml index 351cd3f7309..55951c4036c 100644 --- a/.github/workflows/r.yml +++ b/.github/workflows/r.yml @@ -56,7 +56,7 @@ jobs: spark: [3.4.0, 3.5.0] hadoop: [3] scala: [2.12.15] - r: [oldrel] + r: [oldrel, release] env: SPARK_VERSION: ${{ matrix.spark }} HADOOP_VERSION: ${{ matrix.hadoop }} From 34902d892b18f742452eaa75e5bda9df3950fe53 Mon Sep 17 00:00:00 2001 From: jesspav <202656197+jesspav@users.noreply.github.com> Date: Thu, 5 Jun 2025 09:55:30 -0700 Subject: [PATCH 10/10] use the specialized 33.1-rc1 for the geotools wrapper workflow --- .github/workflows/docker-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index a5beb0e6796..2fdeabdcc3f 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -50,7 +50,7 @@ jobs: include: - spark: 3.5.1 sedona: 'latest' - geotools: 'auto' + geotools: '33.1-rc1' - spark: 3.4.3 sedona: 1.6.0 geotools: 28.2