1
0
mirror of https://github.com/django/django.git synced 2025-10-26 23:26:08 +00:00

Fixed #26112 -- Error when computing aggregate of GIS areas.

Thanks Simon Charette and Claude Paroz for the reviews.
This commit is contained in:
Daniel Wiesmann
2016-01-22 11:03:05 +00:00
committed by Claude Paroz
parent 16baec5c8a
commit a08d2463d2
4 changed files with 36 additions and 16 deletions

View File

@@ -117,24 +117,23 @@ class OracleToleranceMixin(object):
class Area(OracleToleranceMixin, GeoFunc):
output_field_class = AreaField
arity = 1
def as_sql(self, compiler, connection):
if connection.ops.geography:
# Geography fields support area calculation, returns square meters.
self.output_field = AreaField('sq_m')
elif not self.output_field.geodetic(connection):
# Getting the area units of the geographic field.
units = self.output_field.units_name(connection)
if units:
self.output_field = AreaField(
AreaMeasure.unit_attname(self.output_field.units_name(connection))
)
else:
self.output_field = FloatField()
self.output_field.area_att = 'sq_m'
else:
# TODO: Do we want to support raw number areas for geodetic fields?
raise NotImplementedError('Area on geodetic coordinate systems not supported.')
# Getting the area units of the geographic field.
source_fields = self.get_source_fields()
if len(source_fields):
source_field = source_fields[0]
if source_field.geodetic(connection):
# TODO: Do we want to support raw number areas for geodetic fields?
raise NotImplementedError('Area on geodetic coordinate systems not supported.')
units_name = source_field.units_name(connection)
if units_name:
self.output_field.area_att = AreaMeasure.unit_attname(units_name)
return super(Area, self).as_sql(compiler, connection)
def as_oracle(self, compiler, connection):

View File

@@ -21,13 +21,14 @@ class BaseField(object):
class AreaField(BaseField):
"Wrapper for Area values."
def __init__(self, area_att):
def __init__(self, area_att=None):
self.area_att = area_att
def from_db_value(self, value, expression, connection, context):
if connection.features.interprets_empty_strings_as_nulls and value == '':
value = None
if value is not None:
# If the units are known, convert value into area measure.
if value is not None and self.area_att:
value = Area(**{self.area_att: value})
return value