postgis.txt 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. The `psycopg2`_ module is required for use as the database adapter when using
  9. GeoDjango with PostGIS.
  10. On Debian/Ubuntu, you are advised to install the following packages:
  11. postgresql-x.x, postgresql-x.x-postgis, postgresql-server-dev-x.x,
  12. python-psycopg2 (x.x matching the PostgreSQL version you want to install).
  13. Alternately, you can `build from source`_. Consult the platform-specific
  14. instructions if you are on :ref:`macosx` or :ref:`windows`.
  15. .. _PostGIS: https://postgis.net/
  16. .. _psycopg2: http://initd.org/psycopg/
  17. .. _PostGIS requirements: https://postgis.net/docs/postgis_installation.html#install_requirements
  18. .. _build from source: https://postgis.net/docs/postgis_installation.html#install_short_version
  19. Post-installation
  20. =================
  21. .. _spatialdb_template:
  22. Creating a spatial database
  23. ---------------------------
  24. PostGIS 2 includes an extension for PostgreSQL that's used to enable spatial
  25. functionality::
  26. $ createdb <db name>
  27. $ psql <db name>
  28. > CREATE EXTENSION postgis;
  29. The database user must be a superuser in order to run
  30. ``CREATE EXTENSION postgis;``. The command is run during the :djadmin:`migrate`
  31. process. An alternative is to use a migration operation in your project::
  32. from django.contrib.postgres.operations import CreateExtension
  33. from django.db import migrations
  34. class Migration(migrations.Migration):
  35. operations = [
  36. CreateExtension('postgis'),
  37. ...
  38. ]
  39. GeoDjango does not currently leverage any `PostGIS topology functionality`__.
  40. If you plan to use those features at some point, you can also install the
  41. ``postgis_topology`` extension by issuing ``CREATE EXTENSION
  42. postgis_topology;``.
  43. __ https://postgis.net/docs/Topology.html
  44. Managing the database
  45. ---------------------
  46. To administer the database, you can either use the pgAdmin III program
  47. (:menuselection:`Start --> PostgreSQL 9.x --> pgAdmin III`) or the
  48. SQL Shell (:menuselection:`Start --> PostgreSQL 9.x --> SQL Shell`).
  49. For example, to create a ``geodjango`` spatial database and user, the following
  50. may be executed from the SQL Shell as the ``postgres`` user::
  51. postgres# CREATE USER geodjango PASSWORD 'my_passwd';
  52. postgres# CREATE DATABASE geodjango OWNER geodjango;