GeoDjango Installation

GeoDjango is an add-on for Django that turns it into a world-class geographic web framework. GeoDjango strives to make at as simple as possible to create geographic web applications, like location-based services. Some features include:

  1. Django model fields for OGC geometries, that may be edited in the admin.
  2. Extensions to Django’s ORM for the querying and manipulation of spatial data.
  3. Loosely-coupled, high-level Python interfaces for GIS geometry operations and data formats.


In general, GeoDjango installation requires:

  1. Python and Django
  2. Spatial Database
  3. Geospatial Libraries

and may be installed on most of modern computers managed by Linux, Windows and Mac OS X operating systems. In this article we are going to deal with GeoDjango installation on Mac OS X computers. That assumes a familiarity with MacPorts tool. Because MacPorts still builds the software from source, Xcode and X11 are required. 


Installation Summary:


$ sudo port sync

$ sudo port install python26

$ sudo port install postgresql84-server

$ sudo port install geos

$ sudo port install proj

$ sudo port install postgis

$ sudo port install libgeoip

$ sudo port install py26-psycopg2


PostgreSQL Configuring:


$ sudo mkdir /Users/DB/postgresql

$ export PATH=$PATH:/opt/local/lib/postgresql84/bin

$ echo 'export PATH=$PATH:/opt/local/lib/postgresql84/bin' >> ~/.profile

$ chown -R postgres:postgres /Users/DB/postgresql

$ sudo su postgres -c "initdb -E UTF8 -D /Users/DB/postgresql"


PostgreSQL Server Controls:


$ alias pgstart="sudo su postgres -c 'pg_ctl -D /Users/DB/postgresql -l /Users/DB/postgresql/logfile start'"

$ alias pgstop="sudo su postgres -c 'pg_ctl -D /Users/DB/postgresql stop -m fast'"

$ alias pgstatus="sudo su postgres -c 'pg_ctl status -D /Users/DB/postgresql'"

$ pgstart


PostGIS DB Template Creation:


$sudo su postgres

$ POSTGIS_SQL_PATH='pg_config —sharedir'/contrib

$ createdb -E UTF8 postqis_database_template

$ createlang -d postqis_database_template plpgsql

$ psql -d postgres -c "UPDATE pg_database SET datistemplate='true' WHERE datname='postqis_database_template';"

$ psql -d postqis_database_template -f $POSTGIS_SQL_PATH/postgis.sql

$ psql -d postqis_database_template -f $POSTGIS_SQL_PATH/spatial_ref_sys.sql

$ psql -d postqis_database_template -c "GRANT ALL ON geometry_columns TO PUBLIC;"

$ psql -d postqis_database_template -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;"


DB Creation:


$ createdb -T postqis_database_template [your_database_name]

$ createuser —createdb [local_user]