jiayuasu commented on code in PR #1712:
URL: https://github.com/apache/sedona/pull/1712#discussion_r1887525985
##########
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 labelPoint(Geometry geometry) {
+ return labelPoint(geometry, 16, 0.2);
+ }
+
+ public static Geometry labelPoint(Geometry geometry, int gridResolution) {
+ return labelPoint(geometry, gridResolution, 0.2);
+ }
+
+ public static Geometry labelPoint(
+ Geometry geometry, int gridResolution, double goodnessThreshold) {
+ if (geometry.getArea() <= 0) {
+ throw new IllegalArgumentException("Geometry must have a positive area");
+ }
+
+ GeometryFactory geometryFactory = new GeometryFactory();
+
+ // Find the largest polygon
+ Polygon largestPolygon = findLargestPolygon(geometry);
+
+ if (largestPolygon == null) {
+ throw new IllegalArgumentException("Geometry must contain at least one
Polygon");
+ }
+
+ return polygonToLabel(largestPolygon, gridResolution, goodnessThreshold,
geometryFactory);
+ }
+
+ private static Polygon findLargestPolygon(Geometry geometry) {
+ if (geometry instanceof Polygon) {
+ return (Polygon) geometry;
+ }
+
+ if (geometry instanceof GeometryCollection) {
Review Comment:
Are you sure?
So both `MultiPolygon` and `GeometryCollection` return true for `InstanceOf
GeometryCollection`?
--
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]