functions.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:django 作者: alexsukhrin 项目源码 文件源码
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:
                # DistanceSpheroid is more accurate and resource intensive than DistanceSphere
                self.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:
                self.function = connection.ops.spatial_function_name('DistanceSphere')
        return super(Distance, self).as_sql(compiler, connection)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号