You are here

function weather_bearing_to_text in Weather 7

Same name and namespace in other branches
  1. 5.6 weather.module \weather_bearing_to_text()
  2. 6.5 weather.module \weather_bearing_to_text()
  3. 7.3 weather_theme.inc \weather_bearing_to_text()
  4. 7.2 weather_theme.inc \weather_bearing_to_text()

Converts a compass bearing to a text direction.

This function can be used to get a text representation of a compass bearing (for example, 0° North, 86° East, ...).

Parameters

string $bearing: Compass bearing in degrees.

boolean $abbreviated: If true, return abbreviated directions (N, NNW) instead of full text (North, North-Northwest). Defaults to full text directions.

Return value

string Formatted representation.

2 calls to weather_bearing_to_text()
weather_format_nearest_station in ./weather_theme.inc
Format information about nearest METAR station.
weather_format_wind in ./weather_theme.inc
Convert wind.

File

./weather_theme.inc, line 406
Prepare themed weather output.

Code

function weather_bearing_to_text($bearing, $abbreviated = FALSE) {

  // Determine the sector. This works for 0° up to 348.75°
  // If the bearing was greater than 348.75°, perform a wrap (%16)
  $sector = floor(($bearing + 11.25) / 22.5) % 16;
  if (!$abbreviated) {
    $direction = array(
      t('North'),
      t('North-Northeast'),
      t('Northeast'),
      t('East-Northeast'),
      t('East'),
      t('East-Southeast'),
      t('Southeast'),
      t('South-Southeast'),
      t('South'),
      t('South-Southwest'),
      t('Southwest'),
      t('West-Southwest'),
      t('West'),
      t('West-Northwest'),
      t('Northwest'),
      t('North-Northwest'),
    );
  }
  else {
    $direction = array(
      t('N'),
      t('NNE'),
      t('NE'),
      t('ENE'),
      t('E'),
      t('ESE'),
      t('SE'),
      t('SSE'),
      t('S'),
      t('SSW'),
      t('SW'),
      t('WSW'),
      t('W'),
      t('WNW'),
      t('NW'),
      t('NNW'),
    );
  }
  return $direction[$sector];
}