Database Reference
In-Depth Information
at least a weather stationstation =
js_data['list'][0]print 'Data from
weather station %s' % station['name']if
'main' in station:if 'temp' in
station['main']:temperature =
station['main']['temp'] - 273.15 # we
want the temperature in
Celsiuselse:temperature =
Noneelse:temperature = Nonereturn
temperature
$$ LANGUAGE plpythonu;
3. Now, test your function; for example, get the temperature from the closest
weather station to Wat Pho Templum in Bangkok:
postgis_cookbook=# SELECT
chp08.GetWeather(100.49, 13.74);getweather
------------
27.22
(1 row)
4. IncaseyouwanttogetthetemperatureforthepointfeaturesinaPostGIS
table, you can use the coordinates of each feature's geometry:
postgis_cookbook=# SELECT name,
temperature,
chp08.GetWeather(ST_X(the_geom),
ST_Y(the_geom)) AS temperature2 FROM
chp08.cities LIMIT 5;
name | temperature | temperature2
-------------+-------------+--------------
Minneapolis | 275.15 | 15
Saint Paul | 274.15 | 16
Buffalo | 274.15 | 19.44
New York | 280.93 | 19.44
Jersey City | 282.15 | 21.67
(5 rows)
Search WWH ::




Custom Search