我有一堆基于多边形的区域:
regions = Region.objects.filter(criteria=criteria)
模型定义如下:
class Region(models.Model):
poly = models.PolygonField()
我有一个基于点的模型,如下所示:
class Example(models.Model):
point = models.PointField()
有没有办法获取位于查询集中任意多边形内的所有Example实例? 我在文档中找不到与此相关的任何信息。提前致谢!
最佳答案
模型.py:
from django.contrib.gis import models
class Example(models.Model):
point = models.PointField()
objects = models.GeoManager()
您从所有这些区域中构建一个多边形,并询问该多边形内有什么示例
from django.contrib.gis.geos import MultiPolygon
list_poly = [reg.poly for reg in Region.objects.filter(criteria=criteria)]
multipolygon = MultiPolygon(list_poly)
list_examples = Example.objects.filter(point__within=multipolygon)
关于python - 在 GeoDjango 中查找一组多边形内的模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27391689/