Database Reference
In-Depth Information
weather data
cur = conn.cursor()
# iterate all of the cities in the cities
PostGIS layer, and for each of them
# grap the actual temperature from the
closest weather station, and add the 10
# closest stations to the city to the
wstation PostGIS layer
cur.execute("""SELECT ogc_fid, name,
ST_X(the_geom) AS long,
ST_Y(the_geom) AS lat FROM
chp08.cities;""")
for record in cur:
ogc_fid = record[0]
city_name = record[1]
lon = record[2]
lat = record[3]
stations = GetWeatherData(lon, lat)
print stations
for station in stations:
print station
station_id = station['id']
name = station['name']
# for weather data we need to
access the 'main' section in the json
# 'main': {'pressure': 990,
'temp': 272.15, 'humidity': 54}
if 'main' in station:
if 'temp' in station['main']:
temperature =
station['main']['temp']
else:
temperature = -9999 # in some
case the temperature is not available
#
"coord":{"lat":55.8622,"lon":37.395}
station_lat =
Search WWH ::




Custom Search