项目作者: vdurante

项目描述 :
Geohash Functions for SQL Server
高级语言: PLpgSQL
项目地址: git://github.com/vdurante/sql-server-geohash-functions.git
创建时间: 2018-11-21T21:48:15Z
项目社区:https://github.com/vdurante/sql-server-geohash-functions

开源协议:GNU General Public License v3.0

下载


SQL Server Geohash Functions

This repo contains SQL Server functions capable of encoding and decoding Geohashes.

Installation

Just execute the code from geohash.sql in your SQL Server database.

Usage

Encoding

  1. SELECT dbo.geohash_encode(57.64911, 10.40744, 12)
  2. -- u4pruydqqvj8
  1. SELECT dbo.geohash_encode(57.64911, 10.40744, 8)
  2. -- u4pruydq

Decoding

Decoding a Geohash will return a table with a single row with following columns:

  • LatL - Left Latitude
  • LatR - Right Latitude
  • LngT - Top Longitude
  • LngB - Bottom Longitude
  • LatC - Center Latitude
  • LngC - Center Longitude
  • LatError - Latitude Error
  • LngError - Longitude Error

Example:

  1. SELECT
  2. LatL, LatR, LngT, LngB, LatC, LngC, LatError, LngError
  3. FROM dbo.geohash_decode('u4pruyd')
  4. -- 57.6480103 57.6493836 10.4067994 10.4081727 57.6486970 10.4074861 0.0006867 0.0006867

Using columns from a table:

  1. SELECT
  2. t.Geohash, d.LatL, d.LatR, d.LngT, d.LngB, d.LatC, d.LngC, d.LatError, d.LngError
  3. FROM MyTable t
  4. CROSS APPLY dbo.geohash_decode(t.Geohash) d

Credits

  • The geohash_bit, geohash_base32 and geohash_base32_index functions were implemented using nowelium’s geohash-mysql-func as a reference
  • The geohash_encode and geohash_decode functions were implemented using davetroy’s geohash-js as a reference