Geohash

GeoHash介绍及使用 参考 GeoHash核心原理解析 GeoHash算法学习讲解、解析及原理分析 1、geohash是什么 通常我们使用一对(x,y)坐标来表示一个点的坐标。在地图上会有很多点、线、面等空间要素。如果我们要查询在自己位置附近1km以内的公交站。传统的想法是遍历所有的公交站,获取距离在1km以内的结果。然而这种方法太耗费时间和性能,没次都要计算点之间的距离。 可以理解geohash是一种算... 阅读详情


Geohash

From Wikipedia, the free encyclopedia
This article is about a system for encoding geographic coordinates. For the game, see Geohashing.

Geohash is a latitude/longitude geocode 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.

Service[edit]

The purpose of the geohash.org service, launched in February 2008, is to offer short URLs 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 a GPX 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 the peninsula of Jutland, in Denmark) produces a slightly shorter hash of u4pruydqqvj, which can be used in the URL http://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:

Decimal0123456789101112131415
Base 320123456789bcdefg
 
Decimal16171819202122232425262728293031
Base 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.

bitminmidmaxvalerr
1-90.0000.00090.00045.00045.000
00.00045.00090.00022.50022.500
10.00022.50045.00033.75011.250
122.50033.75045.00039.3755.625
133.75039.37545.00042.1882.813
139.37542.18845.00043.5941.406
042.18843.59445.00042.8910.703
042.18842.89143.59442.5390.352
142.18842.53942.89142.7150.176
042.53942.71542.89142.6270.088
042.53942.62742.71542.5830.044
142.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 error
123±23±23±2500
255± 2.8± 5.6±630
378± 0.70± 0.7±78
41010± 0.087± 0.18±20
51213± 0.022± 0.022±2.4
61515± 0.0027± 0.0055±0.61
71718±0.00068±0.00068±0.076
82020±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 the Z-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, see Haversine 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 to Geographical 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, and Accumulo[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]

External links[edit]

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

References[edit]


<img src="//en.wikipedia.org/wiki/Special:CentralAutoLogin/start?type=1x1" alt="" title="" width="1" height="1" style="border: none; position: absolute;" />
Geohash算法 1. 引言 GeoHash本质上是空间索引的一种方式,其基本原理是将地球理解为一个二维平面,将平面递归分解成更小的子块,每个子块在一定经纬度范围内拥有相同的编码。以GeoHash方式建立空间索引,可以提高对空间poi数据进行经纬度检索的效率。 2. 认识Geohash GeoHash将二维的经纬度转换成字符串,比如下图展示了北京9个区域的GeoHash字符串,分别是WX... 阅读详情

相关推荐

GeoHash算法获取附近店铺和距离

1. 简介 GeoHash算法将二维经纬度坐标直接转换成字符串,每一个字符串代表一个矩形区域,也就是说,这个矩形区域内所有的点(经纬度坐标)都共享相同的GeoHash字符串,字符串的长度越大,矩形的区域就越小,经度也就越高。字符串相似的表示距离相近,这样可以利用字符串的前缀匹配来查询附近的POI信息。 2. GeoHash算法 地球纬度区间是[-90,90],经度区间是[-180,180],通过区间法对经度和纬度分别进行计算,假如我们获取到的当前坐标为经度-0.12866, 纬度38.534413,以纬度为

rosefun96的博客 1万+

通用横轴墨卡托投影(Universal Transvers Mercator)

译自http://wiki.gis.com/wiki/index.php/Universal_Transverse_Mercator 2020-1-12版,意译。 目录 由来 定义 UTM经度带 重叠网格 利与弊 纬度带 纬度带 标记 例外 定位办法 The Universal Transverse Mercator (UTM) coordinate system is ...

liji_digital的博客 1万+

geohash和geohash聚合

