Commit 47f22e82 authored by Tim Graham's avatar Tim Graham
Browse files

Fixed #25645 -- Dropped support for SpatiaLite < 4.0.

parent 62e4f8ec
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -29,10 +29,9 @@ class SpatiaLiteIntrospection(DatabaseIntrospection):
        cursor = self.connection.cursor()
        try:
            # Querying the `geometry_columns` table to get additional metadata.
            type_col = 'type' if self.connection.ops.spatial_version < (4, 0, 0) else 'geometry_type'
            cursor.execute('SELECT coord_dimension, srid, %s '
            cursor.execute('SELECT coord_dimension, srid, geometry_type '
                           'FROM geometry_columns '
                           'WHERE f_table_name=%%s AND f_geometry_column=%%s' % type_col,
                           'WHERE f_table_name=%s AND f_geometry_column=%s',
                           (table_name, geo_col))
            row = cursor.fetchone()
            if not row:
+3 −18
Original line number Diff line number Diff line
@@ -2,9 +2,7 @@
 The GeometryColumns and SpatialRefSys models for the SpatiaLite backend.
"""
from django.contrib.gis.db.backends.base.models import SpatialRefSysMixin
from django.contrib.gis.db.backends.spatialite.base import DatabaseWrapper
from django.db import connection, models
from django.db.backends.signals import connection_created
from django.db import models
from django.utils.encoding import python_2_unicode_compatible


@@ -18,6 +16,7 @@ class SpatialiteGeometryColumns(models.Model):
    coord_dimension = models.IntegerField()
    srid = models.IntegerField(primary_key=True)
    spatial_index_enabled = models.IntegerField()
    type = models.IntegerField(db_column='geometry_type')

    class Meta:
        app_label = 'gis'
@@ -55,6 +54,7 @@ class SpatialiteSpatialRefSys(models.Model, SpatialRefSysMixin):
    auth_srid = models.IntegerField()
    ref_sys_name = models.CharField(max_length=256)
    proj4text = models.CharField(max_length=2048)
    srtext = models.CharField(max_length=2048)

    @property
    def wkt(self):
@@ -67,18 +67,3 @@ class SpatialiteSpatialRefSys(models.Model, SpatialRefSysMixin):
        app_label = 'gis'
        db_table = 'spatial_ref_sys'
        managed = False


def add_spatial_version_related_fields(sender, **kwargs):
    """
    Adds fields after establishing a database connection to prevent database
    operations at compile time.
    """
    if connection_created.disconnect(add_spatial_version_related_fields, sender=DatabaseWrapper):
        spatial_version = connection.ops.spatial_version[0]
        if spatial_version >= 4:
            SpatialiteSpatialRefSys.add_to_class('srtext', models.CharField(max_length=2048))
            SpatialiteGeometryColumns.add_to_class('type', models.IntegerField(db_column='geometry_type'))
        else:
            SpatialiteGeometryColumns.add_to_class('type', models.CharField(max_length=30))
connection_created.connect(add_spatial_version_related_fields, sender=DatabaseWrapper)
+4 −9
Original line number Diff line number Diff line
"""
SQL functions reference lists:
http://www.gaia-gis.it/spatialite-3.0.0-BETA/spatialite-sql-3.0.0.html
https://web.archive.org/web/20130407175746/http://www.gaia-gis.it/gaia-sins/spatialite-sql-4.0.0.html
http://www.gaia-gis.it/gaia-sins/spatialite-sql-4.2.1.html
"""
@@ -90,18 +89,14 @@ class SpatiaLiteOperations(BaseSpatialOperations, DatabaseOperations):
            'Length': 'ST_Length',
            'Reverse': 'ST_Reverse',
            'Scale': 'ScaleCoords',
            'Translate': 'ST_Translate' if self.spatial_version >= (3, 1, 0) else 'ShiftCoords',
            'Translate': 'ST_Translate',
            'Union': 'ST_Union',
        }

    @cached_property
    def unsupported_functions(self):
        unsupported = {'BoundingCircle', 'ForceRHR', 'IsValid', 'MakeValid', 'MemSize'}
        if self.spatial_version < (3, 1, 0):
            unsupported.add('SnapToGrid')
        if self.spatial_version < (4, 0, 0):
            unsupported.update({'Perimeter', 'Reverse'})
        elif not self.lwgeom_version():
        if not self.lwgeom_version():
            unsupported.add('GeoHash')
        return unsupported

@@ -116,8 +111,8 @@ class SpatiaLiteOperations(BaseSpatialOperations, DatabaseOperations):
                'database (error was "%s").  Was the SpatiaLite initialization '
                'SQL loaded on this database?') % (self.connection.settings_dict['NAME'], msg)
            six.reraise(ImproperlyConfigured, ImproperlyConfigured(new_msg), sys.exc_info()[2])
        if version < (3, 0, 0):
            raise ImproperlyConfigured('GeoDjango only supports SpatiaLite versions 3.0.0 and above.')
        if version < (4, 0, 0):
            raise ImproperlyConfigured('GeoDjango only supports SpatiaLite versions 4.0.0 and above.')
        return version

    def convert_extent(self, box, srid):
+4 −4
Original line number Diff line number Diff line
@@ -388,7 +388,7 @@ Function PostGIS Oracle MySQL SpatiaLite
:class:`Distance`                     X        X       X (≥ 5.6.1)  X
:class:`Envelope`                     X                X            X
:class:`ForceRHR`                     X
:class:`GeoHash`                      X                             X (≥ 4.0, LWGEOM)
:class:`GeoHash`                      X                             X (LWGEOM)
:class:`Intersection`                 X        X       X (≥ 5.6.1)  X
:class:`IsValid`                      X
:class:`Length`                       X        X       X            X
@@ -396,11 +396,11 @@ Function PostGIS Oracle MySQL SpatiaLite
:class:`MemSize`                      X
:class:`NumGeometries`                X        X       X            X
:class:`NumPoints`                    X        X       X            X
:class:`Perimeter`                    X        X                    X (≥ 4.0)
:class:`Perimeter`                    X        X                    X
:class:`PointOnSurface`               X        X                    X
:class:`Reverse`                      X        X                    X (≥ 4.0)
:class:`Reverse`                      X        X                    X
:class:`Scale`                        X                             X
:class:`SnapToGrid`                   X                             X (≥ 3.1)
:class:`SnapToGrid`                   X                             X
:class:`SymDifference`                X        X       X (≥ 5.6.1)  X
:class:`Transform`                    X        X                    X
:class:`Translate`                    X                             X
+4 −4
Original line number Diff line number Diff line
@@ -263,7 +263,7 @@ right-hand rule.

.. class:: GeoHash(expression, **extra)

*Availability*: PostGIS, SpatiaLite (≥ 4.0, LWGEOM)
*Availability*: PostGIS, SpatiaLite (LWGEOM)

Accepts a single geographic field or expression and returns a `GeoHash`__
representation of the geometry.
@@ -367,7 +367,7 @@ in the first linestring in the geometry field; otherwise returns ``None``.

.. class:: Perimeter(expression, **extra)

*Availability*: PostGIS, Oracle, SpatiaLite (≥ 4.0)
*Availability*: PostGIS, Oracle, SpatiaLite

Accepts a single geographic field or expression and returns the perimeter of the
geometry field as a :class:`~django.contrib.gis.measure.Distance` object. On
@@ -389,7 +389,7 @@ guaranteed to lie on the surface of the field; otherwise returns ``None``.

.. class:: Reverse(expression, **extra)

*Availability*: PostGIS, Oracle, SpatiaLite (≥ 4.0)
*Availability*: PostGIS, Oracle, SpatiaLite

Accepts a single geographic field or expression and returns a geometry with
reversed coordinates.
@@ -410,7 +410,7 @@ scaled coordinates by multiplying them with the ``x``, ``y``, and optionally

.. class:: SnapToGrid(expression, *args, **extra)

*Availability*: PostGIS, SpatiaLite (≥ 3.1)
*Availability*: PostGIS, SpatiaLite

Accepts a single geographic field or expression and returns a geometry with all
points snapped to the given grid.  How the geometry is snapped to the grid
Loading