使用Geopy将英里转换为纬度和经度 [英] Conversion of miles to latitude and longitude degrees using geopy

查看:79
本文介绍了使用Geopy将英里转换为纬度和经度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加一个模型管理器功能,该功能基于与坐标的接近程度来过滤查询集.我发现此博客发布的代码正是在执行该操作我想.

I want to add a model manager function that filters a queryset based on the proximity to coordinates. I found this blog posting with code that is doing precisely what I want.

下面的代码段似乎利用了自此之后已删除的 geopy 函数.通过限制纬度和经度的范围,它可以粗略地缩小查询集的范围.

The snippet below seems to make use of geopy functions that have since been removed. It coarsely narrows down the queryset by limiting the range of latitude and longitude.

    # Prune down the set of all locations to something we can quickly check precisely
    rough_distance = geopy.distance.arc_degrees(arcminutes=geopy.distance.nm(miles=distance)) * 2
    queryset = queryset.filter(
        latitude__range=(latitude - rough_distance, latitude + rough_distance), 
        longitude__range=(longitude - rough_distance, longitude + rough_distance)
    )

问题

由于已删除/移动了一些使用的geopy函数,因此我试图重写此节.但是,我不理解这些计算方法-几乎没有通过几何计算,而且我的研究使我感到困惑的多于实际的帮助.

Problem

Since some of the used geopy functions have been removed/moved, I'm trying to rewrite this stanza. However, I do not understand the calculations---barely passed geometry and my research has confused me more than actually helped me.

任何人都可以帮忙吗?我将不胜感激.

Can anyone help? I would greatly appreciate it.

推荐答案

似乎将距离中的距离转换为海里,每个海里等于一分钟的弧度,即1每个弧度的/60分.然后将该值加倍,然后再从给定的纬度和经度中减去该值.这四个值可用于在坐标周围形成边界框.

It looks like distance in miles is being converted to nautical miles, which are each equal to a minute of arc, which are 1/60th of an arc degree each. That value is then doubled, and then added and subtracted from a given latitude and longitude. These four values can be used to form a bounding box around the coordinates.

您可以在维基百科上查找任何所需的转换因子.那里还有一篇相关文章,标题为 水平位置表示 ,讨论了专家和专家经度和纬度定位的替代方案的缺点是避免了某些复杂性.换句话说,关于在计算中将纬度和经度替换为另一个水平位置表示法的考虑因素.

You can lookup any needed conversion factors on Wikipedia. There's also a relevant article there titled Horizontal position representation which discusses pros and cons of alternatives to longitude and latitude positioning which avoid some of their complexities. In other words, about the considerations involved with replacing latitude and longitude with another horizontal position representation in calculations.

这篇关于使用Geopy将英里转换为纬度和经度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