Writing PostGIS vector data with Psycopg
In this recipe, you will use Python combined with Psycopg, the most popular PostgreSQL database library for Python, in order to write some data to PostGIS using the SQL language.
You will write a procedure to import weather data for the most populated US cities. You will import such weather data from OpenWeatherData.org, which is a web service that provides free weather data and forecast API. The procedure you are going to write will iterate each major USA city and get the actual temperature for it from the closest weather stations using the OpenWeatherData.org Web service API, getting the output in the JSON format. (In case you are new to the JSON format, you can find details about it at http://www.json.org/.)
You will also generate a new PostGIS layer with the 10 closest weather stations to each city.
Getting ready
Create a database schema for the recipes in this chapter using the following command:
postgis_cookbook=# CREATE SCHEMA chp08;
Download the...