jiayuasu commented on code in PR #1712:
URL: https://github.com/apache/sedona/pull/1712#discussion_r1879147274
##########
common/src/main/java/org/apache/sedona/common/Functions.java:
##########
@@ -80,6 +80,123 @@ public static double area(Geometry geometry) {
return geometry.getArea();
}
+ public static Geometry anchor(Geometry geometry) {
+ return anchor(geometry, 2, 0.2);
+ }
+
+ public static Geometry anchor(Geometry geometry, double stepSize) {
+ return anchor(geometry, stepSize, 0.2);
+ }
+
+ public static Geometry anchor(Geometry geometry, double stepSize, double
goodnessThreshold) {
+ if (geometry.getArea() <= 0) {
+ throw new IllegalArgumentException("Geometry must have a positive area");
+ }
+
+ GeometryFactory geometryFactory = new GeometryFactory();
+
+ // If the geometry is a collection, find the largest polygon
+ if (geometry instanceof GeometryCollection) {
+ GeometryCollection gc = (GeometryCollection) geometry;
+ Geometry largestPolygon = null;
+ double maxArea = Double.MIN_VALUE;
+
+ for (int i = 0; i < gc.getNumGeometries(); i++) {
+ Geometry geom = gc.getGeometryN(i);
+ double area = geom.getArea();
+ if (area > maxArea) {
+ largestPolygon = geom;
+ maxArea = area;
+ }
+ }
+
+ // Recursively process the largest polygon
+ if (largestPolygon instanceof Polygon) {
Review Comment:
+1. This function needs to be recursive.
--
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]