Importing the data
We are now ready to import our four sets of data into the DISTAL database. We will be using the techniques discussed in Chapter 3, Python Libraries for Geospatial Development, and Chapter 5, Working with Geospatial Data in Python, to read the data from these data sets, and then insert them into the database using the techniques we discussed in Chapter 6, GIS in the Database.
Let's work through each of the files in turn.
World Borders Dataset
The World Borders Dataset consists of a shapefile containing the outline of each country along with a variety of metadata, including the country's name in Latin-1 character encoding. We can import this directly into our countries
table using the following Python code for MySQL:
import os.path import MySQLdb import osgeo.ogr connection = MySQLdb.connect(user="...", passwd="...") cursor = connection.cursor() cursor.execute("USE distal") cursor.execute("DELETE FROM countries") cursor.execute("SET GLOBAL max_allowed_packet=52428800") srcFile...