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


- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01