summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorFrancisco Couzo <franciscouzo@gmail.com>2019-03-20 13:54:42 -0300
committerTim Graham <timograham@gmail.com>2019-03-20 12:54:42 -0400
commit0193bf874f08f21cdec628b8d80d261471bfe5fc (patch)
treee095cbff7cd8c6a0abf98f2378f1d99747daa5dc /django
parent638d5ea37557a668f59d76bb34ee4e076787b524 (diff)
Fixed #28738 -- Added the GeometryDistance function.
Diffstat (limited to 'django')
-rw-r--r--django/contrib/gis/db/backends/base/operations.py8
-rw-r--r--django/contrib/gis/db/backends/mysql/operations.py6
-rw-r--r--django/contrib/gis/db/backends/oracle/operations.py4
-rw-r--r--django/contrib/gis/db/backends/spatialite/operations.py2
-rw-r--r--django/contrib/gis/db/models/functions.py10
5 files changed, 19 insertions, 11 deletions
diff --git a/django/contrib/gis/db/backends/base/operations.py b/django/contrib/gis/db/backends/base/operations.py
index 860748cc9d..4a2245680f 100644
--- a/django/contrib/gis/db/backends/base/operations.py
+++ b/django/contrib/gis/db/backends/base/operations.py
@@ -40,10 +40,10 @@ class BaseSpatialOperations:
unsupported_functions = {
'Area', 'AsGeoJSON', 'AsGML', 'AsKML', 'AsSVG', 'Azimuth',
'BoundingCircle', 'Centroid', 'Difference', 'Distance', 'Envelope',
- 'GeoHash', 'Intersection', 'IsValid', 'Length', 'LineLocatePoint',
- 'MakeValid', 'MemSize', 'NumGeometries', 'NumPoints', 'Perimeter',
- 'PointOnSurface', 'Reverse', 'Scale', 'SnapToGrid', 'SymDifference',
- 'Transform', 'Translate', 'Union',
+ 'GeoHash', 'GeometryDistance', 'Intersection', 'IsValid', 'Length',
+ 'LineLocatePoint', 'MakeValid', 'MemSize', 'NumGeometries',
+ 'NumPoints', 'Perimeter', 'PointOnSurface', 'Reverse', 'Scale',
+ 'SnapToGrid', 'SymDifference', 'Transform', 'Translate', 'Union',
}
# Constructors
diff --git a/django/contrib/gis/db/backends/mysql/operations.py b/django/contrib/gis/db/backends/mysql/operations.py
index 1ac8055071..e765e4d879 100644
--- a/django/contrib/gis/db/backends/mysql/operations.py
+++ b/django/contrib/gis/db/backends/mysql/operations.py
@@ -54,9 +54,9 @@ class MySQLOperations(BaseSpatialOperations, DatabaseOperations):
def unsupported_functions(self):
unsupported = {
'AsGML', 'AsKML', 'AsSVG', 'Azimuth', 'BoundingCircle',
- 'ForcePolygonCW', 'LineLocatePoint', 'MakeValid', 'MemSize',
- 'Perimeter', 'PointOnSurface', 'Reverse', 'Scale', 'SnapToGrid',
- 'Transform', 'Translate',
+ 'ForcePolygonCW', 'GeometryDistance', 'LineLocatePoint',
+ 'MakeValid', 'MemSize', 'Perimeter', 'PointOnSurface', 'Reverse',
+ 'Scale', 'SnapToGrid', 'Transform', 'Translate',
}
if self.connection.mysql_is_mariadb:
unsupported.update({'GeoHash', 'IsValid'})
diff --git a/django/contrib/gis/db/backends/oracle/operations.py b/django/contrib/gis/db/backends/oracle/operations.py
index df052d74fc..f41ce0ed64 100644
--- a/django/contrib/gis/db/backends/oracle/operations.py
+++ b/django/contrib/gis/db/backends/oracle/operations.py
@@ -107,8 +107,8 @@ class OracleOperations(BaseSpatialOperations, DatabaseOperations):
unsupported_functions = {
'AsGeoJSON', 'AsKML', 'AsSVG', 'Azimuth', 'ForcePolygonCW', 'GeoHash',
- 'LineLocatePoint', 'MakeValid', 'MemSize', 'Scale', 'SnapToGrid',
- 'Translate',
+ 'GeometryDistance', 'LineLocatePoint', 'MakeValid', 'MemSize',
+ 'Scale', 'SnapToGrid', 'Translate',
}
def geo_quote_name(self, name):
diff --git a/django/contrib/gis/db/backends/spatialite/operations.py b/django/contrib/gis/db/backends/spatialite/operations.py
index bbce44b9df..a1c049b562 100644
--- a/django/contrib/gis/db/backends/spatialite/operations.py
+++ b/django/contrib/gis/db/backends/spatialite/operations.py
@@ -79,7 +79,7 @@ class SpatiaLiteOperations(BaseSpatialOperations, DatabaseOperations):
@cached_property
def unsupported_functions(self):
- unsupported = {'BoundingCircle', 'MemSize'}
+ unsupported = {'BoundingCircle', 'GeometryDistance', 'MemSize'}
if not self.lwgeom_version():
unsupported |= {'Azimuth', 'GeoHash', 'IsValid', 'MakeValid'}
return unsupported
diff --git a/django/contrib/gis/db/models/functions.py b/django/contrib/gis/db/models/functions.py
index c1ae4ae445..a79067a45a 100644
--- a/django/contrib/gis/db/models/functions.py
+++ b/django/contrib/gis/db/models/functions.py
@@ -48,7 +48,7 @@ class GeoFuncMixin:
return self.source_expressions[self.geom_param_pos[0]].field
def as_sql(self, compiler, connection, function=None, **extra_context):
- if not self.function and not function:
+ if self.function is None and function is None:
function = connection.ops.spatial_function_name(self.name)
return super().as_sql(compiler, connection, function=function, **extra_context)
@@ -299,6 +299,14 @@ class GeoHash(GeoFunc):
return clone.as_sql(compiler, connection, **extra_context)
+class GeometryDistance(GeoFunc):
+ output_field = FloatField()
+ arity = 2
+ function = ''
+ arg_joiner = ' <-> '
+ geom_param_pos = (0, 1)
+
+
class Intersection(OracleToleranceMixin, GeomOutputGeoFunc):
arity = 2
geom_param_pos = (0, 1)