Created
September 24, 2012 16:29
-
-
Save ajashton/3776859 to your computer and use it in GitHub Desktop.
This file contains 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 city_label_direction(geometry) | |
RETURNS INTEGER AS | |
$$ | |
SELECT Cast(Round(Degrees(ST_Azimuth(ST_ClosestPoint(geometry, $1),$1))) AS INTEGER) | |
FROM osm_places | |
WHERE geometry && ST_Expand($1, 200000) | |
AND scalerank > 0 | |
AND NOT ST_DWithin(geometry, $1, 1) | |
ORDER BY ST_Distance(geometry, $1) ASC | |
LIMIT 1 | |
$$ | |
LANGUAGE 'SQL' | |
STABLE; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment