From af63c69e94f71d81cb4559bc78d6c92e5233f378 Mon Sep 17 00:00:00 2001 From: Nilesh Gajwani Date: Mon, 7 Aug 2023 21:18:26 -0400 Subject: [PATCH] Move tranform() function to geomUtils to prevent inference confusion --- .../main/java/org/apache/sedona/common/Functions.java | 6 +----- .../org/apache/sedona/common/utils/GeomUtils.java | 11 +++++++++++ .../org/apache/sedona/common/utils/RasterUtils.java | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/org/apache/sedona/common/Functions.java b/common/src/main/java/org/apache/sedona/common/Functions.java index 99c68aecef..71101ffa98 100644 --- a/common/src/main/java/org/apache/sedona/common/Functions.java +++ b/common/src/main/java/org/apache/sedona/common/Functions.java @@ -194,13 +194,9 @@ public static Geometry transform(Geometry geometry, String sourceCRS, String tar throws FactoryException, TransformException { CoordinateReferenceSystem sourceCRSCode = parseCRSString(sourceCRS); CoordinateReferenceSystem targetCRScode = parseCRSString(targetCRS); - return transform(geometry, sourceCRSCode, targetCRScode, lenient); + return GeomUtils.transform(geometry, sourceCRSCode, targetCRScode, lenient); } - public static Geometry transform(Geometry geometry, CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, boolean lenient) throws FactoryException, TransformException { - MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS, lenient); - return JTS.transform(geometry, transform); - } private static CoordinateReferenceSystem parseCRSString(String CRSString) throws FactoryException diff --git a/common/src/main/java/org/apache/sedona/common/utils/GeomUtils.java b/common/src/main/java/org/apache/sedona/common/utils/GeomUtils.java index 0b0b2e8615..05accb5d4b 100644 --- a/common/src/main/java/org/apache/sedona/common/utils/GeomUtils.java +++ b/common/src/main/java/org/apache/sedona/common/utils/GeomUtils.java @@ -13,6 +13,8 @@ */ package org.apache.sedona.common.utils; +import org.geotools.geometry.jts.JTS; +import org.geotools.referencing.CRS; import org.locationtech.jts.geom.*; import org.locationtech.jts.geom.impl.CoordinateArraySequence; import org.locationtech.jts.io.ByteOrderValues; @@ -23,6 +25,10 @@ import org.locationtech.jts.algorithm.Angle; import org.locationtech.jts.algorithm.distance.DiscreteFrechetDistance; import org.locationtech.jts.algorithm.distance.DiscreteHausdorffDistance; +import org.opengis.referencing.FactoryException; +import org.opengis.referencing.crs.CoordinateReferenceSystem; +import org.opengis.referencing.operation.MathTransform; +import org.opengis.referencing.operation.TransformException; import java.nio.ByteOrder; import java.util.*; @@ -242,6 +248,11 @@ public static Geometry buildArea(Geometry geom) { return outputGeom; } + public static Geometry transform(Geometry geometry, CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, boolean lenient) throws FactoryException, TransformException { + MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS, lenient); + return JTS.transform(geometry, transform); + } + public static int getDimension(Geometry geometry) { return geometry.getCoordinate() != null && !java.lang.Double.isNaN(geometry.getCoordinate().getZ()) ? 3 : 2; } 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 dcbec54ca5..cc24f1e792 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 @@ -133,7 +133,7 @@ public static Geometry convertCRSIfNeeded(Geometry geometry, CoordinateReference try { CoordinateReferenceSystem queryWindowCRS = CRS.decode("EPSG:" + geomSRID); if (!CRS.equalsIgnoreMetadata(rasterCRS, queryWindowCRS)) { - geometry = Functions.transform(geometry, queryWindowCRS, rasterCRS, true); + geometry = GeomUtils.transform(geometry, queryWindowCRS, rasterCRS, true); } } catch (FactoryException | TransformException e) { throw new RuntimeException("Cannot transform CRS of query window", e);