Friday, November 19, 2010

Weather forecast widget: Weather providers

The one of main parts of weather forecast widget is communication with weather provider.

I have found next providers (please let me know if you know another ones) that work only with the US cities (except Google weather):
Google weather API
Google provides API for getting weather data for US cities by name.
Next is the link to get weather data
http://www.google.com/ig/api?weather=City
The received weather data are stored in XML and contains next:
  • Information about received data (city name, state, forecast date)
  • Current weather conditions:
    • Conditions (Sunny, Rain, Cloudy, Showers etc)
    • Temperature (both Celsius and Fahrenheit)
    • Humidity (in percents)
    • Wind conditions
    • Weather icon (link to icon stored on Google)
  • Weather forecast for next few days:
    • Day of week of forecast (Mon, Tue, Wed etc)
    • Conditions (Rain, Cloudy, Showers etc) 
    • Low temperature (in Fahrenheit)
    • High temperature (in Fahrenheit)
    • Weather icon (link to icon stored on Google)
Here is a sample XML received for NY
<xml_api_reply version="1">
     <weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0"> 
        
<forecast_information>
            
<city data="New York, NY"/>
            
<postal_code data="new york,ny"/>
            
<latitude_e6 data=""/>
            
<longitude_e6 data=""/>
            
<forecast_date data="2010-05-20"/>
        
    <current_date_time data="2010-05-20 07:44:43 +0000"/>
        
    <unit_system data="US"/>
    
    </forecast_information>
        <current_conditions>
            <condition data="Cloudy"/>
            <temp_f data="59"/>
            <temp_c data="15"/>
            <humidity data="Humidity: 80%"/>
            <icon data="/ig/images/weather/cloudy.gif"/>
            <wind_condition data="Wind: N at 0 mph"/>
        </current_conditions>
        <forecast_conditions>
            <day_of_week data="Thu"/>
            <low data="61"/>
            <high data="79"/>
            <icon data="/ig/images/weather/sunny.gif"/>
            <condition data="Sunny"/>
            </forecast_conditions>
        <forecast_conditions>
            <day_of_week data="Fri"/>
            <low data="60"/>
            <high data="83"/>
            <icon data="/ig/images/weather/partly_cloudy.gif"/>
            <condition data="Partly Cloudy"/>
        </forecast_conditions>
    </weather>
</xml_api_reply>

Next are some Google weather icons:

WeatherForecast web service from www.webservicex.net
This web service supports the following two operations:
  • GetWeatherByPlaceName - returns weather forecast for a place name (US cities only)
  • GetWeatherByZipCode - returns weather forecast for a Zip Code (US only)
The first one looks like the Google Weather API defined above. Let investigate it.
To get weather forecast for city it is possible to use HTTP POST request, like this (for New York).
The received weather data are stored in XML:
  • Information about received data (city name, latitude & longitude, state)
  • Weather forecast for next week:
    • Date for forecast
    • Low temperature in Fahrenheit and Celsius
    • High temperature in Fahrenheit and Celsius
    • Weather icon (link to icon from forecast.weather.gov, see below NDFD)
As you can see, there are poor weather data, but they contain almost all that we need, excluding weather conditions.
Next is a sample XML for NY
<WeatherForecasts>
    
