The NOAA Weather Extension works with data provided by the U.S. National Oceanic and Atmospheric Administration (NOAA) and the National Weather Service (NWS). Features include:
This extension makes every effort to follow the NOAA/NWS web service usage guidelines, please be respectful and do the same.
This extension is tested and known to work out of the box with MAMP, WAMP, and common Linux distributions.
Extract the noaaWeather package into your application's protected/extensions directory and make sure the extension directory is named 'noaaWeather'. The extension must be installed under the 'ext.noaaWeather' path alias to work properly.
By default the extension will create a file cache repository in its own 'cache' subdirectory. This path must be writeable by the webserver. If required, the cache path can be configured by merging the following key into the application-level parameters array in the main web configuration file (main.php):
// application-level parameters that can be accessed // using Yii::app()->params['paramName'] 'params'=>array( // CFileCache uses this cachePath by default // Set to null to use the default application file cache path 'noaaWeather.cachePath' => 'protected/extensions/noaaWeather/cache' )
The extension is preconfigured to use an included sqlite database and should work with no configuration. If you need to use another database, import the sql files found in the extension's data subdirectory, then configure the database connection by merging the following key into the application-level parameters array:
// application-level parameters that can be accessed // using Yii::app()->params['paramName'] 'params'=>array( // CDBConnection uses this database configuration by default // Set this parameter to null to use the application database connection 'noaaWeather.dbConfig' => array( 'dsn' => 'sqlite:protected/extensions/noaaWeather/data/noaa_weather.db', 'username' => '', 'password' => '', ), )
Several widgets are included as examples. Start here if you just want to display weather information on your page.
Displays the latest observed conditions for the nearest NWS METAR station using a Yii portlet widget.

$this->widget('ext.noaaWeather.NoaaCurrentObservationsWidget',array( // Required location can be coordinates or a weather station 'location' => array('weatherStation' => 'KMWN'), // Optional params are passed to the view to customize the display 'params' => array( 'title' => 'Mount Washington Current Conditions', 'errorMsg' => 'Error fetching current conditions.', ), ) );
Displays summary forecast information using a Yii portlet widget.

$this->widget('ext.noaaWeather.NoaaForecastMapClickWidget',array( // Required location can be coordinates or a weather station 'location' => array('coordinates'=>array( 'latitude' => 44.27, 'longitude' => -71.3, )), // Optional params are passed to the view to customize the display 'params' => array( 'title' => 'Mount Washington Forecast', 'errorMsg' => 'Error fetching forecast.', 'dayOffset' => 0, 'numDays' => 5, ), ) );
Displays master/detail forecast information using a CJuiTabs widget.

$this->widget('ext.noaaWeather.NoaaForecastAllWidget',array( // Required location can be coordinates or a weather station 'location' => array('coordinates'=>array( 'latitude' => 44.27, 'longitude' => -71.3, )), // Optional params are passed to the view to customize the display 'params' => array( 'errorMsg' => 'Error fetching forecast.', 'dayOffset' => 0, 'numDays' => 6, ), ) );
The look and feel of noaaWeather widgets can be customized without changing the widget logic by providing your own css, view files, or icons and configuring the widget as follows:
$this->widget('ext.noaaWeather.NoaaForecastAllWidget',array( // Required location can be coordinates or a weather station 'location' => array('coordinates'=>array( 'latitude' => 44.27, 'longitude' => -71.3, )), // Optional parameters that customize display // The view file to load 'viewFile' => 'myViewFile', // The path to search for view files 'viewPath' => 'views/site/', // A published asset url 'assetUrl' => '/yii/published/url' // The name of the css file to register with the asset manager 'cssFile' => 'my.css', ) );
The NOAA Weather extension implements access to National Weather Service data in terms of Yii data providers that can be used within your application or to create your own weather widgets. Note that NOAA data providers will throw an exception if they cannot connect to the weather services they depend on and should always be wrapped in a try/catch statement.
This component gathers data from the NWS XML feeds of current weather conditions. It provides access to hourly observation data from NWS METAR stations across the US.
$currentDataProvider = Yii::createComponent( 'ext.noaaWeather.NoaaCurrentObservationsDataProvider', 'coordinates'=>array( 'latitude' => 44.27, 'longitude' => -71.3, ) ); $weather = $currentDataProvider->getData();
This component gathers data from the NWS map click forecast page. It provides access to the same familiar forecast information displayed when you search http://www.weather.gov/.
$mapClickDataProvider = Yii::createComponent( 'ext.noaaWeather.NoaaForecastMapClickDataProvider', 'coordinates'=>array( 'latitude' => 44.27, 'longitude' => -71.3, ) ); $weather = $mapClickDataProvider->getData();
This component gathers data from the NWS National Digital Forecast Database REST Service Single Point Summarized Data interface. It provides access to summarized forecast information.
$summaryDataProvider = Yii::createComponent( 'ext.noaaWeather.NoaaForecastSummaryDataProvider', 'coordinates'=>array( 'latitude' => 44.27, 'longitude' => -71.3, ) ); $weather = $summaryDataProvider->getData();
This component gathers data from the NWS National Digital Forecast Database REST Service Single Point Unsummarized Data interface. It provides access to detailed hourly forecast information.
$detailDataProvider = Yii::createComponent( 'ext.noaaWeather.NoaaForecastDetailDataProvider', 'coordinates'=>array( 'latitude' => 44.27, 'longitude' => -71.3, ) ); $weather = $detailDataProvider->getData();
The above data providers implement a getDataFormatted method that nomalizes weather data and formats it in an associative array rather than raw tabular format. Formatted arrays from multiple data providers can be merged using the php array_merge functions. See the noaaForecastAllWidget source code for an example.
This component provides the extension with access to the Yii database system. This is required to lookup METAR stations in the noaa_weather_stations table. This data comes from http://www.weather.gov/data/current_obs/index.xml
$weatherStations = Yii::createComponent('ext.noaaWeather.NoaaSqlDataProvider', 'SELECT * FROM noaa_weather_stations');
NOAA Weather behaviors implement shared functionality required to process weather data and can be attached to components when developing additional data providers. An overview of functionality is included here, see the class source files for more information.
Caches downloaded data to improve application performance and reduce the load on the NOAA servers.
Translates location data between formats using locator methods. Currently supports Latitude/Longitude and NWS Weather Station ID locators.
Parses a subset of the DWML xml schema.
Fetches data from the NOAA servers using the HTTP GET method. Failed downloads are retried using an exponential backoff method.
Title of Zii CJuiTabs Widget is not set properly. See issue 2885 for more information and workarounds.
Total 1 comment
Just beginning my story with this extension, and even from detailed description, it looks like an awesome piece of code! GREAT!
Just a small notice. Consider updating your ZIP archive. Right now it contains .git subdirectory (totally unnecessary AFAIK), which doubles its size (has 745 kB itself).
EDIT: Extension needs to be updated -- seems NOAA is sending PNGs file names right now and all icons in current version of extensions are JPGs, which ends up with missing file icon in widged.
Leave a comment
Please login to leave your comment.