0
0

Geohashの個人的メモ

Posted at

Geohashとは

地図上のある程度の範囲(四角形)をまとめたものです。
メッシュコードとほぼ同じ概念で、区切り方にクセがあります。
詳細な概念説明は以下のYahoo!のサイトをご確認ください。

Geohashの種類(桁数)

4,5,6,7以外は使わなそうなので、雑に記載しています

桁数 横の長さ 縦の長さ
1 5000km 4000km
2 600km 1000km
3 160km 130km
4 19.5km 31.6km
5 4.82km 3.96km
6 609m 989m
7 152m 124m
8 19m 31m
9 5m 4m
10 0.6m 1m

(上記Yahoo!のサイトより転記)

Geohashの大まかな地図

メッシュコードだと「5339は東京!」など(経験がある人は)分かるのですが、
Geohash初心者には直感的にわからないので、地図を作成してみました。
image.png

サンプル的にFoliumで作ったGeohash3の地図

大体・・・

  • 札幌:xps
  • 東京:xn7
  • 名古屋:xn3かxn1
  • 大阪:xn0
  • 博多:wvu
  • 那覇:wud

ですね、完全に理解した

緯度経度←→Geohashの変換

Web上

こちらのサイトの検索ボタンなどで良い感じにできそうです。

Python

pip install python-geohash で入る以下のライブラリのメモです。
ドキュメントがほぼ皆無?なので、実験結果を残しております。

import geohash

サンプル

例えば、35.71439205890935, 139.7473860851063という点はGeohash=xn77hjの中にあります。
Geohash=xn77hjは、南北方向は、35.7110595703125 - 35.716552734375の範囲、
東西方向は、139.74609375 - 139.757080078125の範囲にあります。
この範囲にあるので、Geohashの中心は35.71380615234375, 139.7515869140625にあります。

image.png

緯度経度→Geohash

geohash.encode(Latitude, Longitude [, 桁数])

Sample

geohash.encode(35.71439205890935,139.7473860851063, 6)
# xn77hj

Geohash→中心緯度経度

geohash.decode(Geohash)

Sample

geohash.decode('xn77hj')
# (35.71380615234375, 139.7515869140625)

Geohash→上下左右の緯度経度(その1)

geohash.bbox(Geohash)

Sample

geohash.bbox('xn77hj')
# {'s': 35.7110595703125,
# 'w': 139.74609375,
# 'n': 35.716552734375,
# 'e': 139.757080078125}

Geohash→領域の大きさ

geohash.decode_exactly(Geohash)
# Center_Latitude, Center_Longitude, Vertical_Length/2, Horizontal_Length/2

Sample

geohash.decode_exactly('xn77hj')
# (35.71380615234375, 139.7515869140625, 0.00274658203125, 0.0054931640625)

Geohashの領域は、縦の長さがVertical_Length2、横の長さがHorizontal_Length2となります。

周辺のGeohash

Yahoo!のサイトのこのイメージで周囲8つを返します。

image.png

geohash.neighbors(Geohash)

Sample

geohash.neighbors('xpskzwj')
# ['xpskzwh',
#  'xpskzwn',
#  'xpskztv',
#  'xpskztu',
#  'xpskzty',
#  'xpskzwm',
#  'xpskzwk',
#  'xpskzwq']

メモ

dir(geohash)
result ['LONG_ZERO', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '__version__', '_base32', '_base32_map', '_decode_c2i', '_encode_i2c', '_float_hex_to_int', '_geohash', '_int_to_float_hex', '_uint64_deinterleave', '_uint64_interleave', 'bbox', 'decode', 'decode_exactly', 'decode_uint64', 'encode', 'encode_uint64', 'expand', 'expand_uint64', 'neighbors', 'sys']
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0