1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed failures with older Spatialite versions

This commit is contained in:
Claude Paroz
2015-04-23 16:23:05 +02:00
parent dd99f57710
commit 6d685b1674
3 changed files with 22 additions and 11 deletions

View File

@@ -80,19 +80,23 @@ class SpatiaLiteOperations(BaseSpatialOperations, DatabaseOperations):
'distance_lte': SpatialOperator(func='Distance', op='<='),
}
function_names = {
'Length': 'ST_Length',
'Reverse': 'ST_Reverse',
'Scale': 'ScaleCoords',
'Translate': 'ST_Translate',
'Union': 'ST_Union',
}
@cached_property
def function_names(self):
return {
'Length': 'ST_Length',
'Reverse': 'ST_Reverse',
'Scale': 'ScaleCoords',
'Translate': 'ST_Translate' if self.spatial_version >= (3, 1, 0) else 'ShiftCoords',
'Union': 'ST_Union',
}
@cached_property
def unsupported_functions(self):
unsupported = {'BoundingCircle', 'ForceRHR', 'GeoHash', 'MemSize'}
if self.spatial_version < (3, 1, 0):
unsupported.add('SnapToGrid')
if self.spatial_version < (4, 0, 0):
unsupported.add('Reverse')
unsupported.update({'Perimeter', 'Reverse'})
return unsupported
@cached_property

View File

@@ -403,9 +403,12 @@ class Transform(GeoFunc):
class Translate(Scale):
def as_sqlite(self, compiler, connection):
# Always provide the z parameter
if len(self.source_expressions) < 4:
func_name = connection.ops.spatial_function_name(self.name)
if func_name == 'ST_Translate' and len(self.source_expressions) < 4:
# Always provide the z parameter for ST_Translate (Spatialite >= 3.1)
self.source_expressions.append(Value(0))
elif func_name == 'ShiftCoords' and len(self.source_expressions) > 3:
raise ValueError("This version of Spatialite doesn't support 3D")
return super(Translate, self).as_sqlite(compiler, connection)