summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Fedoseev <fedoseev.sergey@gmail.com>2017-03-30 18:30:29 +0500
committerTim Graham <timograham@gmail.com>2017-04-07 12:24:38 -0400
commit24ae244a82634254674414bbb99fe10e4c7c08cc (patch)
tree1a10f12910e5209655788e51e70111df1f0d92ac
parentd3cf75ec6fbdd2c1f1bb1e6ccb48d4de1da2952b (diff)
Removed connection agnostic SRID info cache from BaseSpatialField.
-rw-r--r--django/contrib/gis/db/backends/postgis/operations.py2
-rw-r--r--django/contrib/gis/db/models/fields.py18
-rw-r--r--django/contrib/gis/db/models/functions.py4
3 files changed, 6 insertions, 18 deletions
diff --git a/django/contrib/gis/db/backends/postgis/operations.py b/django/contrib/gis/db/backends/postgis/operations.py
index 62f569c754..49662236c0 100644
--- a/django/contrib/gis/db/backends/postgis/operations.py
+++ b/django/contrib/gis/db/backends/postgis/operations.py
@@ -96,7 +96,7 @@ class PostGISDistanceOperator(PostGISOperator):
sql_template = '%(func)s(%(lhs)s, %(rhs)s, %%s) %(op)s %(value)s'
# Using DistanceSpheroid requires the spheroid of the field as
# a parameter.
- sql_params.insert(1, lookup.lhs.output_field._spheroid)
+ sql_params.insert(1, lookup.lhs.output_field.spheroid(connection))
else:
template_params.update({'op': self.op, 'func': connection.ops.spatial_function_name('DistanceSphere')})
return sql_template % template_params, sql_params
diff --git a/django/contrib/gis/db/models/fields.py b/django/contrib/gis/db/models/fields.py
index 77b81cddd1..737d757664 100644
--- a/django/contrib/gis/db/models/fields.py
+++ b/django/contrib/gis/db/models/fields.py
@@ -115,26 +115,14 @@ class BaseSpatialField(Field):
def db_type(self, connection):
return connection.ops.geo_db_type(self)
- # The following functions are used to get the units, their name, and
- # the spheroid corresponding to the SRID of the BaseSpatialField.
- def _get_srid_info(self, connection):
- # Get attributes from `get_srid_info`.
- self._units, self._units_name, self._spheroid = get_srid_info(self.srid, connection)
-
def spheroid(self, connection):
- if not hasattr(self, '_spheroid'):
- self._get_srid_info(connection)
- return self._spheroid
+ return get_srid_info(self.srid, connection)[2]
def units(self, connection):
- if not hasattr(self, '_units'):
- self._get_srid_info(connection)
- return self._units
+ return get_srid_info(self.srid, connection)[0]
def units_name(self, connection):
- if not hasattr(self, '_units_name'):
- self._get_srid_info(connection)
- return self._units_name
+ return get_srid_info(self.srid, connection)[1]
def geodetic(self, connection):
"""
diff --git a/django/contrib/gis/db/models/functions.py b/django/contrib/gis/db/models/functions.py
index 0f18e7bbde..5dbfdd4e56 100644
--- a/django/contrib/gis/db/models/functions.py
+++ b/django/contrib/gis/db/models/functions.py
@@ -301,7 +301,7 @@ class Distance(DistanceResultMixin, OracleToleranceMixin, GeoFunc):
# DistanceSpheroid is more accurate and resource intensive than DistanceSphere
function = connection.ops.spatial_function_name('DistanceSpheroid')
# Replace boolean param by the real spheroid of the base field
- self.source_expressions[2] = Value(geo_field._spheroid)
+ self.source_expressions[2] = Value(geo_field.spheroid(connection))
else:
function = connection.ops.spatial_function_name('DistanceSphere')
return super().as_sql(compiler, connection, function=function)
@@ -380,7 +380,7 @@ class Length(DistanceResultMixin, OracleToleranceMixin, GeoFunc):
elif geo_field.geodetic(connection):
# Geometry fields with geodetic (lon/lat) coordinates need length_spheroid
function = connection.ops.spatial_function_name('LengthSpheroid')
- self.source_expressions.append(Value(geo_field._spheroid))
+ self.source_expressions.append(Value(geo_field.spheroid(connection)))
else:
dim = min(f.dim for f in self.get_source_fields() if f)
if dim > 2: