Last active
September 25, 2015 18:05
-
-
Save stvno/d1caca08c7ca50fda95d to your computer and use it in GitHub Desktop.
SQL version of pointToTileFraction from https://github.com/mapbox/tilebelt/blob/master/index.js#L155
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create or replace function pointToTileFraction(float, float, integer) returns int[3] as $$ | |
declare | |
lon ALIAS FOR $1; | |
lat ALIAS FOR $2; | |
z ALIAS FOR $3; | |
result int[]; | |
BEGIN | |
result := array_append(result, floor(pow(2,z) * (lon / 360 + 0.5))::int); | |
result := array_append(result, floor(pow(2,z) * (0.5-0.25 *(log((1 + sin(lat*pi()/180))/(1 - sin(lat*pi()/180)))/pi())))::int); | |
result := array_append(result, z); | |
return result; | |
END; | |
$$ LANGUAGE 'plpgsql'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment