Postgresql接地距离-带半径的接地盒
请你给我解释一下地球盒函数的这种行为。。。或者我做错了什么 使用的数据Postgresql接地距离-带半径的接地盒,postgresql,earthdistance,Postgresql,Earthdistance,请你给我解释一下地球盒函数的这种行为。。。或者我做错了什么 使用的数据 40.749276, -73.985643 = Empire State Building - is in my table 40.689266, -74.044512 = Statue of Liberty - is my current position in select - 8324m far from Empire State Building 我的桌子 => select id, latitude, lo
40.749276, -73.985643 = Empire State Building - is in my table
40.689266, -74.044512 = Statue of Liberty - is my current position in select - 8324m far from Empire State Building
我的桌子
=> select id, latitude, longitude, title from requests;
id | latitude | longitude | title
----+-----------+------------+-----------------------
1 | 40.749276 | -73.985643 | Empire State Building
从帝国大厦到自由女神像的距离
=> SELECT id, latitude, longitude, title, earth_distance(ll_to_earth(40.689266, -74.044512), ll_to_earth(latitude, longitude)) as distance_from_current_location FROM requests ORDER BY distance_from_current_location ASC;
id | latitude | longitude | title | distance_from_current_location
----+-----------+------------+-----------------------+--------------------------------
1 | 40.749276 | -73.985643 | Empire State Building | 8324.42998846164
我现在的位置是自由女神像,离帝国大厦有8000多米远,但是
选择id为1的返回行,即使半径仅为5558m!你能给我解释一下这种行为或是怎么回事吗
=> SELECT id,latitude,longitude,title FROM requests WHERE earth_box(ll_to_earth(40.689266, -74.044512), 5558) @> ll_to_earth(requests.latitude, requests.longitude);
id | latitude | longitude | title
----+-----------+------------+-----------------------
1 | 40.749276 | -73.985643 | Empire State Building
扩展和postgresql的版本
=> \dx
List of installed extensions
Name | Version | Schema | Description
---------------+---------+------------+-------------------------------------------------------------- cube | 1.0 | public | data type for multidimensional
cubes earthdistance | 1.0 | public | calculate great-circle
distances on the surface of the Earth plpgsql | 1.0 |
pg_catalog | PL/pgSQL procedural language
=> select version();
version
-------------------------------------------------------------------------------------------------------------------------------------- PostgreSQL 9.4beta2 on x86_64-apple-darwin13.3.0, compiled by Apple
LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn), 64-bit
多谢各位
不这里的问题是地球的轨道是法定英里。 8324.42998846164米接近5.172560986623845法定英里 解决方案:将半径转换为法定英里单位
earth_框(ll_to_earth(40.689266,-74.044512),5558/1.609)//不返回结果
earth\u box(ll\u to\u earth(40.689266,-74.044512),9000/1.609)//does.
根据,默认情况下,半径以米表示
我刚刚测试了一下,从文档中可以看出,在WHERE子句语句中需要接地盒和接地距离
因此,您需要同时使用接地盒和接地距离来获得正确的结果
此外,在接地盒功能描述中,它还表示:
此框中的某些点超出指定的大圆
距离该位置,因此使用接地距离进行第二次检查
应包含在查询中
下面将返回结果
SELECT earth_distance(ll_to_earth(40.749276, -73.985643), ll_to_earth(40.689266,-74.044512)) distance
FROM (SELECT 1) test
WHERE
(earth_box(ll_to_earth(40.749276, -73.985643), 9000) @> ll_to_earth(40.689266,-74.044512))
AND earth_distance(ll_to_earth(40.749276, -73.985643), ll_to_earth(40.689266,-74.044512)) <= 9000
order by distance desc
选择接地距离(ll_至_接地(40.749276,-73.985643)、ll_至_接地(40.689266,-74.044512))距离
从(选择1)测试
哪里
(接地盒(ll_对地(40.749276,-73.985643),9000)@>ll_对地(40.689266,-74.044512))
和地球距离(地球到地球(40.749276,-73.985643),地球到地球(40.689266,-74.044512))这些信息很难找到。每个人似乎都认为这需要米。转换成法定英里单位会得到更好的结果,但仍然不是很好。8400/1.609应该已经归还帝国大厦了,但它没有。我知道地球距离不应该很精确,但也不应该太远。也许还有更多?所以我不得不问,这就是earth\u box
的意义,如果你必须检查earth\u distance
?为什么还要把接地盒
放在等式中?
SELECT earth_distance(ll_to_earth(40.749276, -73.985643), ll_to_earth(40.689266,-74.044512)) distance
FROM (SELECT 1) test
WHERE
(earth_box(ll_to_earth(40.749276, -73.985643), 6000) @> ll_to_earth(40.689266,-74.044512))
AND earth_distance(ll_to_earth(40.749276, -73.985643), ll_to_earth(40.689266,-74.044512)) <= 6000
order by distance desc