WeatherMap
From fmepedia
This is another demo of the great web service www.geonames.org and examples of JSONExploder and JSONExtractor use.
GeoNames (http://www.geonames.org) has, among many others, a service that returns the most recent weather information from weather stations within a bounding box. My example takes a feature representing the continental part of the United States, buffers it, extracts coordinates of northern , southern, eastern and western sides, and forms and sends the following URL to the service:
http://ws.geonames.org/weatherJSON?north=52.38&south=22.12&east=-63.95&west=-127.73&maxRows=500
As you can see, the URL contains the word JSON. This means that the results are sent back in this format and assigned to an attribute (_url_contents in my example). We have two transformers that handle JSON, which looks as follows (just a small portion):
{"weatherObservations":[{"clouds":"n/a","weatherCondition":"n/a",
"observation":"K1P1 190540Z AUTO 00000KT 10SM CLR 01/00 A3004 RMK
AO2","windDirection":0,"ICAO":"K1P1","lng":-71.75,"temperature":"1",
"dewPoint":"0","windSpeed":"00","humidity":93,"stationName":"Plymouth,
Plymouth Municipal Airport","datetime":"2008-04-19 07:40:00",
"lat":43.7833333333333},{"clouds":"n/a","weatherCondition":"n/a",
"observation":"KAFP 190540Z AUTO 21004KT 10SM CLR 16/07 A3002 RMK
AO2","windDirection":210,"ICAO":"KAFP","lng":-80.0677777777778,
"temperature":"16","dewPoint":"7","windSpeed":"04","humidity":55,
"stationName":"Wadesboro, Anson County Airport","datetime":"2008-04-19
07:40:00","lat":35.0169444444444}...
It is quite hard to read, isn't it? The first transformer, JSONExploder, will split the attribute into separate features, the number of which is defined by maxRows parameter in the URL and the number of available weather stations. The JSON query for that is json["weatherObservations"][*] - it takes the array "weatherObservation" with the wildcard as an index, which means that all elements should be extracted into features.
The consecutive JSONExtractor transformers extract attribute values into the newly created attributes. For example, the parameters 'JSON Query' set to json["temperature"] and 'Target Attribute' set to temperature will create an attribute temperature and fill it with the temperature at the weather station. Check the workspace to see all the attributes that are extracted, but two of them - lat and lng allow us to create points.
The rest is simple - points are used for building DEM, DEM helps creating contours - this way gives better contours than direct contour generation from the original points. Contours are intersected by the area outline, and areas are built. The last steps include assigning temperatures to areas and coloring. Coloring depends on the range of reported temperatures - the workspace tries to make a smooth continuous transition from blue to red. Bigger range gives smoother picture.
To make sure that my workspace works correctly, I went AccuWeather web site (http://www.accuweather.com) and compared my results with their temperature map. They show really similar picture (except that my map has more details, and I like my design more :)
Note that the workspace makes the map where colored areas can go outside the States boundary - clipping them slows down the running time significantly.
The workspace is attached. It can be easily modified for making maps of other areas. Simply replace the datasource I use with your own, and don't forget to restore all the connections. I tried a few other countries such as France, Germany, Canada, India etc - in most cases they look quite good, although some weather stations return obviously incorrect results, and this distorts the whole picture. For example, in Canada, I found a station far North reporting temperatures around 30° Celsius, and another station in India showing only 0° at the Indian Ocean coast. For these situations you may want to add a Tester transformer, which would exclude such stations.
With an ImageRasterizer transformer we can generate a series of rasters depicting the temperature change over a certain period of time. After that we can create an animated map, but for that purpose we need some other tools rather than FME. Who knows, maybe one day we will be able to do so with Workbench?
The animated GIF is about 2 mb. It shows how the temperatures were changing since April 22 to April 25, 2008:
