install.txt 43 KB

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