Geohash原理 GeoHash本质上是空间索引的一种方式,其基本原理是将地球理解为 一个二维平面,将平面递归分解成更小的子块,每个子块在一定经纬 度范围内拥有相同的编码。以GeoHash方式建立空间索引,可以提高 对空间poi数据进行经纬度检索的效率。 认识Geohash GeoHash将二维的经纬度转换成字符串,比如下图展示了北京9个区 域的GeoHash字符串,分别是WX4ER,WX4G2、WX4G3等等,每 一个字符串代表了某一矩形区域。也就是说,这个矩形区域内所有的 点(经纬度坐标)都共享相同的

erciyuan_的博客 1345

GEOTRANS 3.7 用户使用手册 ------ 文件处理(坐标文件格式)

坐标文件格式GEOTRANS坐标文件由多个部分组成。  每个部分由一个标题组成,标题指定了输入坐标的坐标系类型和数据以及任何所需的参数值,后面跟着一系列输入坐标线,每行有一组坐标值,各个坐标值分开用逗号分隔,每个至少有一个空格。坐标文件标题标题关键字坐标文件正文评论和空白行输出文件文件处理示例坐标文件标题GEOTRANS坐标文件的标题由两个或多个标题行组成,每个标题行包含一个标识行的用途的关键字或...

Zzt的博客 1937

【GIS】geohash原理与实现

参考:https://www.cnblogs.com/LBSer/p/3310455.html https://en.wikipedia.org/wiki/Geohash 引子 考虑一个问题,如何搜索某点附近一定范围内的满足要求的公交站。 (截了个高德的图、并不知道高德地图后台如何搜索的。。。) 无脑思路:把所有的公交站和当前位置都算距离筛选 简单思路:把当前城市/附近行政...

煎饼加鸡丝 3641

Redis GeoHash 全面指南

Redis 的地理空间索引功能(GeoHash)虽然强大,但在处理大规模数据和高并发查询时,性能瓶颈依然存在。主要的性能挑战源于其底层实现和计算复杂性。Redis 使用有序集合(Sorted Set)存储地理空间数据,其中成员的分数(score)是经过 GeoHash 编码后的 52 位整数。这种编码方式虽然能够将二维的经纬度转换为一维的字符串,便于范围查询,但在进行距离计算和范围搜索时,仍需要进行大量的解码和数学运算。特别是在执行GEORADIUS或GEOSEARCH。

步子哥的博客 885

哨兵2号Sentinel-2分幅条带介绍与MGRS网格矢量文件获取

本文介绍哨兵2号(Sentinel-2)遥感影像数据的空间分幅规则,并提供军事格网参考系(Military Grid Reference System,MGRS)的.kml格式文件、.shp格式矢量文件的下载方法~

疯狂学习GIS的博客 5561

Flutter + shorebird 热更新+自定义cdn下载

本文介绍了如何优化Flutter热更新方案Shorebird在国内网络环境下的使用体验。Shorebird默认使用海外CDN存在下载慢、连接不稳定等问题,建议将补丁包上传至国内CDN(如阿里云OSS)。文章详细讲解了Shorebird环境配置、项目集成、构建发布流程,并重点说明了如何修改客户端代码实现自定义补丁下载逻辑。通过替换默认下载器,将补丁下载地址指向国内CDN,可显著提升下载速度和稳定性。这种方案既保留了Shorebird的热更新能力,又解决了国内网络环境下的痛点,适合国内企业部署使用。

sir_Hu的博客 782

GeoHash算法简介

一. 基本原理 GeoHash是一种地址编码方法。他能够把二维的空间经纬度数据编码成一个字符串。 我们知道,经度范围是东经180到西经180,纬度范围是南纬90到北纬90,我们设定西经为负,南纬为负,所以地球上的经度范围就是[-180, 180],纬度范围就是[-90,90]。如果以本初子午线、赤道为界,地球可以分成4个部分。 如果纬度范围[-90°, 0°)用二进制0代表,(0°, 90°]用二进制1代表,经度范围[-180°, 0°)用二进制0代表,(0°, 180°]用二进制1代表,那么地球可以

罗布泊coding 2万+

如何利用CN3791实现太阳能电池板对锂电池的高效充电管理

