Created
August 20, 2020 22:49
-
-
Save mohclips/c888f67cb8e0589e3812d69d2dc6c2fa to your computer and use it in GitHub Desktop.
sql frunction to convert degrees to N E S W compass points
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
DROP FUNCTION IF EXISTS deg_to_nesw; | |
DELIMITER // | |
CREATE FUNCTION deg_to_nesw(deg float) RETURNS char(3) DETERMINISTIC | |
-- based on: https://www.campbellsci.eu/blog/convert-wind-directions | |
BEGIN | |
SET @directions = 'N,NNE,NE,ENE,E,ESE,SE,SSE,S,SSW,SW,WSW,W,WNW,NW,NNW,N'; | |
RETURN substring_index(substring_index(@directions,',',Round((deg MOD 360)/ 22.5,0)+1),',', -1); | |
END | |
// | |
DELIMITER ; | |
select deg_to_nesw(72.8); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is quite clever too.
SELECT deg_to_nesw(seq*22.5) FROM seq_0_to_15 ;