- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我定义了一个城市模型,它保存城市的 geoname_id
和 location
(作为 GeoPt)。我想实现两件事。
500km
半径范围内的所有城市。km
为单位)。实现此目标的最佳方法是什么,请记住我有一个非常庞大的城市数据库,我不想在性能因素上牺牲太多。感谢您提供任何帮助或建议。
最佳答案
这很完美,但是有点慢:
计算距离的函数。传递给此函数的参数是位置或 Geopt() 的纬度和经度元组:
def HaversineDistance(location1, location2):
"""Method to calculate Distance between two sets of Lat/Lon."""
lat1, lon1 = location1
lat2, lon2 = location2
earth = 6371 #Earth's Radius in Kms.
#Calculate Distance based in Haversine Formula
dlat = math.radians(lat2-lat1)
dlon = math.radians(lon2-lon1)
a = math.sin(dlat/2) * math.sin(dlat/2) + math.cos(math.radians(lat1)) * math.cos(math.radians(lat2)) * math.sin(dlon/2) * math.sin(dlon/2)
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a))
d = earth * c
return d
计算半径内周边城市的函数。这是存储所有城市的City模型下的方法:
def get_closest_cities(self, kms):
cities = []
#Find surrounding Cities of a given city within a given radius
allcities = self.country.city_set
for city in allcities:
distance = HaversineDistance((self.location.lat, self.location.lon),(city.location.lat, city.location.lon))
if not distance >= kms:
cities.append((city.name, int(distance)))
cities.remove(cities[0])
return cities
关于python - 在 Google App Engine 上用 Python 计算城市之间的距离并基于 GeoPT 查找周边城市,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10693699/
我正在使用 GAE/J 1.7GWT 2.4JPA请求工厂 我想创建一个字段,用户可以在其中提交地址并将该值保存为数据存储中的 GeoPt。 有什么建议吗? 最佳答案 您可以获取用户指定的地址,使用
如何将地理点重复作为结构化属性? 我的代码如下所示: class MyModel(EndpointsModel): segments = ndb.StructuredProperty(ndb.
我正在用 Java 编写一个 GAE 应用程序并且只使用 Python 处理数据上传。我正在尝试导入如下所示的 CSV 文件: POSTAL_CODE_ID,PostalCode,City,Provi
我在使用 Objectify 查询 GeoPt 字段时遇到了最困难的时间。 我确保有一个关于 GeoPt 字段的 @Index 注释。 然而,下面的语句似乎不起作用 ofy().load()
我正在扩展 GeoModel 以在数据存储中存储位置,这样我就可以更有效地进行基于地理的搜索,并且我假设我可以使用 GeoPt 属性来存储纬度和经度。并且存储工作正常。但是我完全不知道如何从实体中提取
我试图将值从 html 表单传递到 gae 数据存储区并收到以下错误: “BadValueError:预期的 GeoPt,得到 (51.123,-0.123)” 预先致歉,但我是新手,所以可能做错了,
我正在努力将最初用 Python 编写的现有 GAE 应用程序移植到 Go。到目前为止,它非常棒而且相当简单(尽管它并非没有怪癖)。 由于此端口将部署到不同版本的同一个 GAE 应用程序,因此这两个版
我定义了一个城市模型,它保存城市的 geoname_id 和 location(作为 GeoPt)。我想实现两件事。 我想获取距离给定城市 500km 半径范围内的所有城市。 我想计算两个给定城市之间
我正在从一个包含 GeoPt 列的 csv 文件上传数据。我在这样的引号中有 GeoPt 列数据:SomeData,"54.321,-123.456",MoreData 我的 bulkloader.y
这将是一个由两部分组成的问题, 在这里,我将 GeoPt 发送到我的 ndb 服务。 JSON 如下所示。 { "DriverId": 1, "Startpoint": {
我应该如何创建一个 GQL 查询以根据其 GeoPt 属性返回最近的实体(从我的当前位置)?我是否应该创建一个“距离”函数来计算一组距离相当近的实体? 提前致谢! 最佳答案 App Engine 不会
我是一名优秀的程序员,十分优秀!