<Latitude>40.74838</Latitude>
     <Longitude>73.9967041</Longitude>
     <AllocationFactor>0.001051</AllocationFactor>
     <FipsCode>36</FipsCode>
     <PlaceName>NEW YORK</PlaceName>
     <StateCode>NY</StateCode>
     <Details>
          <WeatherData>
               <Day>Tuesday, May 25, 2010</Day>
               <WeatherImage>http://forecast.weather.gov/images/wtf/few.jpg</WeatherImage>
               <MaxTemperatureF>86</MaxTemperatureF>
               <MinTemperatureF>59</MinTemperatureF>
               <MaxTemperatureC>30</MaxTemperatureC>
               <MinTemperatureC>15</MinTemperatureC>
          </WeatherData>
          <WeatherData>
               <Day>Wednesday, May 26, 2010</Day>
               <WeatherImage>http://forecast.weather.gov/images/wtf/sct.jpg</WeatherImage>
               <MaxTemperatureF>92</MaxTemperatureF>
               <MinTemperatureF>66</MinTemperatureF>
               <MaxTemperatureC>33</MaxTemperatureC>
               <MinTemperatureC>19</MinTemperatureC>
          </WeatherData>
          <WeatherData>
               &lt;Day>Thursday, May 27, 2010</Day>
               <WeatherImage>http://forecast.weather.gov/images/wtf/sct.jpg</WeatherImage>
               <MaxTemperatureF>88</MaxTemperatureF>
               <MinTemperatureF>63</MinTemperatureF>
               &lt;MaxTemperatureC>31</MaxTemperatureC>
               <MinTemperatureC>17</MinTemperatureC>
          </WeatherData>
          &lt;WeatherData>
               <Day>Friday, May 28, 2010</Day>
               &lt;WeatherImage>http://forecast.weather.gov/images/wtf/tsra30.jpg</WeatherImage>
               <MaxTemperatureF>77</MaxTemperatureF>
               <MinTemperatureF>64</MinTemperatureF>
               <MaxTemperatureC>25</MaxTemperatureC>
               <MinTemperatureC>18</MinTemperatureC>
          </WeatherData>
          <WeatherData>
               <Day>Saturday, May 29, 2010</Day>
               <WeatherImage>http://forecast.weather.gov/images/wtf/scttsra30.jpg</WeatherImage>
               <MaxTemperatureF>73</MaxTemperatureF>
               <MinTemperatureF>61</MinTemperatureF>
               <MaxTemperatureC>23</MaxTemperatureC>
               <MinTemperatureC>16</MinTemperatureC>
          </WeatherData> 
     </Details>
</WeatherForecasts>

Note this Web service is unavailable time to time.

National Digital Forecast Database
National Digital Forecast Database (NDFD) SOAP web service provides data from the National Weather Service’s (NWS) digital forecast database. It uses XML to store weather data. The NDFD XML language is called Digital Weather Markup Language (DWML) and its schema can be found here.

NDFD web service contains a lot of functions to get weather data. This page uses one of them.

Next is the XML data for Baltimore, MD (please correct date in link) received from NDFDgenByDay
<dwml version="1.0" xsi:noNamespaceSchemaLocation="http://www.nws.noaa.gov/forecasts/xml/DWMLgen/schema/DWML.xsd">
    <head>
        <product srsName="WGS 1984" concise-name="dwmlByDay" operational-mode="official">
            <title> 
                NOAA's National Weather Service Forecast by 24 Hour Period
             </title>
            <field>meteorological</field>
            <category>forecast</category>
            <creation-date refresh-frequency="PT1H">2010-05-21T08:45:54Z</creation-date>
        </product>
        <source>
            <more-information>http://www.nws.noaa.gov/forecasts/xml/</more-information>
            <production-center> 
                Meteorological Development Laboratory
                <sub-center>Product Generation Branch</sub-center>
            </production-center>
            <disclaimer>http://www.nws.noaa.gov/disclaimer.html</disclaimer>
            <credit>http://www.weather.gov/</credit>
            <credit-logo>http://www.weather.gov/images/xml_logo.gif</credit-logo>
            <feedback>http://www.weather.gov/feedback.php</feedback>
        </source>
    </head>
    <data>
        <location>
            <location-key>point1</location-key>
            <point latitude="39.29" longitude="-76.61"/>
        </location>
        <moreWeatherInformation applicable-location="point1">
            http://forecast.weather.gov/MapClick.php?textField1=39.29&textField2=-76.61
        </moreWeatherInformation>
        <time-layout time-coordinate="local" summarization="24hourly">
            <layout-key>k-p24h-n2-1</layout-key>
            <start-valid-time>2010-05-21T06:00:00-04:00</start-valid-time>
            <end-valid-time>2010-05-22T06:00:00-04:00</end-valid-time>
            <start-valid-time>2010-05-22T06:00:00-04:00</start-valid-time>
            <end-valid-time>2010-05-23T06:00:00-04:00</end-valid-time>
        </time-layout>
        <time-layout time-coordinate="local" summarization="12hourly">
            <layout-key>k-p12h-n4-2</layout-key>
            <start-valid-time>2010-05-20T18:00:00-04:00</start-valid-time>
            <end-valid-time>2010-05-21T06:00:00-04:00</end-valid-time>
            <start-valid-time>2010-05-21T06:00:00-04:00</start-valid-time>
            <end-valid-time>2010-05-21T18:00:00-04:00</end-valid-time>
            <start-valid-time>2010-05-21T18:00:00-04:00</start-valid-time>
            <end-valid-time>2010-05-22T06:00:00-04:00</end-valid-time>
            <start-valid-time>2010-05-22T06:00:00-04:00</start-valid-time>
            <end-valid-time>2010-05-22T18:00:00-04:00</end-valid-time>
        </time-layout>
        <time-layout time-coordinate="local" summarization="24hourly">
            <layout-key>k-p2d-n1-3</layout-key>
            <start-valid-time>2010-05-21T06:00:00-04:00</start-valid-time>
            <end-valid-time>2010-05-23T06:00:00-04:00</end-valid-time>
        </time-layout>
        <parameters applicable-location="point1">
            <temperature type="maximum" units="Fahrenheit" time-layout="k-p24h-n2-1">
                <name>Daily Maximum Temperature</name>
                <value>86</value>
                <value>73</value>
            </temperature>
            <temperature type="minimum" units="Fahrenheit" time-layout="k-p24h-n2-1">
                <name>Daily Minimum Temperature</name>
                <value>63</value>
                <value>63</value>
            </temperature>
            <probability-of-precipitation type="12 hour" units="percent" time-layout="k-p12h-n4-2">
                <name>12 Hourly Probability of Precipitation</name>
                <value>0</value>
                <value>0</value>
                <value>17</value>
                <value>39</value>
            </probability-of-precipitation>
            <weather time-layout="k-p24h-n2-1">
                <name>Weather Type, Coverage, and Intensity</name>
                <weather-conditions weather-summary="Partly Sunny"/>
                <weather-conditions weather-summary="Chance Thunderstorms">
                    <value coverage="chance" intensity="none" weather-type="thunderstorms" qualifier="none"/>
                    <value coverage="chance" intensity="light" additive="and" weather-type="rain showers" qualifier="none"/>
                </weather-conditions>
            </weather>
            <conditions-icon type="forecast-NWS" time-layout="k-p24h-n2-1">
                <name>Conditions Icons</name>
                <icon-link>
                    http://www.nws.noaa.gov/weather/images/fcicons/sct.jpg
                </icon-link>
                <icon-link>
                    http://www.nws.noaa.gov/weather/images/fcicons/tsra40.jpg
                </icon-link>
            </conditions-icon>
            <hazards time-layout="k-p2d-n1-3">
                <name>Watches, Warnings, and Advisories</name>
                <hazard-conditions xsi:nil="true"/>
            </hazards>
        </parameters>
    </data>
</dwml>

Next are some weather icons:

NDFD provides all necessary weather data for each point of the USA and I suppose all defined above providers use data from this one.
The disadvantage of using NDFD web service from Android, is the used DWML format for storing weather data. It is some difficult to parse it.

As for me, it's enough to use the Google provider - it provides as current condition as forecast for next few days stored in simple XML.

Note this post was created in May 2010; I planned to post it before, but did not have enough time to finish it. This is why there is used weather data for the May month.

No comments:

Post a Comment