Removed connection agnostic SRID info cache from BaseSpatialField.

This commit is contained in:
Sergey Fedoseev 2017-03-30 18:30:29 +05:00 committed by Tim Graham
parent d3cf75ec6f
commit 24ae244a82
3 changed files with 6 additions and 18 deletions

View File

@ -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

View File

@ -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):
"""

View File

@ -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: