Geohash

来源:互联网 发布:网络挖矿是啥意思 编辑:程序博客网 时间:2024/05/22 03:24


Geohash

From Wikipedia, the free encyclopedia
Jump to: navigation, search
This article is about a system for encoding geographic coordinates. For the game, seeGeohashing.

Geohash is a latitude/longitudegeocode system invented by Gustavo Niemeyer when writing the web service at geohash.org, and put into the public domain. It is a hierarchical spatial data structure which subdivides space into buckets of grid shape.

Geohashes offer properties like arbitrary precision and the possibility of gradually removing characters from the end of the code to reduce its size (and gradually lose precision).

As a consequence of the gradual precision degradation, nearby places will often (but not always) present similar prefixes. The longer a shared prefix is, the closer the two places are.

Contents

 [hide] 
  • 1Service
  • 2Uses
  • 3Example
    • 3.1Decode from base 32
    • 3.2Decode binary to decimal
    • 3.3Worked example
  • 4Limitations
  • 5License and patents
  • 6See also
  • 7External links
  • 8References

Service[edit]

The purpose of the geohash.org service, launched in February 2008, is to offer shortURLs which uniquely identify positions on the Earth, so that referencing them in emails, forums, and websites is more convenient.

To obtain the Geohash, the user provides an address to be geocoded, or latitude and longitude coordinates, in a single input box (most commonly used formats for latitude and longitude pairs are accepted), and performs the request.

Besides showing the latitude and longitude corresponding to the given Geohash, users who navigate to a Geohash at geohash.org are also presented with an embedded map, and may download aGPX file, or transfer the waypoint directly to certain GPS receivers. Links are also provided to external sites that may provide further details around the specified location.

For example, the coordinate pair 57.64911,10.40744 (near the tip of thepeninsula of Jutland, in Denmark) produces a slightly shorter hash of u4pruydqqvj, which can be used in the URLhttp://geohash.org/u4pruydqqvj

Uses[edit]

The main usages of Geohashes are

  • as a unique identifier.
  • represent point data e.g. in databases.

Geohashes have also been proposed to be used for geotagging.

When used in a database, the structure of geohashed data has two advantages. First, data indexed by geohash will have all points for a given rectangular area in contiguous slices (the number of slices depends on the precision required and the presence of geohash "fault lines"). This is especially useful in database systems where queries on a single index are much easier or faster than multiple-index queries. Second, this index structure can be used for a quick-and-dirty proximity search - the closest points are often among the closest geohashes. Another system known as GeoZip might provide a simpler way of achieving similar results if the application does not require the resulting code to be in a compressed format. This claim made by the GeoZip inventor has not been verified yet.

Example[edit]

Using the hash ezs42 as an example, here is how it is decoded into a decimal latitude and longitude

Decode from base 32[edit]

The first step is decoding it from base 32 using the following character map:

Decimal0123456789101112131415Base 320123456789bcdefg Decimal16171819202122232425262728293031Base 32hjkmnpqrstuvwxyz

This operation results in the bits 01101 11111 11000 00100 00010. Assuming that counting starts at 0 in the left side, the even bits are taken for the longitude code (0111110000000), while the odd bits are taken for the latitude code (101111001001).

Decode binary to decimal[edit]

Each binary code is then used in a series of divisions, considering one bit at a time, again from the left to the right side. For the latitude value, the interval -90 to +90 is divided by 2, producing two intervals: -90 to 0, and 0 to +90. Since the first bit is 1, the higher interval is chosen, and becomes the current interval. The procedure is repeated for all bits in the code. Finally, the latitude value is the center of the resulting interval. Longitudes are processed in an equivalent way, keeping in mind that the initial interval is -180 to +180.

Finishing the procedure should yield approximately latitude 42.6 and longitude -5.6.

Worked example[edit]

