Esempio n. 1
1
 def area(self, tolerance=0.05, **kwargs):
     """
     Returns the area of the geographic field in an `area` attribute on
     each element of this GeoQuerySet.
     """
     # Performing setup here rather than in `_spatial_attribute` so that
     # we can get the units for `AreaField`.
     procedure_args, geo_field = self._spatial_setup(
         'area', field_name=kwargs.get('field_name'))
     s = {'procedure_args': procedure_args,
          'geo_field': geo_field,
          'setup': False,
          }
     connection = connections[self.db]
     backend = connection.ops
     if backend.oracle:
         s['procedure_fmt'] = '%(geo_col)s,%(tolerance)s'
         s['procedure_args']['tolerance'] = tolerance
         s['select_field'] = AreaField('sq_m')  # Oracle returns area in units of meters.
     elif backend.postgis or backend.spatialite:
         if backend.geography:
             # Geography fields support area calculation, returns square meters.
             s['select_field'] = AreaField('sq_m')
         elif not geo_field.geodetic(connection):
             # Getting the area units of the geographic field.
             s['select_field'] = AreaField(Area.unit_attname(geo_field.units_name(connection)))
         else:
             # TODO: Do we want to support raw number areas for geodetic fields?
             raise Exception('Area on geodetic coordinate systems not supported.')
     return self._spatial_attribute('area', s, **kwargs)
Esempio n. 2
0
 def area(self, tolerance=0.05, **kwargs):
     """
     Returns the area of the geographic field in an `area` attribute on
     each element of this GeoQuerySet.
     """
     # Peforming setup here rather than in `_spatial_attribute` so that
     # we can get the units for `AreaField`.
     procedure_args, geo_field = self._spatial_setup("area", field_name=kwargs.get("field_name", None))
     s = {"procedure_args": procedure_args, "geo_field": geo_field, "setup": False}
     connection = connections[self.db]
     backend = connection.ops
     if backend.oracle:
         s["procedure_fmt"] = "%(geo_col)s,%(tolerance)s"
         s["procedure_args"]["tolerance"] = tolerance
         s["select_field"] = AreaField("sq_m")  # Oracle returns area in units of meters.
     elif backend.postgis or backend.spatialite:
         if backend.geography:
             # Geography fields support area calculation, returns square meters.
             s["select_field"] = AreaField("sq_m")
         elif not geo_field.geodetic(connection):
             # Getting the area units of the geographic field.
             s["select_field"] = AreaField(Area.unit_attname(geo_field.units_name(connection)))
         else:
             # TODO: Do we want to support raw number areas for geodetic fields?
             raise Exception("Area on geodetic coordinate systems not supported.")
     return self._spatial_attribute("area", s, **kwargs)
Esempio n. 3
0
 def get_area_att_for_field(self, field):
     if field.geodetic(self.connection):
         if self.connection.features.supports_area_geodetic:
             return 'sq_m'
         raise NotImplementedError('Area on geodetic coordinate systems not supported.')
     else:
         units_name = field.units_name(self.connection)
         if units_name:
             return AreaMeasure.unit_attname(units_name)
Esempio n. 4
0
 def get_area_att_for_field(self, field):
     if field.geodetic(self.connection):
         if self.connection.features.supports_area_geodetic:
             return 'sq_m'
         raise NotImplementedError('Area on geodetic coordinate systems not supported.')
     else:
         units_name = field.units_name(self.connection)
         if units_name:
             return AreaMeasure.unit_attname(units_name)
Esempio n. 5
0
 def as_sql(self, compiler, connection):
     if connection.ops.geography:
         self.output_field.area_att = 'sq_m'
     else:
         # 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)
Esempio n. 6
0
 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()
     else:
         # TODO: Do we want to support raw number areas for geodetic fields?
         raise NotImplementedError("Area on geodetic coordinate systems not supported.")
     return super(Area, self).as_sql(compiler, connection)
Esempio n. 7
0
 def as_sql(self, compiler, connection, **extra_context):
     if connection.ops.geography:
         self.output_field.area_att = 'sq_m'
     else:
         # Getting the area units of the geographic field.
         if self.geo_field.geodetic(connection):
             if connection.features.supports_area_geodetic:
                 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.')
         else:
             units_name = self.geo_field.units_name(connection)
             if units_name:
                 self.output_field.area_att = AreaMeasure.unit_attname(units_name)
     return super().as_sql(compiler, connection, **extra_context)
Esempio n. 8
0
 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()
     else:
         # TODO: Do we want to support raw number areas for geodetic fields?
         raise NotImplementedError('Area on geodetic coordinate systems not supported.')
     return super(Area, self).as_sql(compiler, connection)
Esempio n. 9
0
 def as_sql(self, compiler, connection, **extra_context):
     if connection.ops.geography:
         self.output_field.area_att = 'sq_m'
     else:
         # Getting the area units of the geographic field.
         geo_field = self.geo_field
         if geo_field.geodetic(connection):
             if connection.features.supports_area_geodetic:
                 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.')
         else:
             units_name = geo_field.units_name(connection)
             if units_name:
                 self.output_field.area_att = AreaMeasure.unit_attname(units_name)
     return super().as_sql(compiler, connection, **extra_context)
Esempio n. 10
0
from decimal import Decimal
Esempio n. 11
0
import warnings