jiayuasu commented on code in PR #1557: URL: https://github.com/apache/sedona/pull/1557#discussion_r1728507547
########## common/src/main/java/org/apache/sedona/common/utils/GeometryDuplicateCoordinateRemover.java: ########## @@ -0,0 +1,183 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sedona.common.utils; + +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.Objects; +import java.util.Set; +import org.locationtech.jts.geom.*; + +public class GeometryDuplicateCoordinateRemover { + + public static Coordinate[] removeDuplicates(Coordinate[] coords, int minPoints) { + Coordinate pt; + int numPoint = coords.length; + int totalPointsOut = 1; + + double distance = Double.MAX_VALUE; + + if (numPoint <= minPoints) return new Coordinate[0]; + + Coordinate last = coords[0]; + int pToIndex = 1; + + for (int i = 1; i < numPoint; i++) { + boolean lastPoint = (i == numPoint - 1); + + pt = coords[i]; + + if (numPoint + totalPointsOut > minPoints + i) { + if (TOLERANCE > 0.0) { + distance = pt.distance(last); + if (!lastPoint && distance <= TOLERANCE) { + continue; + } + } else { + if (pt.equals2D(last)) { + continue; + } + } + + if (lastPoint && totalPointsOut > 1 && TOLERANCE > 0.0 && distance <= TOLERANCE) { + totalPointsOut--; + pToIndex--; + } + } + + coords[pToIndex] = pt; + totalPointsOut++; + pToIndex++; + last = pt; + } + Coordinate[] newCoordinates = newCoordinates = new Coordinate[totalPointsOut]; Review Comment: Why write it this way? ########## docs/api/sql/Function.md: ########## @@ -3266,6 +3266,46 @@ Output: LINESTRING(0 0, 1 0) ``` +## ST_RemoveRepeatedPoints + +Introduction: This function eliminates consecutive duplicate points within a geometry, preserving endpoints of LineStrings. It operates on (Multi)LineStrings, (Multi)Polygons, and MultiPoints, processing GeometryCollection elements individually. When an optional 'tolerance' value is provided, vertices within that distance are also considered duplicates. + +Format: + +`ST_RemoveRepeatedPoints(geom: Geometry, tolerance: Double)` + +`ST_RemoveRepeatedPoints(geom: Geometry)` + +Since: `v1.7.0` + +SQL Example: + +```sql Review Comment: Can you provide very detailed examples for this function? Similar to the PostGIS examples -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
