Python module for storing and querying geographical coordinates(用于存储和查询地理坐标的 Python 模块)
问题描述
是否有一个 Python 模块,我可以在其中创建具有地理位置坐标(纬度和经度)的对象,并在给定坐标的 5 公里距离(即半径)内查询所有对象?
Is there a Python module where I can create objects with a geographical location coordinate (latitude and longitude), and query all the objects for ones which are within a 5km distance (i.e. radius) of a given coordinate?
我一直在尝试将纬度和经度作为键存储在字典中(因为它们是通过键索引的)并使用一些测距算法来查询它们.但这感觉就像一个可怕的黑客攻击.
I've been trying to store the latitude and longitude as keys in dictionaries (as they're indexed by key) and use some distance finding algorithms to query them. But this feels like a horrible hack.
基本上类似于 PostGIS for PostgreSQL,但都在我的 Python 应用程序的内存中.
Essentially something like PostGIS for PostgreSQL, but all within my Python app's memory.
推荐答案
是的,试试 geopy.
import geopy
import geopy.distance
pt1 = geopy.Point(48.853, 2.349)
pt2 = geopy.Point(52.516, 13.378)
dist = geopy.distance.distance(pt1, pt2).km
# 878.25
之后您可以查询您的积分列表:
afterwards you can query your lists of points:
[pt for pt in points if geopy.distance.distance(orig, pt).km < 5.]
这篇关于用于存储和查询地理坐标的 Python 模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:用于存储和查询地理坐标的 Python 模块
基础教程推荐
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 包装空间模型 2022-01-01
