@@ -176,6 +176,44 @@ public static String containingGeohash(Envelope2D envelope) {
176
176
* @return up to four geohashes that completely cover given envelope
177
177
*/
178
178
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 ;
180
218
}
181
219
}
0 commit comments