Here's a worked example decoding 101111001001 into 42.6. To start with, we know the latitude is somewhere in the range −90 to 90. With no bits, we'd have to guess the latitude was 0, giving us an error of ±90. With one bit, we can decide whether its in the range −90 to 0, or 0 to 90. The first bit is high, so we know our latitude is somewhere between 0 and 90. Without any more bits, we'd guess the latitude was 45, giving us an error of ±45.

Each subsequent bit halves this error. This table shows the effect of each bit. At each stage, the relevant half of the range is highlighted in green; a low bit selects the lower range, a high bit selects the upper range.

The last column shows the latitude, simply the mean value of the range. Each subsequent bit makes this value more precise.

bitminmidmaxvalerr1-90.0000.00090.00045.00045.00000.00045.00090.00022.50022.50010.00022.50045.00033.75011.250122.50033.75045.00039.3755.625133.75039.37545.00042.1882.813139.37542.18845.00043.5941.406042.18843.59445.00042.8910.703042.18842.89143.59442.5390.352142.18842.53942.89142.7150.176042.53942.71542.89142.6270.088042.53942.62742.71542.5830.044142.53942.58342.62742.6050.022

(The numbers in the above table have been rounded to 3 decimal places for clarity)

Final rounding should be done carefully in a way that

 \min \le \mathrm{round}(value) \le \max

So if rounding 42.605 to 42.61 or 42.6 is correct, rounding to 43 it is not.

geohash lengthlat bitslng bitslat errorlng errorkm error123±23±23±2500255± 2.8± 5.6±630378± 0.70± 0.7±7841010± 0.087± 0.18±2051213± 0.022± 0.022±2.461515± 0.0027± 0.0055±0.6171718±0.00068±0.00068±0.07682020±0.000085±0.00017±0.019

Limitations[edit]

One limitation of the Geohash algorithm is in attempting to utilize it to find points in proximity to each other based on a common prefix.Edge case locations close to each other but on opposite sides of the 180 degree meridian will result in Geohash codes with no common prefix (different longitudes for near physical locations). Points close by at the North and South poles will have very different geohashes (different latitudes for near physical locations).

Two close locations on either side of the Equator (or Greenwich meridian) will not have a long common prefix since they belong to different 'halves' of the world. Put simply, one location's binary latitude (or longitude) will be 011111... and the other 100000...., so they will not have a common prefix and most bits will be flipped. This can also be seen as a consequence of relying on theZ-order curve for ordering the points, as two points close-by might be visited at very different times. However, two points with a long common prefix will be close-by.

In order to do a proximity search, one could compute the southwest corner (low geohash with low latitude and longitude) and northeast corner (high geohash with high latitude and longitude) of a bounding box and search for geohashes between those two. This will retrieve all points in the z-order curve between the two corners, which can be far too many points, this also breaks down at the 180 meridians and the poles. Solr uses a filter list of prefixes, by computing the prefixes of the nearest squares close to the geohash [1].

Thirdly, since a geohash (in this implementation) is based on coordinates of longitude and latitude the distance between two geohashes reflects the distance in latitude/longitude coordinates between two points, which does not translate to actual distance, seeHaversine formula.

Example of non-linearity for latitude-longitude system:

  • At the Equator (0 Degrees) the length of a degree of longitude is 111.320 km, while a degree of latitude measures 110.574 km, an error of 0.67%.
  • At 30 Degrees (Mid Latitudes) the error is 110.852/96.486 = 14.89%
  • At 60 Degrees (High Arctic) the error is 111.412/55.800 = 99.67%, reaching infinity at the poles.

Note that these limitations are not due to geohashing, and not due to latitude-longitude coordinates, but due to the difficulty of mapping coordinates on a sphere (non linear and with wrapping of values, similar to modulo arithmetic) to two dimensional coordinates and the difficulty of exploring a two dimensional space uniformly. The first is related toGeographical coordinate system and Map projection, and the other to Hilbert curve and z-order curve. Once a coordinate system is found that represents points linearly in distance and wraps up at the edges, and can be explored uniformly, applying geohashing to those coordinates will not suffer from the limitations above.

