You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sedona.apache.org by zo...@apache.org on 2023/04/12 08:02:57 UTC
[sedona] 01/01: move 3 ST functions implementation to common Functions
This is an automated email from the ASF dual-hosted git repository.
zongsizhang pushed a commit to branch fix/move-sql-st-functions-implementation-to-commons
in repository https://gitbox.apache.org/repos/asf/sedona.git
commit 744960eebf028a7a478490a84e4d464e3f0f1d7a
Author: zongsi.zhang <kr...@gmail.com>
AuthorDate: Wed Apr 12 16:02:43 2023 +0800
move 3 ST functions implementation to common Functions
---
.../main/java/org/apache/sedona/common/Functions.java | 19 +++++++++++++++++++
.../spark/sql/sedona_sql/expressions/Functions.scala | 4 ++--
2 files changed, 21 insertions(+), 2 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 2c90d06b..d8cde549 100644
--- a/common/src/main/java/org/apache/sedona/common/Functions.java
+++ b/common/src/main/java/org/apache/sedona/common/Functions.java
@@ -37,6 +37,7 @@ import org.locationtech.jts.operation.linemerge.LineMerger;
import org.locationtech.jts.operation.valid.IsSimpleOp;
import org.locationtech.jts.operation.valid.IsValidOp;
import org.locationtech.jts.precision.GeometryPrecisionReducer;
+import org.locationtech.jts.simplify.TopologyPreservingSimplifier;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.NoSuchAuthorityCodeException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
@@ -575,4 +576,22 @@ public class Functions {
}
return S2Utils.roundCellsToSameLevel(new ArrayList<>(cellIds), level).stream().map(S2CellId::id).collect(Collectors.toList()).toArray(new Long[cellIds.size()]);
}
+
+ // create static function named simplifyPreserveTopology
+ public static Geometry simplifyPreserveTopology(Geometry geometry, double distanceTolerance) {
+ return TopologyPreservingSimplifier.simplify(geometry, distanceTolerance);
+ }
+
+ public static String geometryType(Geometry geometry) {
+ return "ST_" + geometry.getGeometryType();
+ }
+
+ public static Geometry StartPoint(Geometry geometry, double distance) {
+ if (geometry instanceof LineString) {
+ LineString line = (LineString) geometry;
+ return line.getStartPoint();
+ }
+ return null;
+ }
+
}
diff --git a/sql/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala b/sql/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala
index 9de64be9..132251f1 100644
--- a/sql/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala
+++ b/sql/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala
@@ -310,7 +310,7 @@ case class ST_IsSimple(inputExpressions: Seq[Expression])
* second arg is distance tolerance for the simplification(all vertices in the simplified geometry will be within this distance of the original geometry)
*/
case class ST_SimplifyPreserveTopology(inputExpressions: Seq[Expression])
- extends InferredBinaryExpression(TopologyPreservingSimplifier.simplify) with FoldableExpression {
+ extends InferredBinaryExpression(Functions.simplifyPreserveTopology) with FoldableExpression {
protected def withNewChildrenInternal(newChildren: IndexedSeq[Expression]) = {
copy(inputExpressions = newChildren)
@@ -383,7 +383,7 @@ case class ST_GeometryType(inputExpressions: Seq[Expression])
extends UnaryGeometryExpression with FoldableExpression with CodegenFallback {
override protected def nullSafeEval(geometry: Geometry): Any = {
- UTF8String.fromString("ST_" + geometry.getGeometryType)
+ UTF8String.fromString(Functions.geometryType(geometry))
}
override def dataType: DataType = StringType