jillesvangurp / geogeometry

GeoGeometry is a set of algorithms and functions for manipulating geo hashes and geometric shapes with geo coordinates.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

geoHashesForPolygon Poles Condition

ylassoued opened this issue · comments

Checking proximity to the poles is incorrect in method geoHashesForPolygon (see code snippet below). Since the coordinates (poligonPoints) are always expressed as lat-lon (and not lon-lat), the inequality condition should be applied to ds[0] and not ds[1].

public static Set<String> geoHashesForPolygon(int maxLength, double[]... polygonPoints) {
        for (double[] ds : polygonPoints) {
            // basically the algorithm can go into an endless loop. Best to avoid the poles.
            if(ds[1] < -89.5 || ds[1] > 89.5) {
                throw new IllegalArgumentException(
                        "please stay away from the north pole or the south pole; there are some known issues there. Besides, nothing there but snow and ice.");
            }
        }
        ...
}

I am working with longitudes 108.*. And this is causing the API to throw exceptions (close to north pole).

Fixing the above was not sufficient, as there seems to be an inconsistency throughout the API regarding the order lat-lon vs lon-lat.

Try for example to get the geo-hashes for the following line (lat-lon coordinates):

[108.9614885, 34.2246231], [108.9611199, 34.2244855], [108.9601038, 34.2243422], [108.9592672, 34.2243198]

are you sure you are not mixing up long and lat?

lat/lon order is a bit intentional. Geojson specifies this exactly the opposite from what most APIs seem to do.

I tried both orders lat-lon and lon-lat. The method in question is geoHashesForLine, which seems to call geoHashesForPolygon. Try it yourself.

  • With lat-lon I get "close to poles" exception.
  • With lon-lat, I get an error saying that the latitude (108.*) is out of range.
    There seem to be an inconsistency is dealing with the coordinates in the API.
    To reproduce the error, jut call geoHashesForLine for the following line (expressed here in lat-lon):
[108.9614885, 34.2246231], [108.9611199, 34.2244855], [108.9601038, 34.2243422], [108.9592672, 34.2243198]

Try both lat-lon and lon-lat.

Sorry about this. I haven't really used this in five years and don't really have time to jump on this. Feel free to create a PR to try to fix this.

No worries at all Jilles. I did not pay attention to the date this API was last updated. I have found an alternative anyway.
Cheers