From b21e5b9323ffc14c0fc2ed73d75fa7f99a11f8ab Mon Sep 17 00:00:00 2001 From: --replace-all Date: Sun, 3 Mar 2024 16:45:28 +0100 Subject: [PATCH] Feat: Implemented containingGeohash --- .../java/com/esri/core/geometry/Geohash.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/esri/core/geometry/Geohash.java b/src/main/java/com/esri/core/geometry/Geohash.java index ab61be80..739fda5e 100644 --- a/src/main/java/com/esri/core/geometry/Geohash.java +++ b/src/main/java/com/esri/core/geometry/Geohash.java @@ -167,7 +167,39 @@ public static String convertToBinary( * @return the geohash as a string */ public static String containingGeohash(Envelope2D envelope) { - return ""; + double posMinX = envelope.xmin + 180; + double posMaxX = envelope.xmax + 180; + double posMinY = envelope.ymin + 90; + double posMaxY = envelope.ymax + 90; + int chars = 0; + double xmin = 0; + double xmax = 0; + double ymin = 0; + double ymax = 0; + double deltaLon = 360; + double deltaLat = 180; + + while(xmin == xmax && ymin == ymax && chars < 25){ + + if(chars%2 == 0){ + deltaLon = deltaLon / 8; + deltaLat = deltaLat / 4; + }else{ + deltaLon = deltaLon / 4; + deltaLat = deltaLat / 8; + } + + xmin = Math.floor(posMinX/deltaLon); + xmax = Math.floor(posMaxX/deltaLon); + ymin = Math.floor(posMinY/deltaLat); + ymax = Math.floor(posMaxY/deltaLat); + + chars++; + } + + if(chars == 1) return ""; + + return toGeohash(new Point2D(envelope.xmin, envelope.ymin), chars-1); } /**