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

Started major updates and revamping for Ubuntu 8.04 LTS

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

  • Install Django 1.0 or later
  • Using apt-get or Synaptic, install apache2, python-psycopg2, postgresql, build-essential, libapache2-mod-python, postgresql-8.3-postgis
  • Edit /etc/postgresql/8.3/main/pg_hba.conf to allow django connections
  • Edit /etc/apache2/sites-available/default when creating your first GeoDjango app
  • Download, compiles and install GDAL and GEOS libraries
  • Create your PostGIS enabled PostgreSQL db
  • Proceed with writing your first GeoDjango app

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 5

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 4

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 5

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

Step 6

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
Note: See TracWiki for help on using the wiki.
Back to Top