Version 16 (modified by fsgpr, 7 years ago) (diff)

Completely rewrote Short Version Instructions

TOC()?

GeoDjango Dependencies with Apt-get on Ubuntu

The GeoDjangoInstall wiki describes in detail how to install GeoDjango dependencies from source, which for many reasons is a great approach.

However, with Ubuntu releases you can also use the Synaptic Package Manager (apt-get install on the command line) to handle some of the installation work for you. In the next version of Ubuntu (8.10), it will likely be possible to install almost everything needed using Synaptic as libraries are updated.

  • Note: if you take this route, be advised that the location of install directories will differ significantly from the source install approach. ie. PostGIS will be installed inside the PostgreSQL contrib and share directories specific to the PostgreSQL version number.

This writeup is based on Ubuntu 8.04 LTS. Any readers should update this document based on their experience from this version and note differences with newer versions.

Short Version

The following is a list of commands to enter into the Terminal to install GeoDjango on Ubuntu. For more detailed explanations on the installation process see the GeoDjangoInstall wiki.

 * #Download and Install the latest version of Django
 * cd ~
 * wget http://www.djangoproject.com/download/1.0-beta-1/tarball/
 * tar xzvf Django-1.0-beta_1.tar.gz 
 * sudo python ~/Django-1.0-beta_1/setup.py install  #Enter password to give root privileges as prompted throughout the installation
 * #Install Apache2, PsycoPg2, PostGreSQL, PostGIS, build-essential [to be able to compile libraries], and Mod_Python
 * sudo apt-get install apache2 python-psycopg2 postgresql build-essential libapache2-mod-python postgresql-8.3-postgis #Press 'y' to confirm download
 * wget http://download.osgeo.org/gdal/gdal-1.5.2.tar.gz #The version in the Repositories is currently not new enough for GeoDjango
 * wget http://download.osgeo.org/geos/geos-3.0.0.tar.bz2  #The version in the Repositories is currently not new enough for GeoDjango
 * tar xzvf gdal-1.5.2.tar.gz
 * cd gdal-1.5.2
 * ./configure --datadir=/usr/local/share/gdal
 * make
 * sudo make install
 * cd ~
 * bzip2 -dc geos-3.0.0.tar.bz2 | tar -x
 * cd geos-3.0.0
 * ./configure
 * make
 * sudo make install       
 * sudo cp /usr/share/gcs.csv /usr/local/share/
 * sudo pico /etc/postgresql/8.3/main/pg_hba.conf #Edit to allow Django Connections, as per the regular Django Docs
 * sudo pico /etc/apache2/sites-available/default #Edit to Create Django Locations, as per the regular Django Docs 

Create your PostGIS enabled PostGreSQL db

 * sudo su postgres
 * createuser [username]   
 * psql 
     * alter user [username] with password '[password]';
     * \q
 * createdb [dbname]
 * createlang plpgsql [dbname]
 * psql -d [dbname] -f /usr/share/postgresql-8.3-postgis/lwpostgis.sql
 * psql -d [dbname] -f /usr/share/postgresql-8.3-postgis/spatial_ref_sys.sql

Full Instructions

Step 1

Install Needed Programs using apt-get or Synaptic

apt-get install apache2 python-psycopg2 postgresql build-essential libapache2-mod-python postgresql-8.3-postgis   #Or install using Synaptic

Step 2

  • Open up access in the pg_hba.conf file
    sudo pico /etc/postgresql/8.3/main/pg_hba.conf #Alternatively use gedit or a text editor of your choice  
    # change ident sameuser to trust - WARNING SECURITY RISK
    # comment out this line to allow, for instance, to django/psycopg2 to connect without password
    local   all         postgres                          ident sameuser
    
    • Restart the server by switching into the default user
      sudo su - postgres
      pg_ctl -o -i -D /var/lib/postgresql/8.3/main/ restart
      

Step 3

Download needed libraries that do not have new enough versions in Synaptic

    wget gdal-1.5.2.tar.gz http://download.osgeo.org/gdal/
    wget geos-3.0.0 http://geos.refractions.net/downloads 

Step 4

Compile and install these libraries so GeoDjango can find them Extract gdal-1.5.2.tar.gz and geos-3.0.0 to folders on your Desktop and install::

    #in the gdal-1.5.2 directory
    ./configure --datadir=/usr/local/share/gdal
    make
    sudo make install

    #in the geos-3.0.0 directory
    ./configure
    make
    sudo make install       

    sudo cp /home/[Your Username]/geos-3.0.0/capi/libs/* /usr/lib/
    sudo cp /usr/share/gdal/gcs.csv /usr/local/share/

Step 5

Create your PostGIS template_postgis database

# Switch to the default postgres user
sudo su - postgres
# Create a template database with UTF encoding owned by the postgres user (or your user of choice)
createdb -E UTF8 -O postgres -U postgres template_postgis
# Now you can switch back to your normal user
exit
# Load the required procedural language for postgis
createlang plpgsql -d template_postgis -U postgres

Now you are ready to actually load the postgis functions and tables as sql inserts

  • Note: the two postgis sql files (lwpostgis.sql and spatial_ref_sys.sql) were likely installed in the postgres share directory
    pg_config --sharedir # will give you that dir
    # Also look in:
    ls /usr/share/ # or /usr/local/share/
    

Try:

psql -d template_postgis -U postgres -f /usr/share/postgresql-8.3-postgis/lwpostgis.sql
# Note: ignore any NOTICES, like 'psql:/usr/share/lwpostgis.sql:44: NOTICE:  type "histogram2d" is not yet defined'
  • You should see output like:
    BEGIN
    CREATE FUNCTION
    CREATE OPERATOR
    [...]
    CREATE TYPE
    CREATE AGGREGATE
    COMMIT
    
  • If you get an error about not being able to find geos add /usr/local/lib to /etc/ld.so.conf and run:
    ldconfig # Then restart PostgreSQL
    

Then load the geographic projections table:

psql -d template_postgis -U postgres -f /usr/share/postgresql-8.3-postgis/spatial_ref_sys.sql

Whoa! Hopefully that worked, and you will only have to do it once!

From then on create a PostGIS database like:

createdb -U postgres -T template_postgis DB_NAME

Step 6

Return to GeoDjangoInstall for troubleshooting and tests for GDAL and GEOS (see bottom of page)

Step 7

Check out MapServer, Mapnik, and OpenLayers, open source mapping applications recommended for use with GeoDjango.

Install these and a few other helpful utilities with:

sudo apt-get install cgi-mapserver python-gdal python-mapscript
Back to Top