geohash.netは、文字列と整数のジオハッシュをエンコードおよびデコードするための軽量で高性能C#ライブラリです。
トト
Geohash.netライブラリを使用する方法の簡単な例を次に示します。
using NetGeohash ;
// Encode latitude and longitude coordinates into a geohash string
string geohash = Geohash . Encode ( 37.421999 , - 122.084057 , 9 ) ;
// Decode the geohash string into latitude and longitude coordinates
( double latitude , double longitude ) = Geohash . Decode ( geohash ) ;
// Encode the geohash string into an integer format
ulong geohashInt = Geohash . EncodeToInt64 ( 37.421999 , - 122.084057 , 9 ) ;
// Decode the integer geohash into latitude and longitude coordinates
( latitude , longitude ) = Geohash . DecodeFromInt64 ( geohashInt ) ; Geohashは、短い英数字弦または整数を使用して地理的位置を表現できるジオコーディングシステムです。 2008年にGustavo Niemeyerによって開発され、その後、空間データをエンコードおよびインデックス作成するための一般的な方法になりました。
Geohashingの背後にある概念は、緯度と経度の座標を取り、それらをよりコンパクトな形に変換することです。これは、地球の表面を長方形の細胞に再帰的に細分化することによって達成され、一意の識別子が割り当てられます。 Geohashの長さは精度のレベルを決定し、より長いジオハッシュがより小さな領域を表します。
Geohashセルにはいくつかの顕著な特性があります。
たとえば、緯度37.7749と経度-122.4194の位置のGeohash文字列を12の精密レベルで生成するには、次の3つの段階に従うことができます。
ユニット間隔[0、1]にマッピングし、2^32( exp2(32) )を掛けることにより、緯度と経度を32ビット整数に量子化します。
緯度は範囲を取得します[-90、90]。したがって、緯度の32ビット整数表現は
lat32 = floor ( exp2 ( 32 ) * ( latitude + 90 ) / 180 )私たちの場合、3048827870( 0b10110101101110010110101111011110 )に等しい
同様に経度の場合[-180、180]:
lng32 = floor ( exp2 ( 32 ) * ( longitude + 180 ) / 360 )私たちの場合、686963316( 0b101000111100100011101001110100 )に等しい
32ビットの量子化された緯度と経度は、64ビットの値(整数Geohash )を生成するためにビットインテルレーブです。
以下の図は、操作を示しています。

