O'Reilly logo

Python Geospatial Analysis Essentials by Erik Westra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Setting up a spatial database

When accessing a database using psycopg2, we first have to specify which database we are going to use. This means that the database must exist before your Python code can use it. To set everything up, we'll use the Postgres command-line utilities. Type the following into your terminal or command-line window:

% createdb world_borders

Tip

Don't forget to include the -U postgres option, or sudo, if you need to access Postgres under a different user account.

This creates the database itself. We next want to enable the PostGIS spatial extension for our database. To do this, enter the following command:

% psql -d world_borders -c "CREATE EXTENSION postgis;"

Now that we've set up the database itself, let's create the table within ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required