Ticket #16455: 16455-v10.diff
File 16455-v10.diff, 15.7 KB (added by , 12 years ago) |
---|
-
django/contrib/gis/db/backends/postgis/creation.py
diff --git a/django/contrib/gis/db/backends/postgis/creation.py b/django/contrib/gis/db/backends/postgis/creation.py index bad22be..fc8a242 100644
a b 1 1 from django.conf import settings 2 from django.core.exceptions import ImproperlyConfigured 2 3 from django.db.backends.postgresql_psycopg2.creation import DatabaseCreation 3 4 4 5 class PostGISCreation(DatabaseCreation): … … class PostGISCreation(DatabaseCreation): 38 39 style.SQL_FIELD(qn(f.column)) + 39 40 style.SQL_KEYWORD(' SET NOT NULL') + ';') 40 41 41 42 42 if f.spatial_index: 43 43 # Spatial indexes created the same way for both Geometry and 44 # Geography columns 44 # Geography columns. 45 # PostGIS 2.0 does not support GIST_GEOMETRY_OPS. So, on 1.5 46 # we use GIST_GEOMETRY_OPS, on 2.0 we use either "nd" ops 47 # which are fast on multidimensional cases, or just plain 48 # gist index for the 2d case. 45 49 if f.geography: 46 50 index_opts = '' 51 elif self.connection.ops.spatial_version >= (2, 0): 52 if f.dim > 2: 53 index_opts = ' ' + style.SQL_KEYWORD('gist_geometry_ops_nd') 54 else: 55 index_opts = '' 47 56 else: 48 57 index_opts = ' ' + style.SQL_KEYWORD(self.geom_index_opts) 49 58 output.append(style.SQL_KEYWORD('CREATE INDEX ') + … … class PostGISCreation(DatabaseCreation): 56 65 return output 57 66 58 67 def sql_table_creation_suffix(self): 59 qn = self.connection.ops.quote_name 60 return ' TEMPLATE %s' % qn(getattr(settings, 'POSTGIS_TEMPLATE', 'template_postgis')) 68 cursor = self.connection.cursor() 69 cursor.execute('select datname from pg_database;') 70 db_names = [row[0] for row in cursor.fetchall()] 71 postgis_template = getattr(settings, 'POSTGIS_TEMPLATE', 'template_postgis') 72 73 if postgis_template in db_names: 74 qn = self.connection.ops.quote_name 75 return ' TEMPLATE %s' % qn(postgis_template) 76 elif self.connection.ops.spatial_version < (2, 0): 77 raise ImproperlyConfigured("Template database '%s' does not exist." % postgis_template) 78 else: 79 return '' -
django/contrib/gis/gdal/tests/test_ds.py
diff --git a/django/contrib/gis/gdal/tests/test_ds.py b/django/contrib/gis/gdal/tests/test_ds.py index 71d22a0..5dfafd2 100644
a b from django.contrib.gis.geometry.test_data import get_ds_file, TestDS, TEST_DATA 8 8 ds_list = (TestDS('test_point', nfeat=5, nfld=3, geom='POINT', gtype=1, driver='ESRI Shapefile', 9 9 fields={'dbl' : OFTReal, 'int' : OFTInteger, 'str' : OFTString,}, 10 10 extent=(-1.35011,0.166623,-0.524093,0.824508), # Got extent from QGIS 11 srs_wkt='GEOGCS["GCS_WGS_1984",DATUM["WGS_1984",SPHEROID["WGS_ 1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]',11 srs_wkt='GEOGCS["GCS_WGS_1984",DATUM["WGS_1984",SPHEROID["WGS_84",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]', 12 12 field_values={'dbl' : [float(i) for i in range(1, 6)], 'int' : range(1, 6), 'str' : [str(i) for i in range(1, 6)]}, 13 13 fids=range(5)), 14 14 TestDS('test_vrt', ext='vrt', nfeat=3, nfld=3, geom='POINT', gtype='Point25D', driver='VRT', … … ds_list = (TestDS('test_point', nfeat=5, nfld=3, geom='POINT', gtype=1, driver=' 20 20 driver='ESRI Shapefile', 21 21 fields={'float' : OFTReal, 'int' : OFTInteger, 'str' : OFTString,}, 22 22 extent=(-1.01513,-0.558245,0.161876,0.839637), # Got extent from QGIS 23 srs_wkt='GEOGCS["GCS_WGS_1984",DATUM["WGS_1984",SPHEROID["WGS_ 1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]'),23 srs_wkt='GEOGCS["GCS_WGS_1984",DATUM["WGS_1984",SPHEROID["WGS_84",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]'), 24 24 ) 25 25 26 26 bad_ds = (TestDS('foo'), -
django/contrib/gis/gdal/tests/test_geom.py
diff --git a/django/contrib/gis/gdal/tests/test_geom.py b/django/contrib/gis/gdal/tests/test_geom.py index a0b2593..c12bc76 100644
a b from django.contrib.gis.gdal import (OGRGeometry, OGRGeomType, OGRException, 8 8 OGRIndexError, SpatialReference, CoordTransform, GDAL_VERSION) 9 9 from django.contrib.gis.geometry.test_data import TestDataMixin 10 10 from django.utils.six.moves import xrange 11 from django.utils import simplejson 11 12 from django.utils import unittest 12 13 13 14 class OGRGeomTest(unittest.TestCase, TestDataMixin): … … class OGRGeomTest(unittest.TestCase, TestDataMixin): 111 112 for g in self.geometries.json_geoms: 112 113 geom = OGRGeometry(g.wkt) 113 114 if not hasattr(g, 'not_equal'): 114 self.assertEqual( g.json, geom.json)115 self.assertEqual( g.json, geom.geojson)115 self.assertEqual(simplejson.loads(g.json), simplejson.loads(geom.json)) 116 self.assertEqual(simplejson.loads(g.json), simplejson.loads(geom.geojson)) 116 117 self.assertEqual(OGRGeometry(g.wkt), OGRGeometry(geom.json)) 117 118 118 119 def test02_points(self): -
django/contrib/gis/geos/tests/test_geos.py
diff --git a/django/contrib/gis/geos/tests/test_geos.py b/django/contrib/gis/geos/tests/test_geos.py index d621c6b..0969e23 100644
a b from django.contrib.gis.geometry.test_data import TestDataMixin 10 10 11 11 from django.utils import six 12 12 from django.utils.six.moves import xrange 13 from django.utils import simplejson 13 14 from django.utils import unittest 14 15 15 16 … … class GEOSTest(unittest.TestCase, TestDataMixin): 204 205 for g in self.geometries.json_geoms: 205 206 geom = GEOSGeometry(g.wkt) 206 207 if not hasattr(g, 'not_equal'): 207 self.assertEqual( g.json, geom.json)208 self.assertEqual( g.json, geom.geojson)208 self.assertEqual(simplejson.loads(g.json), simplejson.loads(geom.json)) 209 self.assertEqual(simplejson.loads(g.json), simplejson.loads(geom.geojson)) 209 210 self.assertEqual(GEOSGeometry(g.wkt), GEOSGeometry(geom.json)) 210 211 211 212 def test_fromfile(self): -
docs/ref/contrib/gis/install.txt
diff --git a/docs/ref/contrib/gis/install.txt b/docs/ref/contrib/gis/install.txt index 72bd72a..70b1085 100644
a b supported versions, and any notes for each of the supported database backends: 63 63 ================== ============================== ================== ========================================================== 64 64 Database Library Requirements Supported Versions Notes 65 65 ================== ============================== ================== ========================================================== 66 PostgreSQL GEOS, PROJ.4, PostGIS 8.1+ Requires PostGIS.66 PostgreSQL GEOS, GDAL, PROJ.4, PostGIS 8.2+ Requires PostGIS. 67 67 MySQL GEOS 5.x Not OGC-compliant; limited functionality. 68 68 Oracle GEOS 10.2, 11 XE not supported; not tested with 9. 69 69 SQLite GEOS, GDAL, PROJ.4, SpatiaLite 3.6.+ Requires SpatiaLite 2.3+, pysqlite2 2.5+, and Django 1.1. … … Program Description Required 81 81 ======================== ==================================== ================================ ========================== 82 82 :ref:`GEOS <ref-geos>` Geometry Engine Open Source Yes 3.3, 3.2, 3.1, 3.0 83 83 `PROJ.4`_ Cartographic Projections library Yes (PostgreSQL and SQLite only) 4.7, 4.6, 4.5, 4.4 84 :ref:`GDAL <ref-gdal>` Geospatial Data Abstraction Library No (but, required for SQLite) 1.9, 1.8, 1.7, 1.6, 1.5 84 :ref:`GDAL <ref-gdal>` Geospatial Data Abstraction Library No (but, required for SQLite 85 and PostgreSQL) 1.9, 1.8, 1.7, 1.6, 1.5 85 86 :ref:`GeoIP <ref-geoip>` IP-based geolocation library No 1.4 86 `PostGIS`__ Spatial extensions for PostgreSQL Yes (PostgreSQL only) 1.5, 1.4, 1.387 `PostGIS`__ Spatial extensions for PostgreSQL Yes (PostgreSQL only) 2.0, 1.5, 1.4, 1.3 87 88 `SpatiaLite`__ Spatial extensions for SQLite Yes (SQLite only) 3.0, 2.4, 2.3 88 89 ======================== ==================================== ================================ ========================== 89 90 … … internal geometry representation used by GeoDjango (it's behind the "lazy" 140 141 geometries). Specifically, the C API library is called (e.g., ``libgeos_c.so``) 141 142 directly from Python using ctypes. 142 143 143 First, download GEOS 3. 2from the refractions Web site and untar the source144 First, download GEOS 3.3.5 from the refractions Web site and untar the source 144 145 archive:: 145 146 146 $ wget http://download.osgeo.org/geos/geos-3.3. 0.tar.bz2147 $ tar xjf geos-3.3. 0.tar.bz2147 $ wget http://download.osgeo.org/geos/geos-3.3.5.tar.bz2 148 $ tar xjf geos-3.3.5.tar.bz2 148 149 149 150 Next, change into the directory where GEOS was unpacked, run the configure 150 151 script, compile, and install:: 151 152 152 $ cd geos-3.3. 0153 $ cd geos-3.3.5 153 154 $ ./configure 154 155 $ make 155 156 $ sudo make install … … Finally, configure, make and install PROJ.4:: 221 222 $ sudo make install 222 223 $ cd .. 223 224 224 .. _postgis:225 226 PostGIS227 -------228 229 `PostGIS`__ adds geographic object support to PostgreSQL, turning it230 into a spatial database. :ref:`geosbuild` and :ref:`proj4` should be231 installed prior to building PostGIS.232 233 .. note::234 235 The `psycopg2`_ module is required for use as the database adaptor236 when using GeoDjango with PostGIS.237 238 .. _psycopg2: http://initd.org/psycopg/239 240 First download the source archive, and extract::241 242 $ wget http://postgis.refractions.net/download/postgis-1.5.2.tar.gz243 $ tar xzf postgis-1.5.2.tar.gz244 $ cd postgis-1.5.2245 246 Next, configure, make and install PostGIS::247 248 $ ./configure249 250 Finally, make and install::251 252 $ make253 $ sudo make install254 $ cd ..255 256 .. note::257 258 GeoDjango does not automatically create a spatial database. Please259 consult the section on :ref:`spatialdb_template` for more information.260 261 __ http://postgis.refractions.net/262 263 225 .. _gdalbuild: 264 226 265 227 GDAL … … file: 359 321 360 322 SetEnv GDAL_DATA /usr/local/share 361 323 324 .. _postgis: 325 326 PostGIS 327 ------- 328 329 `PostGIS`__ adds geographic object support to PostgreSQL, turning it 330 into a spatial database. :ref:`geosbuild`, :ref:`proj4` and 331 :ref:`gdalbuild` should be installed prior to building PostGIS. You 332 might also need additional libraries, see `PostGIS requirements`_. 333 334 .. note:: 335 336 The `psycopg2`_ module is required for use as the database adaptor 337 when using GeoDjango with PostGIS. 338 339 .. _psycopg2: http://initd.org/psycopg/ 340 .. _PostGIS requirements: http://www.postgis.org/documentation/manual-2.0/postgis_installation.html#id2711662 341 342 First download the source archive, and extract:: 343 344 $ wget http://postgis.refractions.net/download/postgis-2.0.1.tar.gz 345 $ tar xzf postgis-2.0.1.tar.gz 346 $ cd postgis-2.0.1 347 348 Next, configure, make and install PostGIS:: 349 350 $ ./configure 351 352 Finally, make and install:: 353 354 $ make 355 $ sudo make install 356 $ cd .. 357 358 .. note:: 359 360 GeoDjango does not automatically create a spatial database. Please consult 361 the section on :ref:`spatialdb_template91` or 362 :ref:`spatialdb_template_earlier` for more information. 363 364 __ http://postgis.refractions.net/ 365 362 366 .. _spatialite: 363 367 364 368 SpatiaLite … … After SQLite has been built with the R*Tree module enabled, get the latest 421 425 SpatiaLite library source and tools bundle from the `download page`__:: 422 426 423 427 $ wget http://www.gaia-gis.it/gaia-sins/libspatialite-sources/libspatialite-amalgamation-2.3.1.tar.gz 424 $ wget http://www.gaia-gis.it/gaia-sins/ libspatialite-sources/spatialite-tools-2.3.1.tar.gz428 $ wget http://www.gaia-gis.it/gaia-sins/spatialite-tools-sources/spatialite-tools-2.3.1.tar.gz 425 429 $ tar xzf libspatialite-amalgamation-2.3.1.tar.gz 426 430 $ tar xzf spatialite-tools-2.3.1.tar.gz 427 431 … … to build and install:: 502 506 Post-installation 503 507 ================= 504 508 505 .. _spatialdb_template: 509 .. _spatialdb_template91: 510 511 Creating a spatial database with PostGIS 2.0 and PostgreSQL 9.1 512 --------------------------------------------------------------- 513 514 PostGIS 2 includes an extension for Postgres 9.1 that can be used to enable 515 spatial functionality:: 516 517 $ createdb <db name> 518 $ psql <db name> 519 > CREATE EXTENSION postgis; 520 > CREATE EXTENSION postgis_topology; 521 522 .. _spatialdb_template_earlier: 523 524 Creating a spatial database template for earlier versions 525 --------------------------------------------------------- 506 526 507 Creating a spatial database template for PostGIS 508 ------------------------------------------------ 527 If you have an earlier version of PostGIS or PostgreSQL, the CREATE 528 EXTENSION isn't available and you need to create the spatial database 529 using the following instructions. 509 530 510 531 Creating a spatial database with PostGIS is different than normal because 511 532 additional SQL must be loaded to enable spatial functionality. Because of … … user. For example, you can use the following to become the ``postgres`` user:: 535 556 Once you're a database super user, then you may execute the following commands 536 557 to create a PostGIS spatial database template:: 537 558 538 $ POSTGIS_SQL_PATH=`pg_config --sharedir`/contrib/postgis- 1.5559 $ POSTGIS_SQL_PATH=`pg_config --sharedir`/contrib/postgis-2.0 539 560 # Creating the template spatial database. 540 561 $ createdb -E UTF8 template_postgis 541 562 $ createlang -d template_postgis plpgsql # Adding PLPGSQL language support. … … http://www.gaia-gis.it/spatialite-2.4.0/ for 2.4):: 605 626 606 627 Then, use the ``spatialite`` command to initialize a spatial database:: 607 628 608 $ spatialite geodjango.db < init_spatialite-2. X.sql629 $ spatialite geodjango.db < init_spatialite-2.3.sql 609 630 610 631 .. note:: 611 632 … … Afterwards, the ``/etc/init.d/postgresql-8.3`` script should be used to manage 1080 1101 the starting and stopping of PostgreSQL. 1081 1102 1082 1103 In addition, the SQL files for PostGIS are placed in a different location on 1083 Debian 5.0 . Thus when :ref:`spatialdb_template ` either:1104 Debian 5.0 . Thus when :ref:`spatialdb_template_earlier` either: 1084 1105 1085 1106 * Create a symbolic link to these files: 1086 1107 … … may be executed from the SQL Shell as the ``postgres`` user:: 1266 1287 .. [#] GeoDjango uses the :func:`~ctypes.util.find_library` routine from 1267 1288 :mod:`ctypes.util` to locate shared libraries. 1268 1289 .. [#] The ``psycopg2`` Windows installers are packaged and maintained by 1269 `Jason Erickson <http://www.stickpeople.com/projects/python/win-psycopg/>`_. 1290 `Jason Erickson <http://www.stickpeople.com/projects/python/win-psycopg/>`_. 1291 No newline at end of file -
docs/releases/1.5.txt
diff --git a/docs/releases/1.5.txt b/docs/releases/1.5.txt index 3a9b2d8..19353f6 100644
a b on the form. 252 252 Miscellaneous 253 253 ~~~~~~~~~~~~~ 254 254 255 * GeoDjango added support for PostGIS 2.0 256 255 257 * GeoDjango dropped support for GDAL < 1.5 256 258 257 259 * :func:`~django.utils.http.int_to_base36` properly raises a :exc:`TypeError`