diff options
| author | Claude Paroz <claude@2xlibre.net> | 2014-11-03 22:03:59 +0100 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2015-03-18 19:27:44 +0100 |
| commit | 65129aac07022f23afa1df7ec7fad2216634cb38 (patch) | |
| tree | cabff468510d5a964dfaec06ce71205455a5bdeb /django | |
| parent | b4a56ed4f55502239cb11b57f0fa75baa0a97640 (diff) | |
Fixed #23757 -- Added 3D introspection support to Spatialite backend
Thanks Tim Graham for the review.
Diffstat (limited to 'django')
4 files changed, 16 insertions, 2 deletions
diff --git a/django/contrib/gis/db/backends/base/features.py b/django/contrib/gis/db/backends/base/features.py index ecefde493b..13da494814 100644 --- a/django/contrib/gis/db/backends/base/features.py +++ b/django/contrib/gis/db/backends/base/features.py @@ -14,6 +14,8 @@ class BaseSpatialFeatures(object): # Does the backend introspect GeometryField to its subtypes? supports_geometry_field_introspection = True + # Does the backend support storing 3D geometries? + supports_3d_storage = False # Reference implementation of 3D functions is: # http://postgis.net/docs/PostGIS_Special_Functions_Index.html#PostGIS_3D_Functions supports_3d_functions = False diff --git a/django/contrib/gis/db/backends/postgis/features.py b/django/contrib/gis/db/backends/postgis/features.py index 1cc15bde38..181c859641 100644 --- a/django/contrib/gis/db/backends/postgis/features.py +++ b/django/contrib/gis/db/backends/postgis/features.py @@ -4,5 +4,6 @@ from django.db.backends.postgresql_psycopg2.features import \ class DatabaseFeatures(BaseSpatialFeatures, Psycopg2DatabaseFeatures): + supports_3d_storage = True supports_3d_functions = True supports_left_right_lookups = True diff --git a/django/contrib/gis/db/backends/spatialite/features.py b/django/contrib/gis/db/backends/spatialite/features.py index 613087b51e..5bc4b88de8 100644 --- a/django/contrib/gis/db/backends/spatialite/features.py +++ b/django/contrib/gis/db/backends/spatialite/features.py @@ -1,4 +1,5 @@ from django.contrib.gis.db.backends.base.features import BaseSpatialFeatures +from django.contrib.gis.geos import geos_version from django.db.backends.sqlite3.features import \ DatabaseFeatures as SQLiteDatabaseFeatures from django.utils.functional import cached_property @@ -15,3 +16,7 @@ class DatabaseFeatures(BaseSpatialFeatures, SQLiteDatabaseFeatures): # which can result in a significant performance improvement when # creating the database. return self.connection.ops.spatial_version >= (4, 1, 0) + + @cached_property + def supports_3d_storage(self): + return geos_version() >= '3.3' diff --git a/django/contrib/gis/db/backends/spatialite/introspection.py b/django/contrib/gis/db/backends/spatialite/introspection.py index c1ed7629b9..4222c04f8b 100644 --- a/django/contrib/gis/db/backends/spatialite/introspection.py +++ b/django/contrib/gis/db/backends/spatialite/introspection.py @@ -41,7 +41,13 @@ class SpatiaLiteIntrospection(DatabaseIntrospection): # OGRGeomType does not require GDAL and makes it easy to convert # from OGC geom type name to Django field. - field_type = OGRGeomType(row[2]).django + ogr_type = row[2] + if isinstance(ogr_type, six.integer_types) and ogr_type > 1000: + # Spatialite versions >= 4 use the new SFSQL 1.2 offsets + # 1000 (Z), 2000 (M), and 3000 (ZM) to indicate the presence of + # higher dimensional coordinates (M not yet supported by Django). + ogr_type = ogr_type % 1000 + OGRGeomType.wkb25bit + field_type = OGRGeomType(ogr_type).django # Getting any GeometryField keyword arguments that are not the default. dim = row[0] @@ -49,7 +55,7 @@ class SpatiaLiteIntrospection(DatabaseIntrospection): field_params = {} if srid != 4326: field_params['srid'] = srid - if isinstance(dim, six.string_types) and 'Z' in dim: + if (isinstance(dim, six.string_types) and 'Z' in dim) or dim == 3: field_params['dim'] = 3 finally: cursor.close() |
