Fixed small errors in GeoDjango tutorial, enhanced code pygmentation in install document.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17497 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Ramiro Morales 2012-02-11 01:48:45 +00:00
parent c406b554c7
commit 8a986cb5bc
2 changed files with 51 additions and 24 deletions

View File

@ -4,6 +4,8 @@
GeoDjango Installation GeoDjango Installation
====================== ======================
.. highlight:: console
Overview Overview
======== ========
In general, GeoDjango installation requires: In general, GeoDjango installation requires:
@ -157,7 +159,9 @@ Troubleshooting
Can't find GEOS Library Can't find GEOS Library
~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~
When GeoDjango can't find GEOS, this error is raised:: When GeoDjango can't find GEOS, this error is raised:
.. code-block:: text
ImportError: Could not find the GEOS library (tried "geos_c"). Try setting GEOS_LIBRARY_PATH in your settings. ImportError: Could not find the GEOS library (tried "geos_c"). Try setting GEOS_LIBRARY_PATH in your settings.
@ -174,7 +178,9 @@ If using a binary package of GEOS (e.g., on Ubuntu), you may need to :ref:`binut
If your GEOS library is in a non-standard location, or you don't want to If your GEOS library is in a non-standard location, or you don't want to
modify the system's library path then the :setting:`GEOS_LIBRARY_PATH` modify the system's library path then the :setting:`GEOS_LIBRARY_PATH`
setting may be added to your Django settings file with the full path to the setting may be added to your Django settings file with the full path to the
GEOS C library. For example:: GEOS C library. For example:
.. code-block:: python
GEOS_LIBRARY_PATH = '/home/bob/local/lib/libgeos_c.so' GEOS_LIBRARY_PATH = '/home/bob/local/lib/libgeos_c.so'
@ -295,7 +301,9 @@ Can't find GDAL Library
~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~
When GeoDjango can't find the GDAL library, the ``HAS_GDAL`` flag When GeoDjango can't find the GDAL library, the ``HAS_GDAL`` flag
will be false:: will be false:
.. code-block:: pycon
>>> from django.contrib.gis import gdal >>> from django.contrib.gis import gdal
>>> gdal.HAS_GDAL >>> gdal.HAS_GDAL
@ -312,7 +320,9 @@ The solution is to properly configure your :ref:`libsettings` *or* set
If your GDAL library is in a non-standard location, or you don't want to If your GDAL library is in a non-standard location, or you don't want to
modify the system's library path then the :setting:`GDAL_LIBRARY_PATH` modify the system's library path then the :setting:`GDAL_LIBRARY_PATH`
setting may be added to your Django settings file with the full path to setting may be added to your Django settings file with the full path to
the GDAL library. For example:: the GDAL library. For example:
.. code-block:: python
GDAL_LIBRARY_PATH = '/home/sue/local/lib/libgdal.so' GDAL_LIBRARY_PATH = '/home/sue/local/lib/libgdal.so'
@ -323,7 +333,9 @@ Can't find GDAL data files (``GDAL_DATA``)
When installed from source, GDAL versions 1.5.1 and below have an autoconf bug When installed from source, GDAL versions 1.5.1 and below have an autoconf bug
that places data in the wrong location. [#]_ This can lead to error messages that places data in the wrong location. [#]_ This can lead to error messages
like this:: like this:
.. code-block:: text
ERROR 4: Unable to open EPSG support file gcs.csv. ERROR 4: Unable to open EPSG support file gcs.csv.
... ...
@ -337,7 +349,9 @@ GDAL data files before invoking Python (typically ``/usr/local/share``; use
$ python manage.py shell $ python manage.py shell
If using Apache, you may need to add this environment variable to your configuration If using Apache, you may need to add this environment variable to your configuration
file:: file:
.. code-block:: apache
SetEnv GDAL_DATA /usr/local/share SetEnv GDAL_DATA /usr/local/share
@ -457,7 +471,9 @@ Thus, download pysqlite2 2.6, and untar::
$ cd pysqlite-2.6.0 $ cd pysqlite-2.6.0
Next, use a text editor (e.g., ``emacs`` or ``vi``) to edit the ``setup.cfg`` file Next, use a text editor (e.g., ``emacs`` or ``vi``) to edit the ``setup.cfg`` file
to look like the following:: to look like the following:
.. code-block:: ini
[build_ext] [build_ext]
#define= #define=
@ -627,7 +643,9 @@ In order to conduct database transformations to the so-called "Google"
projection (a spherical mercator projection used by Google Maps), projection (a spherical mercator projection used by Google Maps),
an entry must be added to your spatial database's ``spatial_ref_sys`` table. an entry must be added to your spatial database's ``spatial_ref_sys`` table.
Invoke the Django shell from your project and execute the Invoke the Django shell from your project and execute the
``add_srs_entry`` function:: ``add_srs_entry`` function:
.. code-block:: pycon
$ python manage shell $ python manage shell
>>> from django.contrib.gis.utils import add_srs_entry >>> from django.contrib.gis.utils import add_srs_entry
@ -814,7 +832,9 @@ __ http://www.kyngchaos.com/software/postgres
Use of these binaries requires Django 1.0.3 and above. If you are Use of these binaries requires Django 1.0.3 and above. If you are
using a previous version of Django (like 1.0.2), then you will have using a previous version of Django (like 1.0.2), then you will have
to add the following in your settings:: to add the following in your settings:
.. code-block:: python
GEOS_LIBRARY_PATH='/Library/Frameworks/GEOS.framework/GEOS' GEOS_LIBRARY_PATH='/Library/Frameworks/GEOS.framework/GEOS'
GDAL_LIBRARY_PATH='/Library/Frameworks/GDAL.framework/GDAL' GDAL_LIBRARY_PATH='/Library/Frameworks/GDAL.framework/GDAL'
@ -841,7 +861,9 @@ pysqlite2
~~~~~~~~~ ~~~~~~~~~
Follow the :ref:`pysqlite2` source install instructions, however, Follow the :ref:`pysqlite2` source install instructions, however,
when editing the ``setup.cfg`` use the following instead:: when editing the ``setup.cfg`` use the following instead:
.. code-block:: ini
[build_ext] [build_ext]
#define= #define=
@ -866,7 +888,9 @@ location available in your ``PATH``. For example::
$ sudo cp spatialite /Library/Frameworks/SQLite3.framework/Programs $ sudo cp spatialite /Library/Frameworks/SQLite3.framework/Programs
Finally, for GeoDjango to be able to find the KyngChaos SpatiaLite library, Finally, for GeoDjango to be able to find the KyngChaos SpatiaLite library,
add the following to your ``settings.py``:: add the following to your ``settings.py``:
.. code-block:: python
SPATIALITE_LIBRARY_PATH='/Library/Frameworks/SQLite3.framework/SQLite3' SPATIALITE_LIBRARY_PATH='/Library/Frameworks/SQLite3.framework/SQLite3'
@ -1216,7 +1240,9 @@ Modify Windows Environment
In order to use GeoDjango, you will need to add your Python and OSGeo4W In order to use GeoDjango, you will need to add your Python and OSGeo4W
directories to your Windows system ``Path``, as well as create ``GDAL_DATA`` directories to your Windows system ``Path``, as well as create ``GDAL_DATA``
and ``PROJ_LIB`` environment variables. The following set of commands, and ``PROJ_LIB`` environment variables. The following set of commands,
executable with ``cmd.exe``, will set this up:: executable with ``cmd.exe``, will set this up:
.. code-block:: bat
set OSGEO4W_ROOT=C:\OSGeo4W set OSGEO4W_ROOT=C:\OSGeo4W
set PYTHON_ROOT=C:\Python27 set PYTHON_ROOT=C:\Python27

View File

@ -284,7 +284,7 @@ This management command should produce the following output:
.. code-block:: sql .. code-block:: sql
BEGIN; BEGIN;
CREATE TABLE "world_worldborders" ( CREATE TABLE "world_worldborder" (
"id" serial NOT NULL PRIMARY KEY, "id" serial NOT NULL PRIMARY KEY,
"name" varchar(50) NOT NULL, "name" varchar(50) NOT NULL,
"area" integer NOT NULL, "area" integer NOT NULL,
@ -299,16 +299,16 @@ This management command should produce the following output:
"lat" double precision NOT NULL "lat" double precision NOT NULL
) )
; ;
SELECT AddGeometryColumn('world_worldborders', 'mpoly', 4326, 'MULTIPOLYGON', 2); SELECT AddGeometryColumn('world_worldborder', 'mpoly', 4326, 'MULTIPOLYGON', 2);
ALTER TABLE "world_worldborders" ALTER "mpoly" SET NOT NULL; ALTER TABLE "world_worldborder" ALTER "mpoly" SET NOT NULL;
CREATE INDEX "world_worldborders_mpoly_id" ON "world_worldborders" USING GIST ( "mpoly" GIST_GEOMETRY_OPS ); CREATE INDEX "world_worldborder_mpoly_id" ON "world_worldborder" USING GIST ( "mpoly" GIST_GEOMETRY_OPS );
COMMIT; COMMIT;
If satisfied, you may then create this table in the database by running the If satisfied, you may then create this table in the database by running the
``syncdb`` management command:: ``syncdb`` management command::
$ python manage.py syncdb $ python manage.py syncdb
Creating table world_worldborders Creating table world_worldborder
Installing custom SQL for world.WorldBorder model Installing custom SQL for world.WorldBorder model
The ``syncdb`` command may also prompt you to create an admin user; go ahead The ``syncdb`` command may also prompt you to create an admin user; go ahead
@ -547,7 +547,8 @@ and mapping dictionary created above, automatically:
.. code-block:: bash .. code-block:: bash
$ python manage.py ogrinspect world/data/TM_WORLD_BORDERS-0.3.shp WorldBorder --srid=4326 --mapping --multi $ python manage.py ogrinspect world/data/TM_WORLD_BORDERS-0.3.shp WorldBorder \
--srid=4326 --mapping --multi
A few notes about the command-line options given above: A few notes about the command-line options given above:
@ -661,12 +662,12 @@ of abstraction::
>>> qs = WorldBorder.objects.filter(mpoly__intersects=pnt) >>> qs = WorldBorder.objects.filter(mpoly__intersects=pnt)
>>> print qs.query # Generating the SQL >>> print qs.query # Generating the SQL
SELECT "world_worldborders"."id", "world_worldborders"."name", "world_worldborders"."area", SELECT "world_worldborder"."id", "world_worldborder"."name", "world_worldborder"."area",
"world_worldborders"."pop2005", "world_worldborders"."fips", "world_worldborders"."iso2", "world_worldborder"."pop2005", "world_worldborder"."fips", "world_worldborder"."iso2",
"world_worldborders"."iso3", "world_worldborders"."un", "world_worldborders"."region", "world_worldborder"."iso3", "world_worldborder"."un", "world_worldborder"."region",
"world_worldborders"."subregion", "world_worldborders"."lon", "world_worldborders"."lat", "world_worldborder"."subregion", "world_worldborder"."lon", "world_worldborder"."lat",
"world_worldborders"."mpoly" FROM "world_worldborders" "world_worldborder"."mpoly" FROM "world_worldborder"
WHERE ST_Intersects("world_worldborders"."mpoly", ST_Transform(%s, 4326)) WHERE ST_Intersects("world_worldborder"."mpoly", ST_Transform(%s, 4326))
>>> qs # printing evaluates the queryset >>> qs # printing evaluates the queryset
[<WorldBorder: United States>] [<WorldBorder: United States>]