Skip to content

Commit

Permalink
Move tranform() function to geomUtils to prevent inference confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
iGN5117 committed Aug 8, 2023
1 parent 3daecbc commit af63c69
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 1 addition & 5 deletions common/src/main/java/org/apache/sedona/common/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions common/src/main/java/org/apache/sedona/common/utils/GeomUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.*;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit af63c69

Please sign in to comment.