Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 匹配特定XY半径内的所有位置(坐标lat、lng)_Python_Python 3.x_Flask - Fatal编程技术网

Python 匹配特定XY半径内的所有位置(坐标lat、lng)

Python 匹配特定XY半径内的所有位置(坐标lat、lng),python,python-3.x,flask,Python,Python 3.x,Flask,我有一个带有经纬度的地方数据库。是否有任何库或API允许您匹配围绕特定点的所有位置 例如,假设我想在数据库中找到坐标在原点坐标52.5200°N,13.4050°E的15000m半径范围内的所有结果 有什么现成的解决办法吗 谢谢 根据您打算如何搜索数据库,答案可能会有所不同。如果您打算使用SQL,可以按如下所述操作: 选择Id、邮政编码、Lat、Lon、, acos(sin(:lat)*sin(radians(lat))+cos(:lat)*cos(radians(lat))*cos(radia

我有一个带有经纬度的地方数据库。是否有任何库或API允许您匹配围绕特定点的所有位置

例如,假设我想在数据库中找到坐标在原点坐标52.5200°N,13.4050°E的15000m半径范围内的所有结果

有什么现成的解决办法吗


谢谢

根据您打算如何搜索数据库,答案可能会有所不同。如果您打算使用SQL,可以按如下所述操作:

选择Id、邮政编码、Lat、Lon、,
acos(sin(:lat)*sin(radians(lat))+cos(:lat)*cos(radians(lat))*cos(radians(Lon)-(Lon))*:R作为D
从MyTable
式中,acos(sin(:lat)*sin(radians(lat))+cos(:lat)*cos(radians(lat))*cos(radians(Lon)-(Lon))*:R<:rad

要从数据库中选择距离给定纬度/经度点一定距离内的点,您可以使用该查询,其中
rad
是您的半径,在您的示例中为15000m。

根据您打算搜索数据库的方式,答案可能会有所不同。如果您打算使用SQL,可以按如下所述操作:

选择Id、邮政编码、Lat、Lon、,
acos(sin(:lat)*sin(radians(lat))+cos(:lat)*cos(radians(lat))*cos(radians(Lon)-(Lon))*:R作为D
从MyTable
式中,acos(sin(:lat)*sin(radians(lat))+cos(:lat)*cos(radians(lat))*cos(radians(Lon)-(Lon))*:R<:rad

要从数据库中选择距离给定纬度/经度点一定距离内的点,在选择圆内,您可以使用该查询,其中
rad
是您的半径,在您的示例中为15000m。

POSTGIS是专门为此而设计的。如果你的应用程序将大量使用空间功能/实用程序,你应该考虑切换到它。如果没有,您可以查看
shapely
,Links:POSTGIS是专门为此制作的。如果你的应用程序将大量使用空间功能/实用程序,你应该考虑切换到它。如果没有,您可以查看
shapely
,链接:
Select Id, Postcode, Lat, Lon,
       acos(sin(:lat)*sin(radians(Lat)) + cos(:lat)*cos(radians(Lat))*cos(radians(Lon)-:lon)) * :R As D
From MyTable
Where acos(sin(:lat)*sin(radians(Lat)) + cos(:lat)*cos(radians(Lat))*cos(radians(Lon)-:lon)) * :R < :rad