python - Django属性错误: 'GeoQuerySet' object has no attribute 'extent'

标签 python django geo django-1.10

我的 django 代码已损坏并引发以下 AttributeError:

AttributeError: 'GeoQuerySet' object has no attribute 'extent'

在我的代码中,我尝试在 django geoqueryset 上调用范围:

    if raster and bbox:
        self.extent = qs.extent()

我的 Django 版本当前是 1.10,最近从 Django 1.9 升级。

最佳答案

这是因为 Django deprecated自 Django 版本 1.8 起,GeoQuerySet 上的 extent 方法。可以使用 Extent Aggregate Function 来修复此问题像这样:

from django.contrib.gis.db.models import Extent   

# ...

    if raster and bbox:
        self.extent = qs.aggregate(Extent('geometry')).get(
            'geometry__extent')

关于python - Django属性错误: 'GeoQuerySet' object has no attribute 'extent' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45051785/

相关文章:

geolocation - 安全(通过 https)IP 地址查找 API 服务

php - 使用 MySQL 空间数据在 Google map 上获取最近的地点

python - 使用 pandas 操作创建派生列

python:如何从一天内的时间步中获取最大聚合值?

python - 在python中使用pandoc将Docx转换为pdf

django - 我无法更改 django drf 中的日期格式

javascript - d3 geo - map 投影

python - 如何在 matplotlib 中使用绘图文件?

Python 错误 : xlsxwriter. exceptions.FileCreateError: [Errno 2] No such file or directory: ''

django - 反向为 'edit',未找到任何参数。尝试了 1 个模式 : ['articles/edit/(?P<pk>[0-9]+)/$' ]