InvisibleProgrammer commented on code in PR #6813: URL: https://github.com/apache/hive/pull/6813#discussion_r4102303229
########## ql/src/java/org/apache/hadoop/hive/ql/udf/esri/GeoHashUtils.java: ########## @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.hadoop.hive.ql.udf.esri; + +import ch.hsr.geohash.BoundingBox; +import ch.hsr.geohash.GeoHash; +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.Polygon; + +public final class GeoHashUtils { + + public static final int MIN_CHARACTER_PRECISION = 1; + + /** + * Maximum geohash length in base-32 characters for {@link GeoHash#geoHashStringWithCharacterPrecision}. + */ + public static final int MAX_CHARACTER_PRECISION = 12; + + public static final int DEFAULT_CHARACTER_PRECISION = 12; + + private GeoHashUtils() { + } + + public static String geohashForPoint(double longitude, double latitude, int characterPrecision) { + return GeoHash.geoHashStringWithCharacterPrecision(latitude, longitude, characterPrecision); + } + + /** + * Returns a rectangular polygon for the geohash cell (closed ring, lon/lat coordinates). + * + * @param geohash base-32 geohash string (non-empty) + * @param characterPrecision number of leading characters to use (1–12, at most {@code geohash} + * length) + */ + public static Polygon geohashCellPolygon(String geohash, int characterPrecision) { + if (geohash == null || geohash.isEmpty()) { + return null; + } + if (characterPrecision < MIN_CHARACTER_PRECISION || + characterPrecision > MAX_CHARACTER_PRECISION || + characterPrecision > geohash.length()) { + return null; + } + String hashPrefix = geohash.substring(0, characterPrecision); Review Comment: I'm trying to understand what happens here: we receive a geohash and a precision. And we only use the first part of the hash. That suggests a geohash actually contains geo coordinates only in the first n character, according to precision. What is in the remaining part of the geohash string? -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
