예제 #1
0
파일: functions.py 프로젝트: erozqba/django
 def as_sqlite(self, compiler, connection):
     geo_field = GeometryField(
         srid=self.srid)  # Fake field to get SRID info
     if geo_field.geodetic(connection):
         raise NotImplementedError(
             "Perimeter cannot use a non-projected field.")
     return super(Perimeter, self).as_sql(compiler, connection)
예제 #2
0
 def as_postgresql(self, compiler, connection):
     geo_field = GeometryField(srid=self.srid)  # Fake field to get SRID info
     if geo_field.geodetic(connection) and not self.source_is_geography():
         raise NotImplementedError("ST_Perimeter cannot use a non-projected non-geography field.")
     dim = min(f.dim for f in self.get_source_fields())
     if dim > 2:
         self.function = connection.ops.perimeter3d
     return super(Perimeter, self).as_sql(compiler, connection)
예제 #3
0
 def as_sqlite(self, compiler, connection):
     geo_field = GeometryField(srid=self.srid)
     if geo_field.geodetic(connection):
         if self.spheroid:
             self.function = 'GeodesicLength'
         else:
             self.function = 'GreatCircleLength'
     return super(Length, self).as_sql(compiler, connection)
예제 #4
0
파일: functions.py 프로젝트: erozqba/django
 def as_sql(self, compiler, connection):
     geo_field = GeometryField(
         srid=self.srid)  # Fake field to get SRID info
     if geo_field.geodetic(
             connection
     ) and not connection.features.supports_length_geodetic:
         raise NotImplementedError(
             "This backend doesn't support Length on geodetic fields")
     return super(Length, self).as_sql(compiler, connection)
예제 #5
0
 def as_postgresql(self, compiler, connection):
     geo_field = GeometryField(
         srid=self.srid)  # Fake field to get SRID info
     if geo_field.geodetic(connection) and not self.source_is_geography():
         raise NotImplementedError(
             "ST_Perimeter cannot use a non-projected non-geography field.")
     dim = min(f.dim for f in self.get_source_fields())
     if dim > 2:
         self.function = connection.ops.perimeter3d
     return super(Perimeter, self).as_sql(compiler, connection)
예제 #6
0
파일: functions.py 프로젝트: PAINER/SITE
 def as_postgresql(self, compiler, connection):
     geo_field = GeometryField(srid=self.srid)  # Fake field to get SRID info
     if self.source_is_geography():
         self.source_expressions.append(Value(self.spheroid))
     elif geo_field.geodetic(connection):
         # Geometry fields with geodetic (lon/lat) coordinates need length_spheroid
         self.function = 'ST_Length_Spheroid'
         self.source_expressions.append(Value(geo_field._spheroid))
     else:
         dim = min(f.dim for f in self.get_source_fields() if f)
         if dim > 2:
             self.function = connection.ops.length3d
     return super(Length, self).as_sql(compiler, connection)
예제 #7
0
 def as_postgresql(self, compiler, connection):
     function = None
     geo_field = GeometryField(srid=self.srid)  # Fake field to get SRID info
     if self.source_is_geography():
         self.source_expressions.append(Value(self.spheroid))
     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(connection)))
     else:
         dim = min(f.dim for f in self.get_source_fields() if f)
         if dim > 2:
             function = connection.ops.length3d
     return super().as_sql(compiler, connection, function=function)
예제 #8
0
 def convert_value(self, value, expression, connection, context):
     if value is None:
         return None
     geo_field = GeometryField(srid=self.srid)  # Fake field to get SRID info
     if geo_field.geodetic(connection):
         dist_att = 'm'
     else:
         units = geo_field.units_name(connection)
         if units:
             dist_att = DistanceMeasure.unit_attname(units)
         else:
             dist_att = None
     if dist_att:
         return DistanceMeasure(**{dist_att: value})
     return value
예제 #9
0
파일: functions.py 프로젝트: PAINER/SITE
 def convert_value(self, value, expression, connection, context):
     if value is None:
         return None
     geo_field = GeometryField(srid=self.srid)  # Fake field to get SRID info
     if geo_field.geodetic(connection):
         dist_att = 'm'
     else:
         units = geo_field.units_name(connection)
         if units:
             dist_att = DistanceMeasure.unit_attname(units)
         else:
             dist_att = None
     if dist_att:
         return DistanceMeasure(**{dist_att: value})
     return value
예제 #10
0
 def as_postgresql(self, compiler, connection):
     function = None
     geo_field = GeometryField(
         srid=self.srid)  # Fake field to get SRID info
     if self.source_is_geography():
         self.source_expressions.append(Value(self.spheroid))
     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(connection)))
     else:
         dim = min(f.dim for f in self.get_source_fields() if f)
         if dim > 2:
             function = connection.ops.length3d
     return super().as_sql(compiler, connection, function=function)
