Skip to content

Instantly share code, notes, and snippets.

@ajashton
Created September 24, 2012 16:29
Show Gist options
  • Save ajashton/3776859 to your computer and use it in GitHub Desktop.
Save ajashton/3776859 to your computer and use it in GitHub Desktop.
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