postgis.txt 2.9 KB

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