注:緯度と経度はそれぞれ偶数および奇数ビットを占有します。
実行中の例では、整数Geohashは5589511709871930228( 0b0100110110010001111011110100100100011110110011010111101101110100 )です。
この数は、より低い精度で撮影する必要があります。整数Geohashの精度はN高ビットで構成されているため、過剰なビットを切り捨てる必要があります。ビットシフト操作によってこれを行うことができます:
hash = interleaved >> ( sizeof ( ulong ) * BITS_PER_BYTE - log2 ( 32 ) * precision ) // 64 - 5 * precisionこれは、349344448186995639( 0b010011011001000111101111010010010001111011001101011110110111 )です。
注:このステップは、最終的にGeohashの重要なプレフィックスプロパティを提供します。低精度でのポイントのGeohashは、より高い精度でGeohashのプレフィックスです。したがって、近接検索は、Geohashプレフィックスを一致させる(最初のパスとして)削減できます。
文字列geohashは、integer geohashからbase32エンコーディングによって取得されます。これは、アルファベットの選択を除いて標準です。各Geohash文字は5ビット( log2(32) )バイナリ値を表し、Geohash文字列全体は複数の連結5ビット値で構成されています。
0123456789bcdefghjkmnpqrstuvwxyz
エンコーディングはハイビットで始まり、精度の各文字に対して5ビットの整数Geohashを消費します。その結果、最大精度は12文字または60ビットです。
バイナリ値を5ビットのグループに分割し、各グループを対応するベース32文字に変換します。
01001 ( 9) - 9
10110 (22) - q
01000 ( 8) - 8
11110 (30) - y
11110 (30) - y
10010 (18) - k
01000 ( 8) - 8
11110 (30) - y
11001 (25) - t
10101 (21) - p
11101 (29) - x
10111 (23) - r
すべてのベース32文字を一緒に連結して、最終的なgeohash文字列を形成する: 9q8yyk8ytpxr
内部ユースケースの場合、整数Geohashでは通常十分です。 Base32ステップは、完全性のためにここに含まれていました。
BenchmarkDotNet =v0.13.5, OS =Windows 11 (10.0.22000.1696/21H2/SunValley)
AMD Ryzen 9 3900X, 1 CPU, 24 logical and 12 physical cores
.NET SDK =8.0.100-preview.1.23115.2
[Host] : .NET 8.0.0 (8.0.23.11008), X64 RyuJIT AVX2
Job-KKMPKU : .NET 8.0.0 (8.0.23.11008), X64 RyuJIT AVX2
Jit =RyuJit Platform =X64 Runtime =.NET 8.0
| 方法 | 入力 | 平均 | エラー | stddev | コードサイズ | GEN0 | 割り当てられます |
|---|---|---|---|---|---|---|---|
| netgeohash | k | 8.112 ns | 0.1881 ns | 0.2090 ns | 1,717 b | - | - |
| netcoregeohash | k | 145.271 ns | 0.8736 ns | 0.7295 ns | 18 b | 0.0038 | 32 b |
| ngeohashlib | k | 143.414 ns | 0.8529 ns | 0.7561 ns | 9 b | 0.0229 | 192 b |
| netgeohash | YD | 8.442 ns | 0.1032 ns | 0.0965 ns | 1,717 b | - | - |
| netcoregeohash | YD | 166.305 ns | 0.8682 ns | 0.8121 ns | 18 b | 0.0038 | 32 b |
| ngeohashlib | YD | 169.663 ns | 1.0957 ns | 1.0249 ns | 9 b | 0.0229 | 192 b |
| netgeohash | 6n3 | 9.442 ns | 0.1746 ns | 0.1633 ns | 1,717 b | - | - |
| netcoregeohash | 6n3 | 192.502 ns | 2.0566 ns | 1.9238 ns | 18 b | 0.0038 | 32 b |
| ngeohashlib | 6n3 | 202.150 ns | 1.9676 ns | 1.8405 ns | 9 b | 0.0229 | 192 b |
| netgeohash | ZVGK | 10.183 ns | 0.1023 ns | 0.0907 ns | 1,717 b | - | - |
| netcoregeohash | ZVGK | 218.244 ns | 1.4455 ns | 1.3521 ns | 18 b | 0.0038 | 32 b |
| ngeohashlib | ZVGK | 223.580 ns | 0.7643 ns | 0.6776 ns | 9 b | 0.0229 | 192 b |
| netgeohash | T05kh | 10.726 ns | 0.2016 ns | 0.1886 ns | 1,717 b | - | - |
| netcoregeohash | T05kh | 310.208 ns | 0.9773 ns | 0.8663 ns | 18 b | 0.0038 | 32 b |
| ngeohashlib | T05kh | 263.364 ns | 2.2418 ns | 2.0970 ns | 9 b | 0.0229 | 192 b |
| netgeohash | B5CV2H | 11.413 ns | 0.0796 ns | 0.0706 ns | 1,717 b | - | - |
| netcoregeohash | B5CV2H | 328.490 ns | 2.4518 ns | 2.1735 ns | 18 b | 0.0038 | 32 b |
| ngeohashlib | B5CV2H | 283.862 ns | 2.9657 ns | 2.7741 ns | 9 b | 0.0229 | 192 b |
| netgeohash | vveyj80 | 12.114 ns | 0.1749 ns | 0.1636 ns | 1,717 b | - | - |
| netcoregeohash | vveyj80 | 358.143 ns | 0.9470 ns | 0.7908 ns | 18 b | 0.0038 | 32 b |
| ngeohashlib | vveyj80 | 318.725 ns | 1.7533 ns | 1.6400 ns | 9 b | 0.0229 | 192 b |
| netgeohash | f7y53xjt | 12.676 ns | 0.2287 ns | 0.2140 ns | 1,717 b | - | - |
| netcoregeohash | f7y53xjt | 380.157 ns | 2.2520 ns | 2.1065 ns | 18 b | 0.0038 | 32 b |
| ngeohashlib | f7y53xjt | 334.277 ns | 1.0733 ns | 1.0039 ns | 9 b | 0.0229 | 192 b |
| netgeohash | TRM92JKBV | 12.990 ns | 0.1217 ns | 0.1139 ns | 1,717 b | - | - |
| netcoregeohash | TRM92JKBV | 404.136 ns | 1.9322 ns | 1.7128 ns | 18 b | 0.0038 | 32 b |
| ngeohashlib | TRM92JKBV | 374.209 ns | 1.0807 ns | 1.0109 ns | 9 b | 0.0229 | 192 b |
| netgeohash | DRMQ3GX6ZT | 13.861 ns | 0.1824 ns | 0.1706 ns | 1,717 b | - | - |
| netcoregeohash | DRMQ3GX6ZT | 429.735 ns | 1.6946 ns | 1.4151 ns | 18 b | 0.0038 | 32 b |
| ngeohashlib | DRMQ3GX6ZT | 400.585 ns | 1.9080 ns | 1.7847 ns | 9 b | 0.0229 | 192 b |
| netgeohash | 9Zefgnuj7dw | 14.265 ns | 0.2997 ns | 0.2803 ns | 1,717 b | - | - |
| netcoregeohash | 9Zefgnuj7dw | 455.781 ns | 3.3098 ns | 2.9341 ns | 18 b | 0.0038 | 32 b |
| ngeohashlib | 9Zefgnuj7dw | 416.747 ns | 2.7821 ns | 2.6023 ns | 9 b | 0.0229 | 192 b |
| netgeohash | K9M2H7T1N0C2 | 14.864 ns | 0.3210 ns | 0.3153 ns | 1,717 b | - | - |
| netcoregeohash | K9M2H7T1N0C2 | 479.624 ns | 1.5628 ns | 1.3854 ns | 18 b | 0.0038 | 32 b |
| ngeohashlib | K9M2H7T1N0C2 | 467.252 ns | 1.3795 ns | 1.2904 ns | 9 b | 0.0229 | 192 b |

