gpt4 book ai didi

Postgresql earthdistance - 带半径的earth_box

转载 作者:行者123 更新时间:2023-11-29 11:27:20 25 4
gpt4 key购买 nike

拜托,你能解释一下 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

我的 table

=> 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多米的自由女神像,但是即使半径只有 5558m,也选择 ID 为 1 的返回行!你能解释一下这种行为或哪里出了问题吗?

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

谢谢没有

最佳答案

这里的问题是 earth_box 获得 Statute Miles。8324.42998846164 米接近 5.172560986623845 法定英里 Unit Converter

解决方案:将半径转换为法定英里单位

earth_box(ll_to_earth(40.689266, -74.044512), 5558/1.609)//不返回结果

earth_box(ll_to_earth(40.689266, -74.044512), 9000/1.609)//是。

关于Postgresql earthdistance - 带半径的earth_box,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25577461/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com