本文详细介绍了如何利用CN3791芯片实现太阳能电池板对锂电池的高效充电管理。CN3791集成了MPPT(最大功率点跟踪)功能,能智能调节太阳能板的输出,确保在不同光照条件下获得最大功率。文章涵盖芯片工作原理、外围电路设计、充电全过程管理及实际应用经验,帮助开发者优化太阳能充电系统效率。

weixin_33709219的博客 513

Windows中的TLS 1.2启用方法(IIS、C#、.Net framework)

折腾几天了windows中的tls1.2启用方法!特此记录一下 开发背景: 在一个用.net framework 2.0开发的客户端程序里面嵌入功能调用第三方物联网相关接口,服务器上有一个restful接口用于接收第三方上报的数据及处理,最后再调用第三方的物联网相关接口。本机开发环境Windows 10,客户服务器是Windows Server 2008 R2。 第一次写这种物联网相关的接口调用,而且第三方提供的文档比较简单,最基本的报文示例都没。开发环境里面各种摸索一步一个坑,首先在发送HTTP请求前

dl1314ld的博客 1万+

GeoHash原理以及代码实现

1.Geohash 算法简介 Geohash 是一种地理编码,由 Gustavo Niemeyer 发明的。它是一种分级的数据结构,把空间划分为网格。Geohash 属于空间填充曲线中的 Z 阶曲线(Z-order curve)的实际应用。 Geohash 能够提供任意精度的分段级别。一般分级从 1-12 级。 我们可以利用 Geohash 的字符串长短来决定要划分区域的大小。这个对应关系可以参考上面表格里面 cell 的宽和高。一旦选定 cell 的宽和高,那么 Geohash 字符串的长度就确定下来

qq_43777978的博客 7953

Jenkins离线安装保姆级教程:从下载.war包到SVN+Maven项目一键部署(附避坑脚本)

本文详细介绍了Jenkins离线安装的全流程,包括.war包下载、SVN+Maven项目配置及自动化部署。特别针对内网环境提供解决方案,涵盖插件管理、开发工具链配置、构建触发器和SSH部署等关键步骤,帮助企业在网络隔离环境下实现高效持续集成。

weixin_30096975的博客 382

Redis之GeoHash算法

Redis之GeoHash算法1、什么是GeoHash算法?2、GeoHash算法在Redis的应用2.1、查看一下GeoHash的api2.2、GeoHash的api的使用2.2.1、GEOADD-添加坐标2.2.2、GEODIST-计算两地之间距离2.2.3、GEOHASH-获取某个位置的hash值2.2.4、GEOPOS-获取某个位置的坐标2.2.5、GEORADIUS-给定坐标的范围2.2.6、GEORADIUSBYMEMBER-只是当前key中元素的范围筛选3、GeoHash优缺点3.1、优点3.

qq_41931364的博客 3885

S32DS新建工程、编译调试下载、导入工程详细介绍

新建了一个工程之后,下面简单介绍下基本的UI界面。其中最左下角那个是界面,这个界面很重要,是图形化配置界面,然后可以根据这些配置自动生成代码。其中,左边那些配置文件,都是系统帮我们创建好了的,我们其实可以直接用就行。有PE工具的调试,以及Jlink工具的调试。我目前使用到PE工具调试可以查看寄存器值,而Jlink调试查看不了寄存器值。连接了开发板之后,点击Debug就可以吧程序下载到芯片上了,而且可以进入到调试界面。

luobeihai的博客 2万+

【机器学习实战中阶】音乐流派分类-自动化分类不同音乐风格

数据下载地址:https://www.kaggle.com/datasets/andradaolteanu/gtzan-dataset-music-genre-classification/data背景音乐。专家们长期以来一直在尝试理解声音以及是什么使一首歌曲与另一首不同。如何可视化声音。是什么使一个音调与另一个不同。这个数据集希望能提供实现这些目标的机会。内容原始流派 - 包含10种流派,每种流派有100个音频文件,每个文件长度为30秒(著名的GTZAN数据集,声音的MNIST)

2161

获取指定矩形内的geoHash

给定一个栅格,求出栅格里面的所有geoHash。至于什么是geoHash这边不多解释;做法肯定也不止一种,这里利用第三方工具包,引入包。 <dependency> <groupId>ch.hsr</groupId> <artifactId>geohash</artifactId> <version>1.4.0</version> </dependency> /** * @param maxLa

weixin_38023814的博客 2428

那些年-SAP固定资产导入AS91 OASV

固定资产起初导入步骤: 第一部分:资产数据导入 1)两个日期配置 填写图片摘要(选填) Specify transfer date/last closed fiscal year 这里的日期填写系统切换日期,如果系统是2015-10-01上线,这里填写2015-09-3 填写图片摘要(选填) Specifylast period posted in prv system 这里指定系统切换的上一期间。这里写2015-09 填写图片摘要(选填) ​2)AS91新增 填写固定资产的分类,公司

阿土工作室 7963

Geohash精度和原理

转自:https://blog.csdn.net/u011497262/article/details/81210634    https://www.jianshu.com/p/1ecf03293b9a geohash基本原理是将地球理解为一个二维平面,将平面递归分解成更小的子块,每个子块在一定经纬度范围内拥有相同的编码,这种方式简单粗暴,可以满足对小规模的数据进行经纬度的检索 目录: 经纬度常识 认识geohash geohash算法 geohash原理 对照表 经纬度常识 经...

大JAVA解决方案 5202

【华为OD机试真题】7、字符串筛选排序 | 机试真题+思路参考+代码解析(C++、Java、Py)

题目描述 >输入一个由N个大小写字母组成的字符串 按照ASCII码值从小到大进行排序 查找字符串中第K个最小ASCII码值的字母(k>=1) 输出该字母所在字符串中的位置索引(字符串的第一个位置索引为0) k如果大于字符串长度则输出最大ASCII码值的字母所在字符串的位置索引 如果有重复字母则输出字母的最小位置索引

KJ.JK 2269

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

GeoHash简述

       Geohash是Gustavo Niemeyer于 2008年发明的公共领域地理编码系统,它将地理位置编码为一串字母和数字的短字符串。GM Morton 在 1966 年引入了类似的想法。它是一种分层空间数据结构,将空间细分为网格形状的桶,这是所谓的Z 阶曲线的众多应用之一,通常是空间- 填充曲线。        Geohashes 提供了任意精度等属性,

XiaoCai 4044

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

GeoHash算法介绍

通过上述计算,纬度产生的编码为1 1 0 1 0 0 1 0 1 1 0 0 0 1 0,经度产生的编码为1 0 1 1 1 0 0 0 1 1 0 0 0 1 1。我们知道,经度范围是东经180到西经180,纬度范围是南纬90到北纬90,我们设定西经为负,南纬为负,所以地球上的经度范围就是[-180, 180],纬度范围就是[-90,90]。区间[-90,90]进行二分为[-90,0),[0,90],称为左右区间,可以确定39.928167属于右区间[0,90],给标记为1。

weixin_43204518的博客 2115

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

使用geohash的几个要点

geohash是什么?怎么生成? geohash采用的是base32编码.即Geohash中的每一个字母或者数字(如wx4g0e中的w)都是由5bits组成(2^5 = 32,base32),这5bits可以有32中不同的组合(0~31),这样我们可以将整个地图区域分为32个区域,通过00000 ~ 11111来标识这32个区域。 Geohash的0、1串序列是经度0、1序列和纬度0、1序列...

齐梦星空 2385

GeoHash算法与用法

/** * GeoHash算法 * * 可以到 http://geohash.co/ 进行geohash编码,以确定自己代码是否写错 * * @Description GeoHash字符串编码越长,表示的范围越小,位置也越精确。 * 因此我们就可以通过比较GeoHash匹配的位数来判断两个点之间的大概距离。 * @author xrj * @date 2020/4/15 */...

persistence勿忘初心 6397
上一篇: 开发LBS应用之 根据一点的经纬度实现附近点的查询 - geohash
下一篇: GeoHash核心原理解析
codepython
博客等级 码龄20年 125粉丝 6原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值