span8
span4
span8
span4
This is another demo of the great web servicewww.geonames.organd examples ofJSONExploderandJSONExtractoruse.
GeoNameshas, 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&sou...
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 RMKAO2","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 RMKAO2","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 isjson["weatherObservations"][*]- it takes the array "weatherObservations" with the wildcard as an index, which means that all elements should be extracted into features.
The consecutive JSONExtractor transformers extract attribute values into newly created attributes.For example, the parameters 'JSON Query' set tojson["temperature"]and 'Target Attribute' set totemperaturewill create an attributetemperatureand 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 a DEM, the DEM helps in creating contours - this method gives better contours than direct contour generation from the original points.Contours are intersected by the area outline, and areas are built.最后一个步骤包括指定的温度reas and coloring.Coloring depends on the range of reported temperatures - the workspace tries to make a smooth continuous transition from blue to red.A bigger range gives a smoother picture.
To make sure that my workspace works correctly, I went to theAccuWeather web siteand compared my results to their temperature map.They show a really similar picture (except that my map has more details, and I like my design more :)
Note that the workspace makes a 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 anImageRasterizertransformer 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 than FME.Who knows, maybe one day we will be able to do so with Workbench?
Geocoding with FME Using Gisgraphy
Writing Incremental Updates to Cloud-Based Formats
How do I write updates to an existing ArcGIS Online feature service?
S3ObjectLister, S3Downloader, and S3Uploader transformers
Tutorial: Getting Started with JSON
© 2020 Safe Software Inc |Legal