예제 #11
0
파일: functions.py 프로젝트: PAINER/SITE
 def as_postgresql(self, compiler, connection):
     geo_field = GeometryField(srid=self.srid)  # Fake field to get SRID info
     if self.source_is_geography():
         # Set parameters as geography if base field is geography
         for pos, expr in enumerate(
                 self.source_expressions[self.geom_param_pos + 1:], start=self.geom_param_pos + 1):
             if isinstance(expr, GeomValue):
                 expr.geography = True
     elif geo_field.geodetic(connection):
         # Geometry fields with geodetic (lon/lat) coordinates need special distance functions
         if self.spheroid:
             self.function = 'ST_Distance_Spheroid'  # More accurate, resource intensive
             # Replace boolean param by the real spheroid of the base field
             self.source_expressions[2] = Value(geo_field._spheroid)
         else:
             self.function = 'ST_Distance_Sphere'
     return super(Distance, self).as_sql(compiler, connection)
예제 #12
0
 def as_postgresql(self, compiler, connection):
     function = None
     geo_field = GeometryField(
         srid=self.srid)  # Fake field to get SRID info
     if self.source_is_geography():
         # Set parameters as geography if base field is geography
         for pos, expr in enumerate(
                 self.source_expressions[self.geom_param_pos + 1:],
                 start=self.geom_param_pos + 1):
             if isinstance(expr, GeomValue):
                 expr.geography = True
     elif geo_field.geodetic(connection):
         # Geometry fields with geodetic (lon/lat) coordinates need special distance functions
         if self.spheroid:
             # 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)
         else:
             function = connection.ops.spatial_function_name(
                 'DistanceSphere')
     return super().as_sql(compiler, connection, function=function)
예제 #13
0
    def as_postgresql(self, compiler, connection):
        function = None
        geo_field = GeometryField(srid=self.srid)  # Fake field to get SRID info
        expr2 = self.source_expressions[1]
        geography = self.source_is_geography()
        if expr2.output_field.geography != geography:
            if isinstance(expr2, Value):
                expr2.output_field.geography = geography
            else:
                self.source_expressions[1] = Cast(
                    expr2,
                    GeometryField(srid=expr2.output_field.srid, geography=geography),
                )

        if not geography and geo_field.geodetic(connection):
            # Geometry fields with geodetic (lon/lat) coordinates need special distance functions
            if self.spheroid:
                # 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(connection))
            else:
                function = connection.ops.spatial_function_name('DistanceSphere')
        return super().as_sql(compiler, connection, function=function)
예제 #14
0
    def as_postgresql(self, compiler, connection):
        function = None
        geo_field = GeometryField(srid=self.srid)  # Fake field to get SRID info
        expr2 = self.source_expressions[1]
        geography = self.source_is_geography()
        if expr2.output_field.geography != geography:
            if isinstance(expr2, Value):
                expr2.output_field.geography = geography
            else:
                self.source_expressions[1] = Cast(
                    expr2,
                    GeometryField(srid=expr2.output_field.srid, geography=geography),
                )

        if not geography and geo_field.geodetic(connection):
            # Geometry fields with geodetic (lon/lat) coordinates need special distance functions
            if self.spheroid:
                # 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)
            else:
                function = connection.ops.spatial_function_name('DistanceSphere')
        return super().as_sql(compiler, connection, function=function)
예제 #15
0
파일: functions.py 프로젝트: PAINER/SITE
 def as_sqlite(self, compiler, connection):
     geo_field = GeometryField(srid=self.srid)  # Fake field to get SRID info
     if geo_field.geodetic(connection):
         raise NotImplementedError("Perimeter cannot use a non-projected field.")
     return super(Perimeter, self).as_sql(compiler, connection)
예제 #16
0
 def as_sqlite(self, compiler, connection):
     function = None
     geo_field = GeometryField(srid=self.srid)
     if geo_field.geodetic(connection):
         function = 'GeodesicLength' if self.spheroid else 'GreatCircleLength'
     return super().as_sql(compiler, connection, function=function)
예제 #17
0
파일: functions.py 프로젝트: PAINER/SITE
 def as_sql(self, compiler, connection):
     geo_field = GeometryField(srid=self.srid)  # Fake field to get SRID info
     if geo_field.geodetic(connection) and not connection.features.supports_length_geodetic:
         raise NotImplementedError("This backend doesn't support Length on geodetic fields")
     return super(Length, self).as_sql(compiler, connection)
예제 #18
0
 def as_sqlite(self, compiler, connection):
     function = None
     geo_field = GeometryField(srid=self.srid)
     if geo_field.geodetic(connection):
         function = 'GeodesicLength' if self.spheroid else 'GreatCircleLength'
     return super().as_sql(compiler, connection, function=function)
예제 #19
0
from decimal import Decimal