install.txt 42 KB

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