I’m working on a weather app for Android. The data for wind direction that I get from the weather API is in form of degrees (0 to 360). I want to display wind direction in a user-friendly format such as N (North), NNE (North-northeast), NE (Northeast), ENE (East-Northeast), E (East), ESE (East-Southeast), SE (Southeast), SSE (South-Southeast), S (South), SSW (South-Southwest), SW (Southwest), WSW (West-Southwest), W (West), WNW (West-Northwest), NW (Northwest), and NNW (North-Northwest). I think this is more user-friendly, at least when compared to degrees format.
16-wind compass rose
The eight half-winds are the points obtained by bisecting the angles between the principal winds. The half-winds are north-northeast (NNE), east-northeast (ENE), east-southeast (ESE), south-southeast (SSE), south-southwest (SSW), west-southwest (WSW), west-northwest (WNW) and north-northwest (NNW). Notice that the name is constructed simply by combining the names of the principal winds to either side, with the cardinal wind coming first, the ordinal wind second. The eight principal winds and the eight half-winds together yield a 16-wind compass rose, with each compass point at a 22 1⁄2° angle from the next.
And here is the Java method that I prepared so I can convert direction data from degrees into directions (16-wind compass rose):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
public String convertDegreeToCardinalDirection(int directionInDegrees){ String cardinalDirection = null; if( (directionInDegrees >= 348.75) && (directionInDegrees <= 360) || (directionInDegrees >= 0) && (directionInDegrees <= 11.25) ){ cardinalDirection = "N"; } else if( (directionInDegrees >= 11.25 ) && (directionInDegrees <= 33.75)){ cardinalDirection = "NNE"; } else if( (directionInDegrees >= 33.75 ) &&(directionInDegrees <= 56.25)){ cardinalDirection = "NE"; } else if( (directionInDegrees >= 56.25 ) && (directionInDegrees <= 78.75)){ cardinalDirection = "ENE"; } else if( (directionInDegrees >= 78.75 ) && (directionInDegrees <= 101.25) ){ cardinalDirection = "E"; } else if( (directionInDegrees >= 101.25) && (directionInDegrees <= 123.75) ){ cardinalDirection = "ESE"; } else if( (directionInDegrees >= 123.75) && (directionInDegrees <= 146.25) ){ cardinalDirection = "SE"; } else if( (directionInDegrees >= 146.25) && (directionInDegrees <= 168.75) ){ cardinalDirection = "SSE"; } else if( (directionInDegrees >= 168.75) && (directionInDegrees <= 191.25) ){ cardinalDirection = "S"; } else if( (directionInDegrees >= 191.25) && (directionInDegrees <= 213.75) ){ cardinalDirection = "SSW"; } else if( (directionInDegrees >= 213.75) && (directionInDegrees <= 236.25) ){ cardinalDirection = "SW"; } else if( (directionInDegrees >= 236.25) && (directionInDegrees <= 258.75) ){ cardinalDirection = "WSW"; } else if( (directionInDegrees >= 258.75) && (directionInDegrees <= 281.25) ){ cardinalDirection = "W"; } else if( (directionInDegrees >= 281.25) && (directionInDegrees <= 303.75) ){ cardinalDirection = "WNW"; } else if( (directionInDegrees >= 303.75) && (directionInDegrees <= 326.25) ){ cardinalDirection = "NW"; } else if( (directionInDegrees >= 326.25) && (directionInDegrees <= 348.75) ){ cardinalDirection = "NNW"; } else { cardinalDirection = "?"; } return cardinalDirection; } |