Wednesday, June 4, 2008

GeoDjango on Slicehost: Installing Software (3 of 4)

This page goes through installing the necessary software applications for running GeoDjango.


Python 2.5 is installed by default with Ubuntu 8.04. Ok, that was easy, lets move on to something else...

Apache HTTP Server


Install the Apache packages...
sudo aptitude install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 ssl-cert python-central libapache2-mod-python

Edit the Apache configuration file...
sudo nano /etc/apache2/apache2.conf

Add this line to the end of apache2.conf (replace 'myslice' with whatever you named your slice)
ServerName myslice

Restart Apache...
sudo apache2ctl graceful
sudo /etc/init.d/apache2 restart

The Apache Web server should have started. Verify this by browsing to http://11.222.333.444
You should see the following message...
It Works!


Install the subversion application from the repository...
sudo apt-get install subversion


Checkout the GeoDjango code...
svn co ~/django_gis

Setup a symbolic links so that Python knows how to find the GeoDjango code and the shell knows how to find the Django admin script.
sudo ln -s ~/django_gis/django /usr/lib/python2.5/site-packages/django
sudo ln -s ~/django_gis/django/bin/ /usr/local/bin

Test that the Django Admin script can be found by entering the following... help
... which should return a help message.


Install the PostgreSQL packages...
sudo aptitude install postgresql python-psycopg2 postgresql-server-dev-8.3 flex

Test to see that PostgreSQL is working...
sudo -u postgres psql postgres

Welcome to psql 8.3.1, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help with psql commands \g or terminate with semicolon to execute query \q to quit
postgres=# \q

Next we need to alter the default configuration to allow django to connect to the postgres server.
sudo nano /etc/postgresql/8.3/main/pg_hba.conf

Update the access records to the following...
# Database administrative login by UNIX sockets
local   all         postgres                          ident sameuser

# "local" is for Unix domain socket connections only
#local   all         all                               ident sameuser
local   all     all     password

# IPv4 local connections:
#host    all         all          md5
host    all     all password

# IPv6 local connections:
#host    all         all         ::1/128               md5

Restart the PostgreSQL server, so that it loads the new access configuration...
sudo /etc/init.d/postgresql-8.3 restart

GEOS, proj4, PostGIS, and GDAL

(Refs: and

First, make a directory for downloading source code...
mkdir ~/downloads

The following commands download, build, and install the GEOS, proj4, PostGIS, and GDAL libraries. Run them all at once if you are feeling lucky, or one at a time if you want to watch the messages. Time to get a cup of coffee... this takes a while.
cd ~/downloads
tar xjf geos-3.0.0.tar.bz2
cd geos-3.0.0
sudo make install
cd ~/downloads
tar xzf proj-4.6.0.tar.gz
cd ~/downloads/proj-4.6.0/nad
tar xzf ../../proj-datumgrid-1.3.tar.gz
cd ~/downloads/proj-4.6.0
sudo make install
cd ~/downloads
tar xzf postgis-1.3.3.tar.gz
cd postgis-1.3.3
sudo make install
cd ~/downloads
tar xzf gdal-1.5.1.tar.gz
cd gdal-1.5.1
./configure --datadir=/usr/local/share
sudo make install

The GEOS library is now available in /usr/local/include/
The Proj4 files are now in /usr/local/bin/proj/

Update the shared library configuration file...
sudo nano /etc/

and add the following line to the end

Update the shared libraries...
sudo /sbin/ldconfig

Test that GDAL is installed correctly...

Usage: gdalinfo [--help-general] [-mm] [-stats] [-nogcp] [-nomd] [-noct] [-checksum] [-mdd domain]* datasetname

Test that Python, Django, GDAL, and GEOS are all working together

Start up Python...

Python 2.5.2 (r252:60911, Apr 21 2008, 11:17:30) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information.

Check to see if Python can use the GDAL library...
>>> from django.contrib.gis.gdal import HAS_GDAL
>>> print HAS_GDAL

>>> from django.contrib.gis.tests import test_gdal >>>
....................... BEGIN - expecting IllegalArgumentException; safe to ignore. ERROR 1: IllegalArgumentException: points must form a closed linestring END - expecting IllegalArgumentException; safe to ignore. ...................... ---------------------------------------------------------------------- Ran 45 tests in 0.094s OK

Now check to see if Python can use the GEOS library...
>>> from django.contrib.gis.tests import test_geos

Testing WKT output. ... ok Testing HEX output. ... ok Testing KML output. ... ok Testing the Error handlers. ... BEGIN - expecting GEOS_ERROR; safe to ignore. GEOS_ERROR: ParseException: Expected number but encountered ',' GEOS_ERROR: ParseException: Unknown WKB type 255 END - expecting GEOS_ERROR; safe to ignore. GEOS_ERROR: ParseException: Unexpected EOF parsing WKB ok Testing WKB output. ... ok Testing creation from HEX. ... ok Testing creation from WKB. ... ok Testing EWKT. ... ok Testing GeoJSON input/output (via GDAL). ... ok Testing equivalence with WKT. ... ok Testing Point objects. ... ok Testing MultiPoint objects. ... ok Testing LineString objects. ... ok Testing MultiLineString objects. ... ok Testing LinearRing objects. ... ok Testing Polygon objects. ... ok Testing MultiPolygon objects. ... BEGIN - expecting GEOS_NOTICE; safe to ignore. GEOS_NOTICE: Duplicate Rings at or near point 60 300 END - expecting GEOS_NOTICE; safe to ignore. ok Testing Geometry __del__() on rings and polygons. ... ok Testing Coordinate Sequence objects. ... ok Testing relate() and relate_pattern(). ... ok Testing intersects() and intersection(). ... ok Testing union(). ... ok Testing difference(). ... ok Testing sym_difference(). ... ok Testing buffer(). ... ok Testing the SRID property and keyword. ... ok Testing the mutability of Polygons and Geometry Collections. ... ok Testing three-dimensional geometries. ... ok Testing the distance() function. ... ok Testing the length property. ... ok Testing empty geometries and collections. ... ok Testing `ogr` and `srs` properties. ... ok Testing use with the Python `copy` module. ... ok Testing `transform` method. ... ok Testing `extent` method. ... ok Testing pickling and unpickling support. ... ok ---------------------------------------------------------------------- Ran 36 tests in 0.246s OK

If the tests ran correctly, you now have GeoDjango installed. You can now proceed to Part 4 - Creating a GeoDjango project.

No comments:

Post a Comment