Geodjango 与 Mysql 坐标/多边形精度
我创建了一个与 MySQL 一起使用的 geodjango 数据库。
我的问题是,当我使用 PolygonField 添加新记录然后检查 对于一个点,如果它位于这个多边形内,我会得到错误的结果(比我应该有的点更多)。我使用 [Location.objects.filter(shape__contains='POINT(-0.058188 51.504289)')] 来检查多边形内部的点。
我的模型是:
class Location(models.Model):
locationId = models.IntegerField(unique=True)
shape = models.PolygonField(null=True, blank=True)
objects = models.GeoManager()
将我的形状添加到我使用的数据库中:
polygon = Polygon(((-0.076406999999999975,51.495287999999995),(-0.076412999999999953,51.495159000000008), …(-0.076406999999999975,51.495287999999995)))
请参阅此图片 https://i.sstatic .net/qRSnX.png 即使在 geodjango admin 的地图上,我们也可以看到该多边形的边界不在正确的位置。
我使用像这样的简单 python 脚本来将我的结果与 geodjango 进行比较: http://geospatialpython.com/2011/01/point-in-polygon.html
谢谢你的帮助
I've created a geodjango database working with MySQL.
My problem is that when I add a new record with a PolygonField and then check
for a point if it is inside this polygon I get a wrong results (more points then I should have). I use [Location.objects.filter(shape__contains='POINT(-0.058188 51.504289)')]
to check for a point inside a polygon shape.
My model is:
class Location(models.Model):
locationId = models.IntegerField(unique=True)
shape = models.PolygonField(null=True, blank=True)
objects = models.GeoManager()
To add my shape into a database I used:
polygon = Polygon(((-0.076406999999999975,51.495287999999995),(-0.076412999999999953,51.495159000000008), …(-0.076406999999999975,51.495287999999995)))
Please see this image https://i.sstatic.net/qRSnX.png
Even on the map in geodjango admin we can see that the boarders of this polygon are not in the correct pleace.
I was using a simple python script like this to compare my results with geodjango:
http://geospatialpython.com/2011/01/point-in-polygon.html
Thank you for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
引用贾斯汀·波隆的话:
它实际上执行的是 bbcontains 而不是 contains,并且以不可靠的结果而闻名。 https://code.djangoproject.com/ticket/13430
我建议迁移到 PostgreSQL。
如果这不是一个选项,我没有答案。
Quote Justin Bronn:
Instead of contains it actually executes bbcontains, and is well known for unreliable results. https://code.djangoproject.com/ticket/13430
I'd suggest moving to PostgreSQL.
I don't have answer if it's not an option.
感谢您的帮助。最后,我使用了两阶段方法:
** - 第一步**是使用 shape__contains 检查结果列表
** - 第二步** 是循环遍历这些结果并检查某个点是否位于这些多边形内部使用 Polygon.Intersects(locationPoint)
Thank you for your help. Finally I've used a two-phase approach:
** - First step** is to check for a list of results using shape__contains
** - Second step** is to loop through those results and check if a point is inside those polygons using polygon.intersects(locationPoint)