postgis.txt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.
  48. GeoDjango does not currently leverage any `PostGIS topology functionality`__.
  49. If you plan to use those features at some point, you can also install the
  50. ``postgis_topology`` extension by issuing ``CREATE EXTENSION
  51. postgis_topology;``.
  52. __ http://postgis.net/docs/Topology.html
  53. Managing the database
  54. ---------------------
  55. To administer the database, you can either use the pgAdmin III program
  56. (:menuselection:`Start --> PostgreSQL 9.x --> pgAdmin III`) or the
  57. SQL Shell (:menuselection:`Start --> PostgreSQL 9.x --> SQL Shell`).
  58. For example, to create a ``geodjango`` spatial database and user, the following
  59. may be executed from the SQL Shell as the ``postgres`` user::
  60. postgres# CREATE USER geodjango PASSWORD 'my_passwd';
  61. postgres# CREATE DATABASE geodjango OWNER geodjango;