Skip to content

Commit e0b04d3

Browse files
committed
feat: coveringGeohash funciton added
Adds funtion which given an envelope returns up to four geohashes which cover the envelope.
1 parent dbe750f commit e0b04d3

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/main/java/com/esri/core/geometry/Geohash.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,44 @@ public static String containingGeohash(Envelope2D envelope) {
176176
* @return up to four geohashes that completely cover given envelope
177177
*/
178178
public static String[] coveringGeohash(Envelope2D envelope) {
179-
return new String[] {};
179+
180+
String[] geoHashes = new String[4];
181+
182+
double xmin = envelope.xmin;
183+
double ymin = envelope.ymin;
184+
double xmax = envelope.xmax;
185+
double ymax = envelope.ymax;
186+
187+
if (NumberUtils.isNaN(xmax)) {
188+
return new String[] {""};
189+
}
190+
String[] geoHash = {containingGeohash(envelope)};
191+
if (xmin == xmax && ymin == ymax) {
192+
Point2D p = new Point2D(xmax, ymax);
193+
return geoHash;
194+
}
195+
if (geoHash[0] != ""){
196+
return geoHash;
197+
}
198+
199+
int grid = 45;
200+
int gridMaxLon = (int)Math.floor(xmax/grid);
201+
int gridMinLon = (int)Math.floor(xmin/grid);
202+
int gridMaxLat = (int)Math.floor(ymax/grid);
203+
int gridMinLat = (int)Math.floor(ymin/grid);
204+
int deltaLon = gridMaxLon - gridMinLon + 1;
205+
int deltaLat = gridMaxLat - gridMinLat + 1;
206+
207+
if (deltaLon * deltaLat > 4){
208+
return geoHashes;
209+
} else {
210+
for (int i = 0; i < deltaLon; i++){
211+
for (int j = 0; j < deltaLat; j++){
212+
Point2D p = new Point2D(gridMinLon + i * grid, gridMinLat + j * grid);
213+
geoHashes[i*deltaLat] = toGeohash(p, 1);
214+
}
215+
}
216+
}
217+
return geoHashes;
180218
}
181219
}

0 commit comments

Comments
 (0)