Removed connection agnostic SRID info cache from BaseSpatialField.
This commit is contained in:
parent
d3cf75ec6f
commit
24ae244a82
|
@ -96,7 +96,7 @@ class PostGISDistanceOperator(PostGISOperator):
|
||||||
sql_template = '%(func)s(%(lhs)s, %(rhs)s, %%s) %(op)s %(value)s'
|
sql_template = '%(func)s(%(lhs)s, %(rhs)s, %%s) %(op)s %(value)s'
|
||||||
# Using DistanceSpheroid requires the spheroid of the field as
|
# Using DistanceSpheroid requires the spheroid of the field as
|
||||||
# a parameter.
|
# a parameter.
|
||||||
sql_params.insert(1, lookup.lhs.output_field._spheroid)
|
sql_params.insert(1, lookup.lhs.output_field.spheroid(connection))
|
||||||
else:
|
else:
|
||||||
template_params.update({'op': self.op, 'func': connection.ops.spatial_function_name('DistanceSphere')})
|
template_params.update({'op': self.op, 'func': connection.ops.spatial_function_name('DistanceSphere')})
|
||||||
return sql_template % template_params, sql_params
|
return sql_template % template_params, sql_params
|
||||||
|
|
|
@ -115,26 +115,14 @@ class BaseSpatialField(Field):
|
||||||
def db_type(self, connection):
|
def db_type(self, connection):
|
||||||
return connection.ops.geo_db_type(self)
|
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):
|
def spheroid(self, connection):
|
||||||
if not hasattr(self, '_spheroid'):
|
return get_srid_info(self.srid, connection)[2]
|
||||||
self._get_srid_info(connection)
|
|
||||||
return self._spheroid
|
|
||||||
|
|
||||||
def units(self, connection):
|
def units(self, connection):
|
||||||
if not hasattr(self, '_units'):
|
return get_srid_info(self.srid, connection)[0]
|
||||||
self._get_srid_info(connection)
|
|
||||||
return self._units
|
|
||||||
|
|
||||||
def units_name(self, connection):
|
def units_name(self, connection):
|
||||||
if not hasattr(self, '_units_name'):
|
return get_srid_info(self.srid, connection)[1]
|
||||||
self._get_srid_info(connection)
|
|
||||||
return self._units_name
|
|
||||||
|
|
||||||
def geodetic(self, connection):
|
def geodetic(self, connection):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -301,7 +301,7 @@ class Distance(DistanceResultMixin, OracleToleranceMixin, GeoFunc):
|
||||||
# DistanceSpheroid is more accurate and resource intensive than DistanceSphere
|
# DistanceSpheroid is more accurate and resource intensive than DistanceSphere
|
||||||
function = connection.ops.spatial_function_name('DistanceSpheroid')
|
function = connection.ops.spatial_function_name('DistanceSpheroid')
|
||||||
# Replace boolean param by the real spheroid of the base field
|
# 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:
|
else:
|
||||||
function = connection.ops.spatial_function_name('DistanceSphere')
|
function = connection.ops.spatial_function_name('DistanceSphere')
|
||||||
return super().as_sql(compiler, connection, function=function)
|
return super().as_sql(compiler, connection, function=function)
|
||||||
|
@ -380,7 +380,7 @@ class Length(DistanceResultMixin, OracleToleranceMixin, GeoFunc):
|
||||||
elif geo_field.geodetic(connection):
|
elif geo_field.geodetic(connection):
|
||||||
# Geometry fields with geodetic (lon/lat) coordinates need length_spheroid
|
# Geometry fields with geodetic (lon/lat) coordinates need length_spheroid
|
||||||
function = connection.ops.spatial_function_name('LengthSpheroid')
|
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:
|
else:
|
||||||
dim = min(f.dim for f in self.get_source_fields() if f)
|
dim = min(f.dim for f in self.get_source_fields() if f)
|
||||||
if dim > 2:
|
if dim > 2:
|
||||||
|
|
Loading…
Reference in New Issue