@@ -42,11 +42,26 @@ public List<String> evaluate(
42
42
return null ;
43
43
}
44
44
45
- Geometry polygon = CTX .getShapeFactory ().getGeometryFrom (shape );
46
- if (!(polygon instanceof Polygon || polygon instanceof MultiPolygon )) {
45
+ Geometry geometry = CTX .getShapeFactory ().getGeometryFrom (shape );
46
+ if (!(geometry instanceof Polygon || geometry instanceof MultiPolygon )) {
47
47
return null ;
48
48
}
49
49
50
+ Set <String > geohashes = new HashSet <>();
51
+
52
+ if (geometry instanceof Polygon ) {
53
+ geohashes = getGeoHashes ((Polygon ) geometry , precision );
54
+ } else {
55
+ for (int i = 0 ; i < geometry .getNumGeometries (); i ++){
56
+ Geometry polygon = geometry .getGeometryN (i );
57
+ geohashes .addAll (getGeoHashes ((Polygon ) polygon , precision ));
58
+ }
59
+ }
60
+
61
+ return new ArrayList <>(geohashes );
62
+ }
63
+
64
+ private Set <String > getGeoHashes (Polygon polygon , Integer precision ){
50
65
Point centroid = polygon .getCentroid ();
51
66
52
67
Set <String > geohashes = new HashSet <>();
@@ -55,8 +70,7 @@ public List<String> evaluate(
55
70
56
71
while (!testingGeohashes .isEmpty ()) {
57
72
String geohash = testingGeohashes .poll ();
58
- Geometry geohashGeometry = CTX .getShapeFactory ().getGeometryFrom (
59
- GeohashUtils .decodeBoundary (geohash , CTX ));
73
+ Geometry geohashGeometry = CTX .getShapeFactory ().getGeometryFrom (GeohashUtils .decodeBoundary (geohash , CTX ));
60
74
61
75
if (polygon .contains (geohashGeometry ) || polygon .intersects (geohashGeometry )) {
62
76
geohashes .add (geohash );
@@ -72,7 +86,7 @@ public List<String> evaluate(
72
86
}
73
87
}
74
88
75
- return new ArrayList <>( geohashes ) ;
89
+ return geohashes ;
76
90
}
77
91
78
92
public List <String > evaluate (
0 commit comments