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 http://www.openweatherdata.org/, which is a web service that provides free weather data and a 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 http://www.openweatherdata.org/ web service API, getting the output in 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...