微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Postgresql earthdistance – 具有半径的earth_box

拜托,你能解释一下earth_Box函数的这种行为……或者我做错了什么?

使用的数据

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,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

我现在的位置是距离帝国大厦800米以上的Libery雕像,但是
选择返回行,ID为1,即使半径仅为5558m!你能解释一下这种行为或出了什么问题吗?

=> SELECT id,title FROM requests WHERE earth_Box(ll_to_earth(40.689266,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

谢谢
诺埃

解决方法

这里的问题是earth_Box获得了Statute Miles.
8324.42998846164米附近有5.172560986623845法定里程
Unit Converter

解决方案:将半径转换为Statute Miles单位

earth_Box(ll_to_earth(40.689266,5558 / 1.609)//不返回结果

earth_Box(ll_to_earth(40.689266,9000 / 1.609)//确实.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