2012-10-19 16:19:17 +00:00
|
|
|
==================
|
|
|
|
Installing PostGIS
|
|
|
|
==================
|
|
|
|
|
|
|
|
`PostGIS`__ adds geographic object support to PostgreSQL, turning it
|
|
|
|
into a spatial database. :ref:`geosbuild`, :ref:`proj4` and
|
|
|
|
:ref:`gdalbuild` should be installed prior to building PostGIS. You
|
|
|
|
might also need additional libraries, see `PostGIS requirements`_.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
2014-02-28 16:44:03 +00:00
|
|
|
The `psycopg2`_ module is required for use as the database adapter
|
2012-10-19 16:19:17 +00:00
|
|
|
when using GeoDjango with PostGIS.
|
|
|
|
|
|
|
|
.. _psycopg2: http://initd.org/psycopg/
|
2015-03-17 22:34:15 +00:00
|
|
|
.. _PostGIS requirements: http://postgis.net/docs/manual-2.1/postgis_installation.html#install_requirements
|
2012-10-19 16:19:17 +00:00
|
|
|
|
|
|
|
On Debian/Ubuntu, you are advised to install the following packages:
|
|
|
|
postgresql-x.x, postgresql-x.x-postgis, postgresql-server-dev-x.x,
|
|
|
|
python-psycopg2 (x.x matching the PostgreSQL version you want to install).
|
|
|
|
Please also consult platform-specific instructions if you are on :ref:`macosx`
|
|
|
|
or :ref:`windows`.
|
|
|
|
|
|
|
|
Building from source
|
|
|
|
====================
|
|
|
|
|
|
|
|
First download the source archive, and extract::
|
|
|
|
|
2015-03-17 22:34:15 +00:00
|
|
|
$ wget http://download.osgeo.org/postgis/source/postgis-2.1.5.tar.gz
|
|
|
|
$ tar xzf postgis-2.1.5.tar.gz
|
|
|
|
$ cd postgis-2.1.5
|
2012-10-19 16:19:17 +00:00
|
|
|
|
|
|
|
Next, configure, make and install PostGIS::
|
|
|
|
|
|
|
|
$ ./configure
|
|
|
|
|
|
|
|
Finally, make and install::
|
|
|
|
|
|
|
|
$ make
|
|
|
|
$ sudo make install
|
|
|
|
$ cd ..
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
GeoDjango does not automatically create a spatial database. Please consult
|
2015-03-17 15:16:50 +00:00
|
|
|
the section on :ref:`spatialdb_template91` for more information.
|
2012-10-19 16:19:17 +00:00
|
|
|
|
2014-12-19 17:07:03 +00:00
|
|
|
__ http://postgis.net/
|
2012-10-19 16:19:17 +00:00
|
|
|
|
|
|
|
Post-installation
|
|
|
|
=================
|
|
|
|
|
|
|
|
.. _spatialdb_template:
|
|
|
|
.. _spatialdb_template91:
|
|
|
|
|
2015-03-17 15:16:50 +00:00
|
|
|
Creating a spatial database
|
|
|
|
---------------------------
|
2012-10-19 16:19:17 +00:00
|
|
|
|
2015-12-23 16:47:40 +00:00
|
|
|
PostGIS 2 includes an extension for PostgreSQL that's used to enable spatial
|
|
|
|
functionality::
|
2012-10-19 16:19:17 +00:00
|
|
|
|
|
|
|
$ createdb <db name>
|
|
|
|
$ psql <db name>
|
|
|
|
> CREATE EXTENSION postgis;
|
|
|
|
|
2015-09-10 22:37:58 +00:00
|
|
|
The database user must be a superuser in order to run
|
2015-09-12 20:27:30 +00:00
|
|
|
``CREATE EXTENSION postgis;``. The command is run during the :djadmin:`migrate`
|
2016-09-01 13:59:33 +00:00
|
|
|
process. An alternative is to use a migration operation in your project::
|
|
|
|
|
2016-09-28 18:24:49 +00:00
|
|
|
from django.contrib.postgres.operations import CreateExtension
|
2016-09-01 13:59:33 +00:00
|
|
|
from django.db import migrations
|
|
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
|
|
|
operations = [
|
|
|
|
CreateExtension('postgis'),
|
|
|
|
...
|
|
|
|
]
|
2015-09-10 22:37:58 +00:00
|
|
|
|
2015-04-21 15:54:38 +00:00
|
|
|
GeoDjango does not currently leverage any `PostGIS topology functionality`__.
|
|
|
|
If you plan to use those features at some point, you can also install the
|
|
|
|
``postgis_topology`` extension by issuing ``CREATE EXTENSION
|
|
|
|
postgis_topology;``.
|
|
|
|
|
|
|
|
__ http://postgis.net/docs/Topology.html
|
2012-10-19 16:19:17 +00:00
|
|
|
|
|
|
|
Managing the database
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
To administer the database, you can either use the pgAdmin III program
|
2013-02-23 15:40:19 +00:00
|
|
|
(:menuselection:`Start --> PostgreSQL 9.x --> pgAdmin III`) or the
|
|
|
|
SQL Shell (:menuselection:`Start --> PostgreSQL 9.x --> SQL Shell`).
|
2012-10-19 16:19:17 +00:00
|
|
|
For example, to create a ``geodjango`` spatial database and user, the following
|
|
|
|
may be executed from the SQL Shell as the ``postgres`` user::
|
|
|
|
|
|
|
|
postgres# CREATE USER geodjango PASSWORD 'my_passwd';
|
2015-03-17 15:16:50 +00:00
|
|
|
postgres# CREATE DATABASE geodjango OWNER geodjango;
|