Skip to content

Latitude -90 is treated as invalid value #20

Open

Description

@GoogleCodeExporter
What steps will reproduce the problem?
1. Pass for example -90 to encode
2. Watch the exception being raised.


def encode(latitude, longitude, precision=12):
    if latitude >= 90.0 or latitude < -90.0:
        raise Exception("invalid latitude.")

What is the expected output? What do you see instead?
If I'm not wrong -90 is still correct value. it's south pole.


Original issue reported on code.google.com by fi...@fizyk.net.pl on 3 Mar 2015 at 11:24

Activity

  1. hkwi commented on Jul 19, 2016

    @hkwi
    Owner

    Geohash encodes an area, not point. Some tiles do have latitude 90 at nouth edge. As encode() takes south-west coordinates, latitude 90 will be invalid.

    >>> geohash.encode(-90,0)
    'h00000000000'
    
  2. kerrick-lyft commented on Jul 20, 2016

    @kerrick-lyft

    The official geohash site does work with latitude == 90. For example, it encodes (90, -122) as crcp: http://geohash.org/crcp

    In the spirit of "be liberal in what you accept", I think encode() should work with latitude == 90, and the most reasonable thing is to return the northern-most geohash for that longitude and precision. We're seeing errors in production when latitude == 90 (probably invalid data anyway, but we'd like to avoid throwing an exception).

    Could you please re-consider merging #22?

  3. hkwi commented on Jul 21, 2016

    @hkwi
    Owner

    One big problem of accepting latitude=90 is that breaks encode/decode pair. python-geohash library will do the best for precision, but loss will be introduced when converting the coordinates into angled value.

    As you might already see, geohash.org does behaves very tricky on latitude=90. You see 90.000000 string representation on geohash.org, but it is not the real floating point number. IMHO, latitude=90 should be handled by application, not codec. You can use "zzzzzzzzzzzz" for "very near to northern polar".

    >>> geohash.decode("zzzzzzzzzzzz")[0]
    89.99999999738066
    >>> "%f" % geohash.decode("zzzzzzzzzzzz")[0]
    '90.000000'
    >>> geohash.encode(*geohash.decode("zzzzzzzzzzzz"))
    'zzzzzzzzzzzz'
    

    I'm sorry I can't merge #22 .

  4. added a commit that references this issue on Jun 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions