install.txt 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  1. .. _ref-gis-install:
  2. ======================
  3. GeoDjango Installation
  4. ======================
  5. .. highlight:: console
  6. Overview
  7. ========
  8. In general, GeoDjango installation requires:
  9. 1. :ref:`Python and Django <django>`
  10. 2. :ref:`spatial_database`
  11. 3. :ref:`geospatial_libs`
  12. Details for each of the requirements and installation instructions
  13. are provided in the sections below. In addition, platform-specific
  14. instructions are available for:
  15. * :ref:`macosx`
  16. * :ref:`ubuntudebian`
  17. * :ref:`windows`
  18. .. admonition:: Use the Source
  19. Because GeoDjango takes advantage of the latest in the open source geospatial
  20. software technology, recent versions of the libraries are necessary.
  21. If binary packages aren't available for your platform,
  22. :ref:`installation from source <build_from_source>`
  23. may be required. When compiling the libraries from source, please follow the
  24. directions closely, especially if you're a beginner.
  25. Requirements
  26. ============
  27. .. _django:
  28. Python and Django
  29. -----------------
  30. Because GeoDjango is included with Django, please refer to Django's
  31. :doc:`installation instructions </intro/install>` for details on how to install.
  32. .. _spatial_database:
  33. Spatial Database
  34. ----------------
  35. PostgreSQL (with PostGIS), MySQL, Oracle, and SQLite (with SpatiaLite) are
  36. the spatial databases currently supported.
  37. .. note::
  38. PostGIS is recommended, because it is the most mature and feature-rich
  39. open source spatial database.
  40. The geospatial libraries required for a GeoDjango installation depends
  41. on the spatial database used. The following lists the library requirements,
  42. supported versions, and any notes for each of the supported database backends:
  43. ================== ============================== ================== ==========================================================
  44. Database Library Requirements Supported Versions Notes
  45. ================== ============================== ================== ==========================================================
  46. PostgreSQL GEOS, PROJ.4, PostGIS 8.1+ Requires PostGIS.
  47. MySQL GEOS 5.x Not OGC-compliant; limited functionality.
  48. Oracle GEOS 10.2, 11 XE not supported; not tested with 9.
  49. SQLite GEOS, GDAL, PROJ.4, SpatiaLite 3.6.+ Requires SpatiaLite 2.3+, pysqlite2 2.5+, and Django 1.1.
  50. ================== ============================== ================== ==========================================================
  51. .. _geospatial_libs:
  52. Geospatial Libraries
  53. --------------------
  54. GeoDjango uses and/or provides interfaces for the following open source
  55. geospatial libraries:
  56. ======================== ==================================== ================================ ==========================
  57. Program Description Required Supported Versions
  58. ======================== ==================================== ================================ ==========================
  59. :ref:`GEOS <ref-geos>` Geometry Engine Open Source Yes 3.3, 3.2, 3.1, 3.0
  60. `PROJ.4`_ Cartographic Projections library Yes (PostgreSQL and SQLite only) 4.7, 4.6, 4.5, 4.4
  61. :ref:`GDAL <ref-gdal>` Geospatial Data Abstraction Library No (but, required for SQLite) 1.8, 1.7, 1.6, 1.5, 1.4
  62. :ref:`GeoIP <ref-geoip>` IP-based geolocation library No 1.4
  63. `PostGIS`__ Spatial extensions for PostgreSQL Yes (PostgreSQL only) 1.5, 1.4, 1.3
  64. `SpatiaLite`__ Spatial extensions for SQLite Yes (SQLite only) 3.0, 2.4, 2.3
  65. ======================== ==================================== ================================ ==========================
  66. .. admonition:: Install GDAL
  67. While :ref:`gdalbuild` is technically not required, it is *recommended*.
  68. Important features of GeoDjango (including the :ref:`ref-layermapping`,
  69. geometry reprojection, and the geographic admin) depend on its
  70. functionality.
  71. .. note::
  72. The GeoDjango interfaces to GEOS, GDAL, and GeoIP may be used
  73. independently of Django. In other words, no database or settings file
  74. required -- just import them as normal from :mod:`django.contrib.gis`.
  75. .. _PROJ.4: http://trac.osgeo.org/proj/
  76. __ http://postgis.refractions.net/
  77. __ http://www.gaia-gis.it/spatialite/index.html
  78. .. _build_from_source:
  79. Building from Source
  80. ====================
  81. When installing from source on UNIX and GNU/Linux systems, please follow
  82. the installation instructions carefully, and install the libraries in the
  83. given order. If using MySQL or Oracle as the spatial database, only GEOS
  84. is required.
  85. .. note::
  86. On Linux platforms, it may be necessary to run the ``ldconfig``
  87. command after installing each library. For example::
  88. $ sudo make install
  89. $ sudo ldconfig
  90. .. note::
  91. OS X users are required to install `Apple Developer Tools`_ in order
  92. to compile software from source. This is typically included on your
  93. OS X installation DVDs.
  94. .. _Apple Developer Tools: http://developer.apple.com/tools/xcode/
  95. .. _geosbuild:
  96. GEOS
  97. ----
  98. GEOS is a C++ library for performing geometric operations, and is the default
  99. internal geometry representation used by GeoDjango (it's behind the "lazy"
  100. geometries). Specifically, the C API library is called (e.g., ``libgeos_c.so``)
  101. directly from Python using ctypes.
  102. First, download GEOS 3.2 from the refractions Web site and untar the source
  103. archive::
  104. $ wget http://download.osgeo.org/geos/geos-3.3.0.tar.bz2
  105. $ tar xjf geos-3.3.0.tar.bz2
  106. Next, change into the directory where GEOS was unpacked, run the configure
  107. script, compile, and install::
  108. $ cd geos-3.3.0
  109. $ ./configure
  110. $ make
  111. $ sudo make install
  112. $ cd ..
  113. Troubleshooting
  114. ^^^^^^^^^^^^^^^
  115. Can't find GEOS Library
  116. ~~~~~~~~~~~~~~~~~~~~~~~
  117. When GeoDjango can't find GEOS, this error is raised:
  118. .. code-block:: text
  119. ImportError: Could not find the GEOS library (tried "geos_c"). Try setting GEOS_LIBRARY_PATH in your settings.
  120. The most common solution is to properly configure your :ref:`libsettings` *or* set
  121. :ref:`geoslibrarypath` in your settings.
  122. If using a binary package of GEOS (e.g., on Ubuntu), you may need to :ref:`binutils`.
  123. .. _geoslibrarypath:
  124. ``GEOS_LIBRARY_PATH``
  125. ~~~~~~~~~~~~~~~~~~~~~
  126. If your GEOS library is in a non-standard location, or you don't want to
  127. modify the system's library path then the :setting:`GEOS_LIBRARY_PATH`
  128. setting may be added to your Django settings file with the full path to the
  129. GEOS C library. For example:
  130. .. code-block:: python
  131. GEOS_LIBRARY_PATH = '/home/bob/local/lib/libgeos_c.so'
  132. .. note::
  133. The setting must be the *full* path to the **C** shared library; in
  134. other words you want to use ``libgeos_c.so``, not ``libgeos.so``.
  135. .. _proj4:
  136. PROJ.4
  137. ------
  138. `PROJ.4`_ is a library for converting geospatial data to different coordinate
  139. reference systems.
  140. First, download the PROJ.4 source code and datum shifting files [#]_::
  141. $ wget http://download.osgeo.org/proj/proj-4.7.0.tar.gz
  142. $ wget http://download.osgeo.org/proj/proj-datumgrid-1.5.zip
  143. Next, untar the source code archive, and extract the datum shifting files in the
  144. ``nad`` subdirectory. This must be done *prior* to configuration::
  145. $ tar xzf proj-4.7.0.tar.gz
  146. $ cd proj-4.7.0/nad
  147. $ unzip ../../proj-datumgrid-1.5.zip
  148. $ cd ..
  149. Finally, configure, make and install PROJ.4::
  150. $ ./configure
  151. $ make
  152. $ sudo make install
  153. $ cd ..
  154. .. _postgis:
  155. PostGIS
  156. -------
  157. `PostGIS`__ adds geographic object support to PostgreSQL, turning it
  158. into a spatial database. :ref:`geosbuild` and :ref:`proj4` should be
  159. installed prior to building PostGIS.
  160. .. note::
  161. The `psycopg2`_ module is required for use as the database adaptor
  162. when using GeoDjango with PostGIS.
  163. .. _psycopg2: http://initd.org/projects/psycopg2
  164. First download the source archive, and extract::
  165. $ wget http://postgis.refractions.net/download/postgis-1.5.2.tar.gz
  166. $ tar xzf postgis-1.5.2.tar.gz
  167. $ cd postgis-1.5.2
  168. Next, configure, make and install PostGIS::
  169. $ ./configure
  170. Finally, make and install::
  171. $ make
  172. $ sudo make install
  173. $ cd ..
  174. .. note::
  175. GeoDjango does not automatically create a spatial database. Please
  176. consult the section on :ref:`spatialdb_template` for more information.
  177. __ http://postgis.refractions.net/
  178. .. _gdalbuild:
  179. GDAL
  180. ----
  181. `GDAL`__ is an excellent open source geospatial library that has support for
  182. reading most vector and raster spatial data formats. Currently, GeoDjango only
  183. supports :ref:`GDAL's vector data <ref-gdal>` capabilities [#]_.
  184. :ref:`geosbuild` and :ref:`proj4` should be installed prior to building GDAL.
  185. First download the latest GDAL release version and untar the archive::
  186. $ wget http://download.osgeo.org/gdal/gdal-1.8.1.tar.gz
  187. $ tar xzf gdal-1.8.1.tar.gz
  188. $ cd gdal-1.8.1
  189. Configure, make and install::
  190. $ ./configure
  191. $ make # Go get some coffee, this takes a while.
  192. $ sudo make install
  193. $ cd ..
  194. .. note::
  195. Because GeoDjango has it's own Python interface, the preceding instructions
  196. do not build GDAL's own Python bindings. The bindings may be built by
  197. adding the ``--with-python`` flag when running ``configure``. See
  198. `GDAL/OGR In Python`__ for more information on GDAL's bindings.
  199. If you have any problems, please see the troubleshooting section below for
  200. suggestions and solutions.
  201. __ http://trac.osgeo.org/gdal/
  202. __ http://trac.osgeo.org/gdal/wiki/GdalOgrInPython
  203. .. _gdaltrouble:
  204. Troubleshooting
  205. ^^^^^^^^^^^^^^^
  206. Can't find GDAL Library
  207. ~~~~~~~~~~~~~~~~~~~~~~~
  208. When GeoDjango can't find the GDAL library, the ``HAS_GDAL`` flag
  209. will be false:
  210. .. code-block:: pycon
  211. >>> from django.contrib.gis import gdal
  212. >>> gdal.HAS_GDAL
  213. False
  214. The solution is to properly configure your :ref:`libsettings` *or* set
  215. :ref:`gdallibrarypath` in your settings.
  216. .. _gdallibrarypath:
  217. ``GDAL_LIBRARY_PATH``
  218. ~~~~~~~~~~~~~~~~~~~~~
  219. If your GDAL library is in a non-standard location, or you don't want to
  220. modify the system's library path then the :setting:`GDAL_LIBRARY_PATH`
  221. setting may be added to your Django settings file with the full path to
  222. the GDAL library. For example:
  223. .. code-block:: python
  224. GDAL_LIBRARY_PATH = '/home/sue/local/lib/libgdal.so'
  225. .. _gdaldata:
  226. Can't find GDAL data files (``GDAL_DATA``)
  227. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  228. When installed from source, GDAL versions 1.5.1 and below have an autoconf bug
  229. that places data in the wrong location. [#]_ This can lead to error messages
  230. like this:
  231. .. code-block:: text
  232. ERROR 4: Unable to open EPSG support file gcs.csv.
  233. ...
  234. OGRException: OGR failure.
  235. The solution is to set the ``GDAL_DATA`` environment variable to the location of the
  236. GDAL data files before invoking Python (typically ``/usr/local/share``; use
  237. ``gdal-config --datadir`` to find out). For example::
  238. $ export GDAL_DATA=`gdal-config --datadir`
  239. $ python manage.py shell
  240. If using Apache, you may need to add this environment variable to your configuration
  241. file:
  242. .. code-block:: apache
  243. SetEnv GDAL_DATA /usr/local/share
  244. .. _spatialite:
  245. SpatiaLite
  246. ----------
  247. .. note::
  248. Mac OS X users should follow the instructions in the :ref:`kyngchaos` section,
  249. as it is much easier than building from source.
  250. `SpatiaLite`__ adds spatial support to SQLite, turning it into a full-featured
  251. spatial database. Because SpatiaLite has special requirements, it typically
  252. requires SQLite and pysqlite2 (the Python SQLite DB-API adaptor) to be built from
  253. source. :ref:`geosbuild` and :ref:`proj4` should be installed prior to building
  254. SpatiaLite.
  255. After installation is complete, don't forget to read the post-installation
  256. docs on :ref:`create_spatialite_db`.
  257. __ http://www.gaia-gis.it/spatialite/index.html
  258. .. _sqlite:
  259. SQLite
  260. ^^^^^^
  261. Typically, SQLite packages are not compiled to include the `R*Tree module`__ --
  262. thus it must be compiled from source. First download the latest amalgamation
  263. source archive from the `SQLite download page`__, and extract::
  264. $ wget http://sqlite.org/sqlite-amalgamation-3.6.23.1.tar.gz
  265. $ tar xzf sqlite-amalgamation-3.6.23.1.tar.gz
  266. $ cd sqlite-3.6.23.1
  267. Next, run the ``configure`` script -- however the ``CFLAGS`` environment variable
  268. needs to be customized so that SQLite knows to build the R*Tree module::
  269. $ CFLAGS="-DSQLITE_ENABLE_RTREE=1" ./configure
  270. $ make
  271. $ sudo make install
  272. $ cd ..
  273. .. note::
  274. If using Ubuntu, installing a newer SQLite from source can be very difficult
  275. because it links to the existing ``libsqlite3.so`` in ``/usr/lib`` which
  276. many other packages depend on. Unfortunately, the best solution at this time
  277. is to overwrite the existing library by adding ``--prefix=/usr`` to the
  278. ``configure`` command.
  279. __ http://www.sqlite.org/rtree.html
  280. __ http://www.sqlite.org/download.html
  281. .. _spatialitebuild :
  282. SpatiaLite Library (``libspatialite``) and Tools (``spatialite``)
  283. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  284. After SQLite has been built with the R*Tree module enabled, get the latest
  285. SpatiaLite library source and tools bundle from the `download page`__::
  286. $ wget http://www.gaia-gis.it/spatialite/libspatialite-amalgamation-2.3.1.tar.gz
  287. $ wget http://www.gaia-gis.it/spatialite/spatialite-tools-2.3.1.tar.gz
  288. $ tar xzf libspatialite-amalgamation-2.3.1.tar.gz
  289. $ tar xzf spatialite-tools-2.3.1.tar.gz
  290. Prior to attempting to build, please read the important notes below to see if
  291. customization of the ``configure`` command is necessary. If not, then run the
  292. ``configure`` script, make, and install for the SpatiaLite library::
  293. $ cd libspatialite-amalgamation-2.3.1
  294. $ ./configure # May need to modified, see notes below.
  295. $ make
  296. $ sudo make install
  297. $ cd ..
  298. Finally, do the same for the SpatiaLite tools::
  299. $ cd spatialite-tools-2.3.1
  300. $ ./configure # May need to modified, see notes below.
  301. $ make
  302. $ sudo make install
  303. $ cd ..
  304. .. note::
  305. If you've installed GEOS and PROJ.4 from binary packages, you will have to specify
  306. their paths when running the ``configure`` scripts for *both* the library and the
  307. tools (the configure scripts look, by default, in ``/usr/local``). For example,
  308. on Debian/Ubuntu distributions that have GEOS and PROJ.4 packages, the command would be::
  309. $ ./configure --with-proj-include=/usr/include --with-proj-lib=/usr/lib --with-geos-include=/usr/include --with-geos-lib=/usr/lib
  310. .. note::
  311. For Mac OS X users building from source, the SpatiaLite library *and* tools
  312. need to have their ``target`` configured::
  313. $ ./configure --target=macosx
  314. __ http://www.gaia-gis.it/spatialite/sources.html
  315. .. _pysqlite2:
  316. pysqlite2
  317. ^^^^^^^^^
  318. Because SpatiaLite must be loaded as an external extension, it requires the
  319. ``enable_load_extension`` method, which is only available in versions 2.5+.
  320. Thus, download pysqlite2 2.6, and untar::
  321. $ wget http://pysqlite.googlecode.com/files/pysqlite-2.6.0.tar.gz
  322. $ tar xzf pysqlite-2.6.0.tar.gz
  323. $ cd pysqlite-2.6.0
  324. Next, use a text editor (e.g., ``emacs`` or ``vi``) to edit the ``setup.cfg`` file
  325. to look like the following:
  326. .. code-block:: ini
  327. [build_ext]
  328. #define=
  329. include_dirs=/usr/local/include
  330. library_dirs=/usr/local/lib
  331. libraries=sqlite3
  332. #define=SQLITE_OMIT_LOAD_EXTENSION
  333. .. note::
  334. The important thing here is to make sure you comment out the
  335. ``define=SQLITE_OMIT_LOAD_EXTENSION`` flag and that the ``include_dirs``
  336. and ``library_dirs`` settings are uncommented and set to the appropriate
  337. path if the SQLite header files and libraries are not in ``/usr/include``
  338. and ``/usr/lib``, respectively.
  339. After modifying ``setup.cfg`` appropriately, then run the ``setup.py`` script
  340. to build and install::
  341. $ sudo python setup.py install
  342. Post-Installation
  343. =================
  344. .. _spatialdb_template:
  345. Creating a Spatial Database Template for PostGIS
  346. ------------------------------------------------
  347. Creating a spatial database with PostGIS is different than normal because
  348. additional SQL must be loaded to enable spatial functionality. Because of
  349. the steps in this process, it's better to create a database template that
  350. can be reused later.
  351. First, you need to be able to execute the commands as a privileged database
  352. user. For example, you can use the following to become the ``postgres`` user::
  353. $ sudo su - postgres
  354. .. note::
  355. The location *and* name of the PostGIS SQL files (e.g., from
  356. ``POSTGIS_SQL_PATH`` below) depends on the version of PostGIS.
  357. PostGIS versions 1.3 and below use ``<pg_sharedir>/contrib/lwpostgis.sql``;
  358. whereas version 1.4 uses ``<sharedir>/contrib/postgis.sql`` and
  359. version 1.5 uses ``<sharedir>/contrib/postgis-1.5/postgis.sql``.
  360. To complicate matters, :ref:`ubuntudebian` distributions have their
  361. own separate directory naming system that changes each release.
  362. The example below assumes PostGIS 1.5, thus you may need to modify
  363. ``POSTGIS_SQL_PATH`` and the name of the SQL file for the specific
  364. version of PostGIS you are using.
  365. Once you're a database super user, then you may execute the following commands
  366. to create a PostGIS spatial database template::
  367. $ POSTGIS_SQL_PATH=`pg_config --sharedir`/contrib/postgis-1.5
  368. # Creating the template spatial database.
  369. $ createdb -E UTF8 template_postgis
  370. $ createlang -d template_postgis plpgsql # Adding PLPGSQL language support.
  371. # Allows non-superusers the ability to create from this template
  372. $ psql -d postgres -c "UPDATE pg_database SET datistemplate='true' WHERE datname='template_postgis';"
  373. # Loading the PostGIS SQL routines
  374. $ psql -d template_postgis -f $POSTGIS_SQL_PATH/postgis.sql
  375. $ psql -d template_postgis -f $POSTGIS_SQL_PATH/spatial_ref_sys.sql
  376. # Enabling users to alter spatial tables.
  377. $ psql -d template_postgis -c "GRANT ALL ON geometry_columns TO PUBLIC;"
  378. $ psql -d template_postgis -c "GRANT ALL ON geography_columns TO PUBLIC;"
  379. $ psql -d template_postgis -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;"
  380. These commands may be placed in a shell script for later use; for convenience
  381. the following scripts are available:
  382. =============== =============================================
  383. PostGIS Version Bash Shell Script
  384. =============== =============================================
  385. 1.3 :download:`create_template_postgis-1.3.sh`
  386. 1.4 :download:`create_template_postgis-1.4.sh`
  387. 1.5 :download:`create_template_postgis-1.5.sh`
  388. Debian/Ubuntu :download:`create_template_postgis-debian.sh`
  389. =============== =============================================
  390. Afterwards, you may create a spatial database by simply specifying
  391. ``template_postgis`` as the template to use (via the ``-T`` option)::
  392. $ createdb -T template_postgis <db name>
  393. .. note::
  394. While the ``createdb`` command does not require database super-user privileges,
  395. it must be executed by a database user that has permissions to create databases.
  396. You can create such a user with the following command::
  397. $ createuser --createdb <user>
  398. .. _create_spatialite_db:
  399. Creating a Spatial Database for SpatiaLite
  400. -------------------------------------------
  401. After the SpatiaLite library and tools have been installed, it is now possible
  402. to create a spatial database for use with GeoDjango.
  403. For this, a number of spatial metadata tables must be created in the database
  404. before any spatial query is performed against it.
  405. If you are using SpatiaLite 3.0 or newer then use the ``spatialite`` utility to
  406. call the ``InitSpatiaMetaData()`` function which will take care of that (you can
  407. safely ignore the error messages shown) then you can skip the rest of this
  408. section::
  409. $ spatialite geodjango.db "SELECT InitSpatialMetaData();"
  410. the SPATIAL_REF_SYS table already contains some row(s)
  411. InitSpatiaMetaData ()error:"table spatial_ref_sys already exists"
  412. 0
  413. If you re using a version of Spatialite older than 3.0 then to achieve the same
  414. result you need to download a database initialization file and execute the SQL
  415. queries it contains against your database.
  416. First, get it from the appropiate SpatiaLite Resources page (i.e.
  417. http://www.gaia-gis.it/spatialite-2.3.1/resources.html for 2.3 or
  418. http://www.gaia-gis.it/spatialite-2.4.0/ for 2.4)::
  419. $ wget http://www.gaia-gis.it/spatialite-2.3.1/init_spatialite-2.3.sql.gz
  420. $ gunzip init_spatialite-2.3.sql.gz
  421. (Or, if you are using SpatiaLite 2.4 then do::
  422. $ wget http://www.gaia-gis.it/spatialite-2.4.0/init_spatialite-2.4.sql.gz
  423. $ gunzip init_spatialite-2.4.sql.gz
  424. )
  425. Now, the ``spatialite`` command can be used to initialize a spatial database::
  426. $ spatialite geodjango.db < init_spatialite-2.X.sql
  427. .. note::
  428. The parameter ``geodjango.db`` is the *filename* of the SQLite database
  429. you want to use. Use the same in the :setting:`DATABASES` ``"name"`` key
  430. inside your ``settings.py``.
  431. Add ``django.contrib.gis`` to :setting:`INSTALLED_APPS`
  432. -------------------------------------------------------
  433. Like other Django contrib applications, you will *only* need to add
  434. :mod:`django.contrib.gis` to :setting:`INSTALLED_APPS` in your settings.
  435. This is the so that ``gis`` templates can be located -- if not done, then
  436. features such as the geographic admin or KML sitemaps will not function properly.
  437. .. _addgoogleprojection:
  438. Add Google Projection to ``spatial_ref_sys`` table
  439. --------------------------------------------------
  440. .. versionchanged:: 1.2
  441. .. note::
  442. If running PostGIS 1.4 and above, the entry is already included in the
  443. default ``spatial_ref_sys`` table. You can skip this step.
  444. In order to conduct database transformations to the so-called "Google"
  445. projection (a spherical mercator projection used by Google Maps),
  446. an entry must be added to your spatial database's ``spatial_ref_sys`` table.
  447. Invoke the Django shell from your project and execute the
  448. ``add_srs_entry`` function:
  449. .. code-block:: pycon
  450. $ python manage shell
  451. >>> from django.contrib.gis.utils import add_srs_entry
  452. >>> add_srs_entry(900913)
  453. .. note::
  454. In Django 1.1 the name of this function is ``add_postgis_srs``.
  455. This adds an entry for the 900913 SRID to the ``spatial_ref_sys`` (or equivalent)
  456. table, making it possible for the spatial database to transform coordinates in
  457. this projection. You only need to execute this command *once* per spatial database.
  458. Troubleshooting
  459. ===============
  460. If you can't find the solution to your problem here then participate in the
  461. community! You can:
  462. * Join the ``#geodjango`` IRC channel on FreeNode. Please be patient and polite
  463. -- while you may not get an immediate response, someone will attempt to answer
  464. your question as soon as they see it.
  465. * Ask your question on the `GeoDjango`__ mailing list.
  466. * File a ticket on the `Django trac`__ if you think there's a bug. Make
  467. sure to provide a complete description of the problem, versions used,
  468. and specify the component as "GIS".
  469. __ http://groups.google.com/group/geodjango
  470. __ http://code.djangoproject.com/simpleticket
  471. .. _libsettings:
  472. Library Environment Settings
  473. ----------------------------
  474. By far, the most common problem when installing GeoDjango is that the
  475. external shared libraries (e.g., for GEOS and GDAL) cannot be located. [#]_
  476. Typically, the cause of this problem is that the operating system isn't aware
  477. of the directory where the libraries built from source were installed.
  478. In general, the library path may be set on a per-user basis by setting
  479. an environment variable, or by configuring the library path for the entire
  480. system.
  481. ``LD_LIBRARY_PATH`` environment variable
  482. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  483. A user may set this environment variable to customize the library paths
  484. they want to use. The typical library directory for software
  485. built from source is ``/usr/local/lib``. Thus, ``/usr/local/lib`` needs
  486. to be included in the ``LD_LIBRARY_PATH`` variable. For example, the user
  487. could place the following in their bash profile::
  488. export LD_LIBRARY_PATH=/usr/local/lib
  489. Setting System Library Path
  490. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  491. On GNU/Linux systems, there is typically a file in ``/etc/ld.so.conf``, which may include
  492. additional paths from files in another directory, such as ``/etc/ld.so.conf.d``.
  493. As the root user, add the custom library path (like ``/usr/local/lib``) on a
  494. new line in ``ld.so.conf``. This is *one* example of how to do so::
  495. $ sudo echo /usr/local/lib >> /etc/ld.so.conf
  496. $ sudo ldconfig
  497. For OpenSolaris users, the system library path may be modified using the
  498. ``crle`` utility. Run ``crle`` with no options to see the current configuration
  499. and use ``crle -l`` to set with the new library path. Be *very* careful when
  500. modifying the system library path::
  501. # crle -l $OLD_PATH:/usr/local/lib
  502. .. _binutils:
  503. Install ``binutils``
  504. ^^^^^^^^^^^^^^^^^^^^
  505. GeoDjango uses the ``find_library`` function (from the ``ctypes.util`` Python
  506. module) to discover libraries. The ``find_library`` routine uses a program
  507. called ``objdump`` (part of the ``binutils`` package) to verify a shared
  508. library on GNU/Linux systems. Thus, if ``binutils`` is not installed on your
  509. Linux system then Python's ctypes may not be able to find your library even if
  510. your library path is set correctly and geospatial libraries were built perfectly.
  511. The ``binutils`` package may be installed on Debian and Ubuntu systems using the
  512. following command::
  513. $ sudo apt-get install binutils
  514. Similarly, on Red Hat and CentOS systems::
  515. $ sudo yum install binutils
  516. Platform Specific Instructions
  517. ==============================
  518. .. _macosx:
  519. Mac OS X
  520. --------
  521. Because of the variety of packaging systems available for OS X, users have
  522. several different options for installing GeoDjango. These options are:
  523. * :ref:`kyngchaos`
  524. * :ref:`fink`
  525. * :ref:`macports`
  526. * :ref:`build_from_source`
  527. .. note::
  528. Currently, the easiest and recommended approach for installing GeoDjango
  529. on OS X is to use the KyngChaos packages.
  530. This section also includes instructions for installing an upgraded version
  531. of :ref:`macosx_python` from packages provided by the Python Software
  532. Foundation, however, this is not required.
  533. .. _macosx_python:
  534. Python
  535. ^^^^^^
  536. Although OS X comes with Python installed, users can use framework
  537. installers (`2.5`__ and `2.6`__ are available) provided by
  538. the Python Software Foundation. An advantage to using the installer is
  539. that OS X's Python will remain "pristine" for internal operating system
  540. use.
  541. __ http://python.org/ftp/python/2.5.4/python-2.5.4-macosx.dmg
  542. __ http://python.org/ftp/python/2.6.2/python-2.6.2-macosx2009-04-16.dmg
  543. .. note::
  544. You will need to modify the ``PATH`` environment variable in your
  545. ``.profile`` file so that the new version of Python is used when
  546. ``python`` is entered at the command-line::
  547. export PATH=/Library/Frameworks/Python.framework/Versions/Current/bin:$PATH
  548. .. _kyngchaos:
  549. KyngChaos Packages
  550. ^^^^^^^^^^^^^^^^^^
  551. William Kyngesburye provides a number of `geospatial library binary packages`__
  552. that make it simple to get GeoDjango installed on OS X without compiling
  553. them from source. However, the `Apple Developer Tools`_ are still necessary
  554. for compiling the Python database adapters :ref:`psycopg2_kyngchaos` (for PostGIS)
  555. and :ref:`pysqlite2_kyngchaos` (for SpatiaLite).
  556. .. note::
  557. SpatiaLite users should consult the :ref:`spatialite_kyngchaos` section
  558. after installing the packages for additional instructions.
  559. Download the framework packages for:
  560. * UnixImageIO
  561. * PROJ
  562. * GEOS
  563. * SQLite3 (includes the SpatiaLite library)
  564. * GDAL
  565. Install the packages in the order they are listed above, as the GDAL and SQLite
  566. packages require the packages listed before them. Afterwards, you can also
  567. install the KyngChaos binary packages for `PostgreSQL and PostGIS`__.
  568. After installing the binary packages, you'll want to add the following to
  569. your ``.profile`` to be able to run the package programs from the command-line::
  570. export PATH=/Library/Frameworks/UnixImageIO.framework/Programs:$PATH
  571. export PATH=/Library/Frameworks/PROJ.framework/Programs:$PATH
  572. export PATH=/Library/Frameworks/GEOS.framework/Programs:$PATH
  573. export PATH=/Library/Frameworks/SQLite3.framework/Programs:$PATH
  574. export PATH=/Library/Frameworks/GDAL.framework/Programs:$PATH
  575. export PATH=/usr/local/pgsql/bin:$PATH
  576. __ http://www.kyngchaos.com/software/frameworks
  577. __ http://www.kyngchaos.com/software/postgres
  578. .. note::
  579. Use of these binaries requires Django 1.0.3 and above. If you are
  580. using a previous version of Django (like 1.0.2), then you will have
  581. to add the following in your settings:
  582. .. code-block:: python
  583. GEOS_LIBRARY_PATH='/Library/Frameworks/GEOS.framework/GEOS'
  584. GDAL_LIBRARY_PATH='/Library/Frameworks/GDAL.framework/GDAL'
  585. .. _psycopg2_kyngchaos:
  586. psycopg2
  587. ~~~~~~~~
  588. After you've installed the KyngChaos binaries and modified your ``PATH``, as
  589. described above, ``psycopg2`` may be installed using the following command::
  590. $ sudo python easy_install psycopg2
  591. .. note::
  592. To use ``easy_install`` you'll need to install Python's `setuptools`_.
  593. .. _setuptools: http://pypi.python.org/pypi/setuptools
  594. .. _pysqlite2_kyngchaos:
  595. pysqlite2
  596. ~~~~~~~~~
  597. Follow the :ref:`pysqlite2` source install instructions, however,
  598. when editing the ``setup.cfg`` use the following instead:
  599. .. code-block:: ini
  600. [build_ext]
  601. #define=
  602. include_dirs=/Library/Frameworks/SQLite3.framework/unix/include
  603. library_dirs=/Library/Frameworks/SQLite3.framework/unix/lib
  604. libraries=sqlite3
  605. #define=SQLITE_OMIT_LOAD_EXTENSION
  606. .. _spatialite_kyngchaos:
  607. SpatiaLite
  608. ~~~~~~~~~~
  609. When :ref:`create_spatialite_db`, the ``spatialite`` program is required.
  610. However, instead of attempting to compile the SpatiaLite tools from source,
  611. download the `SpatiaLite Binaries`__ for OS X, and install ``spatialite`` in a
  612. location available in your ``PATH``. For example::
  613. $ curl -O http://www.gaia-gis.it/spatialite/spatialite-tools-osx-x86-2.3.1.tar.gz
  614. $ tar xzf spatialite-tools-osx-x86-2.3.1.tar.gz
  615. $ cd spatialite-tools-osx-x86-2.3.1/bin
  616. $ sudo cp spatialite /Library/Frameworks/SQLite3.framework/Programs
  617. Finally, for GeoDjango to be able to find the KyngChaos SpatiaLite library,
  618. add the following to your ``settings.py``:
  619. .. code-block:: python
  620. SPATIALITE_LIBRARY_PATH='/Library/Frameworks/SQLite3.framework/SQLite3'
  621. __ http://www.gaia-gis.it/spatialite/binaries.html
  622. .. _fink:
  623. Fink
  624. ^^^^
  625. `Kurt Schwehr`__ has been gracious enough to create GeoDjango packages for users
  626. of the `Fink`__ package system. The following packages are available, depending
  627. on which version of Python you want to use:
  628. * ``django-gis-py26``
  629. * ``django-gis-py25``
  630. * ``django-gis-py24``
  631. __ http://schwehr.org/blog/
  632. __ http://www.finkproject.org/
  633. .. _macports:
  634. MacPorts
  635. ^^^^^^^^
  636. `MacPorts`__ may be used to install GeoDjango prerequisites on Macintosh
  637. computers running OS X. Because MacPorts still builds the software from source,
  638. the `Apple Developer Tools`_ are required.
  639. Summary::
  640. $ sudo port install postgresql83-server
  641. $ sudo port install geos
  642. $ sudo port install proj
  643. $ sudo port install postgis
  644. $ sudo port install gdal
  645. $ sudo port install libgeoip
  646. .. note::
  647. You will also have to modify the ``PATH`` in your ``.profile`` so
  648. that the MacPorts programs are accessible from the command-line::
  649. export PATH=/opt/local/bin:/opt/local/lib/postgresql83/bin
  650. In addition, add the ``DYLD_FALLBACK_LIBRARY_PATH`` setting so that
  651. the libraries can be found by Python::
  652. export DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib:/opt/local/lib/postgresql83
  653. __ http://www.macports.org/
  654. .. _ubuntudebian:
  655. Ubuntu & Debian GNU/Linux
  656. -------------------------
  657. .. note::
  658. The PostGIS SQL files are not placed in the PostgreSQL share directory in
  659. the Debian and Ubuntu packages, and are located instead in a special
  660. directory depending on the release. Thus, when :ref:`spatialdb_template`
  661. use the :download:`create_template_postgis-debian.sh` script instead.
  662. .. _ubuntu:
  663. Ubuntu
  664. ^^^^^^
  665. .. _ubuntu10:
  666. 10.04 and 10.10
  667. ~~~~~~~~~~~~~~~
  668. In Ubuntu 10 PostgreSQL was upgraded to 8.4 and GDAL was upgraded to 1.6.
  669. Ubuntu 10.04 uses PostGIS 1.4, while Ubuntu 10.10 uses PostGIS 1.5 (with
  670. geography support). The installation commands are::
  671. $ sudo apt-get install binutils gdal-bin libproj-dev postgresql-8.4-postgis \
  672. postgresql-server-dev-8.4 python-psycopg2 python-setuptools
  673. $ sudo easy_install Django
  674. .. _ibex:
  675. 8.10
  676. ~~~~
  677. Use the synaptic package manager to install the following packages::
  678. $ sudo apt-get install binutils gdal-bin postgresql-8.3-postgis \
  679. postgresql-server-dev-8.3 python-psycopg2 python-setuptools
  680. Afterwards, you may install Django with Python's ``easy_install`` script (the
  681. Ubuntu package ``python-django`` uses an older version missing several
  682. important bug fixes for GeoDjango)::
  683. $ sudo easy_install Django
  684. That's it! For the curious, the required binary prerequisites packages are:
  685. * ``binutils``: for ctypes to find libraries
  686. * ``postgresql-8.3``
  687. * ``postgresql-server-dev-8.3``: for ``pg_config``
  688. * ``postgresql-8.3-postgis``: for PostGIS 1.3.3
  689. * ``libgeos-3.0.0``, and ``libgeos-c1``: for GEOS 3.0.0
  690. * ``libgdal1-1.5.0``: for GDAL 1.5.0 library
  691. * ``proj``: for PROJ 4.6.0 -- but no datum shifting files, see note below
  692. * ``python-psycopg2``
  693. * ``python-setuptools``: for ``easy_install``
  694. Optional packages to consider:
  695. * ``libgeoip1``: for :ref:`GeoIP <ref-geoip>` support
  696. * ``gdal-bin``: for GDAL command line programs like ``ogr2ogr``
  697. * ``python-gdal`` for GDAL's own Python bindings -- includes interfaces for raster manipulation
  698. .. note::
  699. On this version of Ubuntu the ``proj`` package does not come with the
  700. datum shifting files installed, which will cause problems with the
  701. geographic admin because the ``null`` datum grid is not available for
  702. transforming geometries to the spherical mercator projection. A solution
  703. is to download the datum-shifting files, create the grid file, and
  704. install it yourself::
  705. $ wget http://download.osgeo.org/proj/proj-datumgrid-1.4.tar.gz
  706. $ mkdir nad
  707. $ cd nad
  708. $ tar xzf ../proj-datumgrid-1.4.tar.gz
  709. $ nad2bin null < null.lla
  710. $ sudo cp null /usr/share/proj
  711. Otherwise, the Ubuntu ``proj`` package is fine for general use as long as you
  712. do not plan on doing any database transformation of geometries to the
  713. Google projection (900913).
  714. .. _heron:
  715. 8.04 and lower
  716. ~~~~~~~~~~~~~~
  717. The 8.04 (and lower) versions of Ubuntu use GEOS v2.2.3 in their binary packages,
  718. which is incompatible with GeoDjango. Thus, do *not* use the binary packages
  719. for GEOS or PostGIS and build some prerequisites from source, per the instructions
  720. in this document; however, it is okay to use the PostgreSQL binary packages.
  721. For more details, please see the Debian instructions for :ref:`etch` below.
  722. .. _debian:
  723. Debian
  724. ------
  725. .. _etch:
  726. 4.0 (Etch)
  727. ^^^^^^^^^^
  728. The situation here is the same as that of Ubuntu :ref:`heron` -- in other words,
  729. some packages must be built from source to work properly with GeoDjango.
  730. Binary Packages
  731. ~~~~~~~~~~~~~~~
  732. The following command will install acceptable binary packages, as well as
  733. the development tools necessary to build the rest of the requirements::
  734. $ sudo apt-get install binutils bzip2 gcc g++ flex make postgresql-8.1 \
  735. postgresql-server-dev-8.1 python-ctypes python-psycopg2 python-setuptools
  736. Required package information:
  737. * ``binutils``: for ctypes to find libraries
  738. * ``bzip2``: for decompressing the source packages
  739. * ``gcc``, ``g++``, ``make``: GNU developer tools used to compile the libraries
  740. * ``flex``: required to build PostGIS
  741. * ``postgresql-8.1``
  742. * ``postgresql-server-dev-8.1``: for ``pg_config``
  743. * ``python-psycopg2``
  744. * ``python-setuptools``: for ``easy_install``
  745. Optional packages:
  746. * ``libgeoip``: for :ref:`GeoIP <ref-geoip>` support
  747. Source Packages
  748. ~~~~~~~~~~~~~~~
  749. You will still have to install :ref:`geosbuild`, :ref:`proj4`,
  750. :ref:`postgis`, and :ref:`gdalbuild` from source. Please follow the
  751. directions carefully.
  752. .. _lenny:
  753. 5.0 (Lenny)
  754. ^^^^^^^^^^^
  755. This version is comparable to Ubuntu :ref:`ibex`, so the command
  756. is very similar::
  757. $ sudo apt-get install binutils libgdal1-1.5.0 postgresql-8.3 \
  758. postgresql-8.3-postgis postgresql-server-dev-8.3 \
  759. python-psycopg2 python-setuptools
  760. This assumes that you are using PostgreSQL version 8.3. Else, replace ``8.3``
  761. in the above command with the appropriate PostgreSQL version.
  762. .. note::
  763. Please read the note in the Ubuntu :ref:`ibex` install documentation
  764. about the ``proj`` package -- it also applies here because the package does
  765. not include the datum shifting files.
  766. .. _post_install:
  767. Post-installation Notes
  768. ~~~~~~~~~~~~~~~~~~~~~~~
  769. If the PostgreSQL database cluster was not initiated after installing, then it
  770. can be created (and started) with the following command::
  771. $ sudo pg_createcluster --start 8.3 main
  772. Afterwards, the ``/etc/init.d/postgresql-8.3`` script should be used to manage
  773. the starting and stopping of PostgreSQL.
  774. In addition, the SQL files for PostGIS are placed in a different location on
  775. Debian 5.0 . Thus when :ref:`spatialdb_template` either:
  776. * Create a symbolic link to these files::
  777. $ sudo ln -s /usr/share/postgresql-8.3-postgis/{lwpostgis,spatial_ref_sys}.sql \
  778. /usr/share/postgresql/8.3
  779. If not running PostgreSQL 8.3, then replace ``8.3`` in the command above with the correct version.
  780. * Or use the :download:`create_template_postgis-debian.sh` to create the spatial database.
  781. .. _windows:
  782. Windows
  783. -------
  784. Proceed through the following sections sequentially in order to install
  785. GeoDjango on Windows.
  786. .. note::
  787. These instructions assume that you are using 32-bit versions of
  788. all programs. While 64-bit versions of Python and PostgreSQL 9.0
  789. are available, 64-bit versions of spatial libraries, like
  790. GEOS and GDAL, are not yet provided by the :ref:`OSGeo4W` installer.
  791. Python
  792. ^^^^^^
  793. First, download the latest `Python 2.7 installer`__ from the Python Web site.
  794. Next, run the installer and keep the defaults -- for example, keep
  795. 'Install for all users' checked and the installation path set as
  796. ``C:\Python27``.
  797. .. note::
  798. You may already have a version of Python installed in ``C:\python`` as ESRI
  799. products sometimes install a copy there. *You should still install a
  800. fresh version of Python 2.7.*
  801. __ http://python.org/download/
  802. PostgreSQL
  803. ^^^^^^^^^^
  804. First, download the latest `PostgreSQL 9.0 installer`__ from the
  805. `EnterpriseDB`__ Web site. After downloading, simply run the installer,
  806. follow the on-screen directions, and keep the default options unless
  807. you know the consequences of changing them.
  808. .. note::
  809. The PostgreSQL installer creates both a new Windows user to be the
  810. 'postgres service account' and a ``postgres`` database superuser
  811. You will be prompted once to set the password for both accounts --
  812. make sure to remember it!
  813. When the installer completes, it will ask to launch the Application Stack
  814. Builder (ASB) on exit -- keep this checked, as it is necessary to
  815. install :ref:`postgisasb`.
  816. .. note::
  817. If installed successfully, the PostgreSQL server will run in the
  818. background each time the system as started as a Windows service.
  819. A :menuselection:`PostgreSQL 9.0` start menu group will created
  820. and contains shortcuts for the ASB as well as the 'SQL Shell',
  821. which will launch a ``psql`` command window.
  822. __ http://www.enterprisedb.com/products-services-training/pgdownload
  823. __ http://www.enterprisedb.com
  824. .. _postgisasb:
  825. PostGIS
  826. ^^^^^^^
  827. From within the Application Stack Builder (to run outside of the installer,
  828. :menuselection:`Start --> Programs --> PostgreSQL 9.0`), select
  829. :menuselection:`PostgreSQL Database Server 9.0 on port 5432` from the drop down
  830. menu. Next, expand the :menuselection:`Categories --> Spatial Extensions` menu
  831. tree and select :menuselection:`PostGIS 1.5 for PostgreSQL 9.0`.
  832. After clicking next, you will be prompted to select your mirror, PostGIS
  833. will be downloaded, and the PostGIS installer will begin. Select only the
  834. default options during install (e.g., do not uncheck the option to create a
  835. default PostGIS database).
  836. .. note::
  837. You will be prompted to enter your ``postgres`` database superuser
  838. password in the 'Database Connection Information' dialog.
  839. psycopg2
  840. ^^^^^^^^
  841. The ``psycopg2`` Python module provides the interface between Python and the
  842. PostgreSQL database. Download the latest `Windows installer`__ for your version
  843. of Python and PostgreSQL and run using the default settings. [#]_
  844. __ http://www.stickpeople.com/projects/python/win-psycopg/
  845. .. _osgeo4w:
  846. OSGeo4W
  847. ^^^^^^^
  848. The `OSGeo4W installer`_ makes it simple to install the PROJ.4, GDAL, and GEOS
  849. libraries required by GeoDjango. First, download the `OSGeo4W installer`_,
  850. and run it. Select :menuselection:`Express Web-GIS Install` and click next.
  851. In the 'Select Packages' list, ensure that GDAL is selected; MapServer and
  852. Apache are also enabled by default, but are not required by GeoDjango and
  853. may be unchecked safely. After clicking next, the packages will be
  854. automatically downloaded and installed, after which you may exit the
  855. installer.
  856. .. _OSGeo4W installer: http://trac.osgeo.org/osgeo4w/
  857. Modify Windows Environment
  858. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  859. In order to use GeoDjango, you will need to add your Python and OSGeo4W
  860. directories to your Windows system ``Path``, as well as create ``GDAL_DATA``
  861. and ``PROJ_LIB`` environment variables. The following set of commands,
  862. executable with ``cmd.exe``, will set this up:
  863. .. code-block:: bat
  864. set OSGEO4W_ROOT=C:\OSGeo4W
  865. set PYTHON_ROOT=C:\Python27
  866. set GDAL_DATA=%OSGEO4W_ROOT%\share\gdal
  867. set PROJ_LIB=%OSGEO4W_ROOT%\share\proj
  868. set PATH=%PATH%;%PYTHON_ROOT%;%OSGEO4W_ROOT%\bin
  869. reg ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /f /d "%PATH%"
  870. reg ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v GDAL_DATA /t REG_EXPAND_SZ /f /d "%GDAL_DATA%"
  871. reg ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PROJ_LIB /t REG_EXPAND_SZ /f /d "%PROJ_LIB%"
  872. For your convenience, these commands are available in the executable batch
  873. script, :download:`geodjango_setup.bat`.
  874. .. note::
  875. Administrator privileges are required to execute these commands.
  876. To do this, right-click on :download:`geodjango_setup.bat` and select
  877. :menuselection:`Run as administrator`. You need to log out and log back in again
  878. for the settings to take effect.
  879. .. note::
  880. If you customized the Python or OSGeo4W installation directories,
  881. then you will need to modify the ``OSGEO4W_ROOT`` and/or ``PYTHON_ROOT``
  882. variables accordingly.
  883. Install Django and Setup Database
  884. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  885. Finally, :ref:`install Django <installing-official-release>` on your system.
  886. You do not need to create a spatial database template, as one named
  887. ``template_postgis`` is created for you when installing PostGIS.
  888. To administer the database, you can either use the pgAdmin III program
  889. (:menuselection:`Start --> PostgreSQL 9.0 --> pgAdmin III`) or the
  890. SQL Shell (:menuselection:`Start --> PostgreSQL 9.0 --> SQL Shell`).
  891. For example, to create a ``geodjango`` spatial database and user, the following
  892. may be executed from the SQL Shell as the ``postgres`` user::
  893. postgres# CREATE USER geodjango PASSWORD 'my_passwd';
  894. postgres# CREATE DATABASE geodjango OWNER geodjango TEMPLATE template_postgis ENCODING 'utf8';
  895. .. rubric:: Footnotes
  896. .. [#] The datum shifting files are needed for converting data to and from
  897. certain projections.
  898. For example, the PROJ.4 string for the `Google projection (900913)
  899. <http://spatialreference.org/ref/epsg/900913/proj4>`_ requires the
  900. ``null`` grid file only included in the extra datum shifting files.
  901. It is easier to install the shifting files now, then to have debug a
  902. problem caused by their absence later.
  903. .. [#] Specifically, GeoDjango provides support for the `OGR
  904. <http://gdal.org/ogr>`_ library, a component of GDAL.
  905. .. [#] See `GDAL ticket #2382 <http://trac.osgeo.org/gdal/ticket/2382>`_.
  906. .. [#] GeoDjango uses the :func:`~ctypes.util.find_library` routine from
  907. :mod:`ctypes.util` to locate shared libraries.
  908. .. [#] The ``psycopg2`` Windows installers are packaged and maintained by
  909. `Jason Erickson <http://www.stickpeople.com/projects/python/win-psycopg/>`_.