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 模块


基础教程推荐
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01