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 脚本监听来自另一个脚本的输入 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 筛选NumPy数组 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01