You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sedona.apache.org by ji...@apache.org on 2023/08/09 03:32:00 UTC
[sedona] branch master updated: [SEDONA-347] Centralize transform() usages (#949)
This is an automated email from the ASF dual-hosted git repository.
jiayu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sedona.git
The following commit(s) were added to refs/heads/master by this push:
new f0cee53f [SEDONA-347] Centralize transform() usages (#949)
f0cee53f is described below
commit f0cee53f88fcb8681744a0317c258b69fba82614
Author: Nilesh Gajwani <ni...@gmail.com>
AuthorDate: Tue Aug 8 23:31:55 2023 -0400
[SEDONA-347] Centralize transform() usages (#949)
Co-authored-by: Jia Yu <ji...@apache.org>
---
common/src/main/java/org/apache/sedona/common/Functions.java | 8 ++++----
.../main/java/org/apache/sedona/common/utils/GeomUtils.java | 11 +++++++++++
.../main/java/org/apache/sedona/common/utils/RasterUtils.java | 4 ++--
3 files changed, 17 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 032a2cd6..71101ffa 100644
--- a/common/src/main/java/org/apache/sedona/common/Functions.java
+++ b/common/src/main/java/org/apache/sedona/common/Functions.java
@@ -189,15 +189,15 @@ public class Functions {
return transform(geometry, sourceCRS, targetCRS, false);
}
+
public static Geometry transform(Geometry geometry, String sourceCRS, String targetCRS, boolean lenient)
throws FactoryException, TransformException {
-
- CoordinateReferenceSystem sourceCRScode = parseCRSString(sourceCRS);
+ CoordinateReferenceSystem sourceCRSCode = parseCRSString(sourceCRS);
CoordinateReferenceSystem targetCRScode = parseCRSString(targetCRS);
- MathTransform transform = CRS.findMathTransform(sourceCRScode, targetCRScode, lenient);
- return JTS.transform(geometry, transform);
+ return GeomUtils.transform(geometry, sourceCRSCode, targetCRScode, lenient);
}
+
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 0b0b2e86..05accb5d 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.operation.union.UnaryUnionOp;
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 class GeomUtils {
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 69bb44f7..cc24f1e7 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
@@ -19,6 +19,7 @@
package org.apache.sedona.common.utils;
import com.sun.media.imageioimpl.common.BogusColorSpace;
+import org.apache.sedona.common.Functions;
import org.geotools.coverage.CoverageFactoryFinder;
import org.geotools.coverage.GridSampleDimension;
import org.geotools.coverage.grid.GridCoordinates2D;
@@ -132,8 +133,7 @@ public class RasterUtils {
try {
CoordinateReferenceSystem queryWindowCRS = CRS.decode("EPSG:" + geomSRID);
if (!CRS.equalsIgnoreMetadata(rasterCRS, queryWindowCRS)) {
- MathTransform transform = CRS.findMathTransform(queryWindowCRS, rasterCRS, true);
- geometry = JTS.transform(geometry, transform);
+ geometry = GeomUtils.transform(geometry, queryWindowCRS, rasterCRS, true);
}
} catch (FactoryException | TransformException e) {
throw new RuntimeException("Cannot transform CRS of query window", e);