Skip to content

vdurante/sql-server-geohash-functions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

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

SELECT dbo.geohash_encode(57.64911, 10.40744, 12)
-- u4pruydqqvj8
SELECT dbo.geohash_encode(57.64911, 10.40744, 8)
-- 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:

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

Using columns from a table:

SELECT
    t.Geohash, d.LatL, d.LatR, d.LngT, d.LngB, d.LatC, d.LngC, d.LatError, d.LngError
FROM MyTable t 
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

About

Geohash Functions for SQL Server

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages