Skip to content

Instantly share code, notes, and snippets.

@snerpton
Last active October 15, 2019 09:50
Show Gist options
  • Save snerpton/9a0f9f7f20210b7cefa6 to your computer and use it in GitHub Desktop.
Save snerpton/9a0f9f7f20210b7cefa6 to your computer and use it in GitHub Desktop.
Method to convert numeric wind direction to text e.g. 25 returns NNE
/// <summary>
/// Converts direction in degrees to a text based description, e.g. 25 returns NNE
/// </summary>
/// <param name="windDirectionDegrees">Direction in degrees</param>
/// <returns>Wind direction as text</returns>
private string GetWindDirection(double windDirectionDegrees)
{
if (windDirectionDegrees > 348.75 && windDirectionDegrees < 11.25)
{
return "N";
}
else if (windDirectionDegrees > 11.25 && windDirectionDegrees < 33.75)
{
return "NNE";
}
else if (windDirectionDegrees > 33.75 && windDirectionDegrees < 56.25)
{
return "NE";
}
else if (windDirectionDegrees > 56.25 && windDirectionDegrees < 78.75)
{
return "ENE";
}
else if (windDirectionDegrees > 78.75 && windDirectionDegrees < 101.25)
{
return "E";
}
else if (windDirectionDegrees > 101.25 && windDirectionDegrees < 123.75)
{
return "ESE";
}
else if (windDirectionDegrees > 123.75 && windDirectionDegrees < 146.25)
{
return "SE";
}
else if (windDirectionDegrees > 146.25 && windDirectionDegrees < 168.75)
{
return "SSE";
}
else if (windDirectionDegrees > 168.75 && windDirectionDegrees < 191.25)
{
return "S";
}
else if (windDirectionDegrees > 191.25 && windDirectionDegrees < 213.75)
{
return "SSW";
}
else if (windDirectionDegrees > 213.75 && windDirectionDegrees < 236.25)
{
return "SW";
}
else if (windDirectionDegrees > 236.25 && windDirectionDegrees < 258.75)
{
return "WSW";
}
else if (windDirectionDegrees > 258.75 && windDirectionDegrees < 281.25)
{
return "W";
}
else if (windDirectionDegrees > 281.25 && windDirectionDegrees < 303.75)
{
return "WNW";
}
else if (windDirectionDegrees > 303.75 && windDirectionDegrees < 326.25)
{
return "NW";
}
else if (windDirectionDegrees > 326.25 && windDirectionDegrees < 348.75)
{
return "NNW";
}
else
{
return "undefined";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment