Broadcast on Broadcast off
The Documentation for Project Zero has moved. Please update your bookmarks to: http://www.projectzero.org/documentation/
Table of
Contents...
Hide

Project Zero Developer’s Guide

Concepts and components
Basic concepts overview
Event processing
Writing Java handlers
Writing Groovy handlers
Firing events
Global Context
Global Context reference
Application directory layout
Virtualized directories
Assemble
PHP
Features and configuration
Configuration
Debugging
Dependencies
Packaging
Application classpath
Logging and tracing
RESTful resources
RESTful documentation
File serving
Response rendering
Validators and validation
HTTP error handling
Calling a remote resource
Using the Connection API
Sending an email using EmailConnection
Configuring destinations
Configuring protocols
Configuring connection handlers
Creating a connection handler
Creating a custom protocol transport
Simple logging connection handlers
Protocol reference
Client programming with Dojo
Runtime options
Deployment modifications
HTTP configuration
SSL configuration
Proxy configuration
Extending the CLI
Security considerations
Authentication
OpenID authentication
Extending security
Security tokens
CSRF prevention support
Extending token support
Leveraging TAI
User service
File based user service
LDAP user service
Extending user service
Security Utilities
Leveraging XOREncoder
Extensions
Atom support
RSS support
JSON support
XMLEncoder
REST to SOAP extension
URIUtils
Developer Web tools
Database setup tools
Configuring data access
Common query patterns
Advanced query patterns
Update patterns
Local database transactions
Extending data access
Configuration vendor differences
PHP data access
Resource model
Configuring ZRM
Resource model declaration
Programmatic model API
HTTP REST API
A ZRM mini tutorial
Active content filtering support
Default filters
Custom filters
Runtime management
Management commands
Zero socket opener
Other extension modules
Amazon E-commerce service
Flickr service
WeatherZero forecast service
Wikipedia service
Reference
Zero command line interface
JavaDoc - Public API
JavaDoc - Public SPI
JavaDoc - All Classes

 

WeatherZero forecast service

This extension provides an easy way to get weather forecast data for a set of latitude and longitude points, for a given timespan. It is a wrapper for the NWS (National Weather Service) SOAP weather service: http://www.weather.gov/xml/. The extension creates the SOAP request to the NWS service and uses a SAX parser to perform the tasks described in this article.

Adding weatherZero to your project

To use the weatherZero extension, add it to your project. You can do this with the Project Zero tooling by editing your config/ivy.xml file. Add the weatherZero library to your dependencies. If you do not have the library installed, it is downloaded automatically when you save the ivy.xml file or the next time your resolve your project.

Requesting weather information

To perform a request, use the following call:

com.tripwx.forecasts.WeatherForecastRetriever:

public static Object getWeatherForecast(List pointsData, Date startTime, Date endTime)

Using the parameters

Use the following parameters for this call:

pointsData
This provides the List of Map objects with keys lat, lng, and optionally, time. The lat and lng pairs represent the decimal coordinates for each point, latitude and longitude, where a forecast is to be provided. The time object is a placeholder that specifies the time you want a forecast at each point, as shown in the following example:
     [
         {"lat": 35.77975, "lng": -78.64341, "time": 1201030680000}, 
         {"lat": 36.83412, "lng": -75.30676000000001, "time": 1201030680000}
         {"lat": 35.9767, "lng": -79.71538, "time": 1201030680000}
     ]
     

startTime
This is the Date object representing the beginning (time and date) of the timespan for which weather information is to be obtained for each of the specified (latitude and longitude pair) points.

endTime
This is the Date object representing the end (time and date) of the timespan for which weather information is to be obtained for each of the specified (latitude and longitude pair) points.

When this method is run, the weatherZero extension queries the NWS Web service for the weather data of each requested point for the timespan indicated by the startTime and endTime parameters. When the method completes, the global context contains weather information for each point for the entire time span. The information for a given point is located at the following location:

/request/wx/points#<POINT_NUMBER>
In this string, POINT_NUMBER is the index of the point in pointsData. At each such URI (for example, /request/wx/points#3) there is a map containing valueKeys as keys and Lists of weather data values as values. The Lists vary in length, as different types of weather information have different granularity of forecast time. For example, temperatures are given on 3 hour intervals, whereas precipitation probability is on a 12 hour interval. The XML document returned by the NWS service provides time layouts to detail how the list of values maps to the times. This mapping is abstracted by the weatherZero extension and the utility getter method that is described in the following section.

Using the valueKeys

The following valueKeys, both constant variable name in com.tripwx.forecasts.WxValueKeys, and String value, are provided:

ICONS_KEY = "icons"
Strings a URL to an icon depicting overall weather conditions
MAX_DAILY_TEMPS_KEY = "maxDailyTemps"
The integer maximum daily temperature in degrees Fahrenheit
MIN_DAILY_TEMPS_KEY = "minDailyTemps"
The integer minimum daily temperature in degrees Fahrenheit
HOURLY_TEMPS_KEY = "hourlyTemps"
The integer actual temperature in degrees Fahrenheit
APPARENT_TEMPS_KEY = "apparentTemps"
The integer apparent temperature in degrees Fahrenheit
DEWPOINT_TEMPS_KEY = "dewpointTemps"
The integer dewpoint in degrees Fahrenheit
CONDITIONS_KEY = "wxConditions"
The List of Strings describing weather conditions
CLOUD_COVER_KEY = "cloudCover"
The integer percentage of sky covered with clouds
WIND_DIRECTION_KEY = "windDirection"
The direction the wind is coming from in integer degrees (from true north, not magnetic north)
WIND_SPEED_KEY = "windSpeed"
The sustained wind speed (integer knots; mph=knots*1.15)
WIND_GUST_KEY = "windGust"
The wind gust speed (integer knots; mph=knots*1.15)
HUMIDITY_KEY = "humidity"
The relative humidity (integer percentage)
PRECIPITATION_PROBABILITY_KEY = "precipProbability"
The probability of precipitation in a 12 hour period
SNOW_KEY = "snow"
The inches of snow in a 6 hour period
RAIN_KEY = "rain"
The inches of rain in a 6 hour period

Getting results

Navigating all of this through global context URIs would be only slightly more fun than reading regular expressions, so a convenience method is provided. The signature is:

com.tripwx.forecasts.Utils:

public static Object getValueAtTime(String valueKey, int pointIndex, Date time)

Using the parameters

The following parameters are used for this signature:

valueKey
One of the valueKeys listed in the previous example that indicate which type of information to retrieve.
pointIndex
The index into the list of points initially provided to the getWeatherForecast() that resolves to the point for which weather is to be retrieved.
time
The Date object representing the time for which weather forecast information is to be retrieved for the specified point.

Additional resources

r5 - 08 Feb 2008 - 17:48:10 - marc
Syndicate this site RSS ATOM
Copyright 2007 © IBM Corporation | Privacy | Terms of Use | About this site