| 方法 | 緯度 | 経度 | 精度 | 平均 | エラー | stddev | コードサイズ | GEN0 | 割り当てられます |
|---|---|---|---|---|---|---|---|---|---|
| netgeohash | -89.127865 | -179.438962 | 7 | 20.69 ns | 0.146 ns | 0.129 ns | 906 b | 0.0048 | 40 b |
| netcoregeohash | -89.127865 | -179.438962 | 7 | 195.04 ns | 0.632 ns | 0.528 ns | 14 b | 0.0172 | 144 b |
| ngeohashlib | -89.127865 | -179.438962 | 7 | 324.45 ns | 3.044 ns | 2.848 ns | 19 b | 0.0458 | 384 b |
| netgeohash | -41.2858 | 174.7868 | 12 | 24.77 ns | 0.352 ns | 0.329 ns | 906 b | 0.0057 | 48 b |
| netcoregeohash | -41.2858 | 174.7868 | 12 | 318.08 ns | 2.079 ns | 1.944 ns | 14 b | 0.0181 | 152 b |
| ngeohashlib | -41.2858 | 174.7868 | 12 | 493.78 ns | 2.879 ns | 2.552 ns | 19 b | 0.0687 | 576 b |
| netgeohash | -12.347856 | 34.890273 | 3 | 17.95 ns | 0.215 ns | 0.201 ns | 906 b | 0.0038 | 32 b |
| netcoregeohash | -12.347856 | 34.890273 | 3 | 104.91 ns | 0.616 ns | 0.546 ns | 14 b | 0.0162 | 136 b |
| ngeohashlib | -12.347856 | 34.890273 | 3 | 167.74 ns | 2.523 ns | 2.360 ns | 19 b | 0.0277 | 232 b |
| netgeohash | 45.678912 | 92.45236 | 4 | 18.39 ns | 0.313 ns | 0.293 ns | 906 b | 0.0038 | 32 b |
| netcoregeohash | 45.678912 | 92.45236 | 4 | 127.05 ns | 1.053 ns | 0.985 ns | 14 b | 0.0162 | 136 b |
| ngeohashlib | 45.678912 | 92.45236 | 4 | 209.17 ns | 1.549 ns | 1.449 ns | 19 b | 0.0305 | 256 b |
| netgeohash | 52.5174 | 13.409 | 12 | 24.64 ns | 0.299 ns | 0.280 ns | 906 b | 0.0057 | 48 b |
| netcoregeohash | 52.5174 | 13.409 | 12 | 310.05 ns | 1.637 ns | 1.451 ns | 14 b | 0.0181 | 152 b |
| ngeohashlib | 52.5174 | 13.409 | 12 | 498.72 ns | 5.374 ns | 5.027 ns | 19 b | 0.0687 | 576 b |
| netgeohash | 80.294617 | 19.543821 | 5 | 18.82 ns | 0.228 ns | 0.191 ns | 906 b | 0.0038 | 32 b |
| netcoregeohash | 80.294617 | 19.543821 | 5 | 152.24 ns | 0.561 ns | 0.498 ns | 14 b | 0.0162 | 136 b |
| ngeohashlib | 80.294617 | 19.543821 | 5 | 242.98 ns | 2.265 ns | 2.008 ns | 19 b | 0.0391 | 328 b |

geohash.netへの貢献をお勧めします!バグに出くわしたり、新しい機能の提案をしている場合は、subを開いたり、githubにプルリクエストを送信したりすることをheしないでください。私は常に図書館を強化し、コミュニティにより多くの価値を提供する方法を探しています。
Geohash.netは、Michael McLoughlinの調査と調査結果に基づいています。 GOの地理ハッシングと高性能ジオハシングアルゴリズムの実装に関する彼の研究は、Golang AssemblyのGeohashのこの記事に記載されています。