While it is possible to apply geohashing to an area with a cartesian coordinate system, it would then only apply to the area where the coordinate system applies.

Despite those issues, there are possible workarounds, and the algorithm has been successfully used in Elasticsearch,[1] MongoDB,[2] HBase, andAccumulo[3] to implement proximity searches.

An alternative to storing Geohashes as strings in a database are Locational codes, which are also called spatial keys and similar to QuadTiles.[4][5]

License and patents[edit]

The Geohash geocode has been put in the public domain by its inventor in the public announcement date, on February 26, 2008.[6]

While comparable algorithms have been successfully patented[7] and had copyright claimed upon,[8][9] GeoHash is based on an entirely different algorithm and approach.

See also[edit]

  • Geohash-36
  • Grid (spatial index)
  • Morton number (number theory)
  • Natural Area Code
  • Maidenhead Locator System
  • Military grid reference system

External links[edit]

  • geohash.org
  • elasticsearch: the definitive guide - Geo
  • Visualizing Geohash
  • Perl module to interact with geohash.org
  • Libraries, packages and modules for encoding and decoding geohashes without interacting with geohash.org:in C, Python, Haskell,

Perl,Ruby (Gem), Ruby, Ocaml, Clojure, Go, Objective-C, Javascript (Demo),PHP, MySQL, PostGIS, nodejs

  • Java classes for encoding and decoding geohashes: geospatialweb, jgeohash, geohash-java, and geo
  • kml file for Google Earth displaying geohash grid
  • Area Check Tool
  • [2] -GeoMesa - A spatio-temporal database using Geohashes and Accumulo
  • Simple and fast conversion from geohash to latitude/longitude and from latitude/longitude to geohash

References[edit]

  1. Jump up^ geo_shape Type Mapping in Elasticsearch
  2. Jump up^ Geospatial Indexing in MongoDB
  3. Jump up^ Spatio-temporal Indexing in Non-relational Distributed Databases
  4. Jump up^ Spatial Keys
  5. Jump up^ QuadTiles
  6. Jump up^ geohash.org announcement post in groundspeak.com forum
  7. Jump up^ Compact text encoding of latitude/longitude coordinates - Patent 20050023524
  8. Jump up^ Does Microsoft Infringe the Natural Area Coding System?
  9. Jump up^ The Natural Area Coding System - Legal and Licensing


[hide]
Geocoding systems
Administrative codes
  • HASC
  • NUTS (EU)
  • ONS
  • MARC country codes
  • SGC codes (Canada)
  • UN M.49 (UN)
 Airport codes
  • IATA airport code
  • ICAO airport code
 Country codes
  • IANA country code
  • ISO 3166-1
    • alpha-2
    • alpha-3
    • numeric
  • IOC country code
 Geodesic place codes
Global
  • Geohash
  • Geohash-36
  • Georef
  • Geotude
  • SALB
  • Marsden square
  • Natural Area Code
  • QDGC
  • UN/LOCODE
  • UTM
  • WMO squares
 
North America
  • FIPS country code (FIPS 10-4)
  • FIPS place code (FIPS 55)
  • FIPS county code (FIPS 6-4)
  • FIPS state code (FIPS 5-2)
  • SGC codes
 Postal codes
  • Natural Area Code
  • Postal Index Number
  • ZIP code
 Telephony
  • ITU-R country codes
  • ITU-T country calling codes
  • ITU-T mobile calling codes
 Radio broadcasting
  • Maidenhead Locator System
  • Historical : QRA locator
 Sport
  • IOC country codes
<img src="//en.wikipedia.org/wiki/Special:CentralAutoLogin/start?type=1x1" alt="" title="" width="1" height="1" style="border: none; position: absolute;" />
Retrieved from "http://en.wikipedia.org/w/index.php?title=Geohash&oldid=651848024"
0 0
原创粉丝点击