GeoDjango 中的地理模式距离 - PostGIS 1.5
我在模型中存储一个名为“坐标”的 PointField 字段。
然后,我在命令解释器中查询距给定实例最近的实例,并打印其名称和以公里为单位的距离。
[(p.name, p.distance.m) for p in Model_Name.objects.filter(
coordinates__distance_lte=(pnt, 1000000)).distance(pnt)]
问题是,当字段“坐标”是几何类型时,它会很好地工作。但是,如果我包含选项“geography=True”,为了获得更好的精度,它会返回一个小得多的值,即使我指示像以前一样以公里为单位打印它。
如何获得正确的地理计算?
谢谢
I store a PointField field named "coordinates" in a model.
Then, I consult nearest instances from a given one, in the command interpreter, and print its name and the distance in km.
[(p.name, p.distance.m) for p in Model_Name.objects.filter(
coordinates__distance_lte=(pnt, 1000000)).distance(pnt)]
The thing is, when the field "coordinates" is of kind geometry, it works well. But if I include the option "geography=True", to get better precision, it returns a much smaller value, even that I am indicating to print it in km as before.
How can I get correct geography calculations?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 .距离() 附加到末尾查询集将导致 geoqueryset 中的每个对象都用距离对象进行注释。您可以使用该距离对象来获取不同单位的距离。
但是在 django 1.9 中,它们 移动了目标柱,而附加 .distance() 仍然有效,现在推荐的方法是
最后,而不是使用
coordinates__distance_lte
有一个postgis和mysql 5.7中提供了更快的方法: dwithinAppending .distance() to the end of the query set would result in each object in the geoqueryset being annotated with a distance object. And you can use that distance object to get distances in different units.
However in django 1.9 they moved the goal posts, while appending .distance() still works, now the recommended way is to do
Finally, instead of using
coordinates__distance_lte
there is a much faster method available in postgis and mysql 5.7: dwithin