install.txt 44 KB

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