PostgreSQL+PostGIS 函数,为一对(纬度、经度)点提供角度分离

发布于 2024-09-25 08:50:01 字数 548 浏览 0 评论 0原文

我编写了以下代码(在花了几个小时尝试正确引用之后):

CREATE FUNCTION ast3angsep(double precision, double precision, double precision, double precision) RETURNS double precision AS $$
SELECT ST_Distance( ST_GeographyFromText('SRID=4326;POINT('||$1||' '||$2||')'), ST_GeographyFromText('SRID=4326;POINT('||$3||' '||$4||')') )/6370986.0/PI()*180.0;
$$
LANGUAGE SQL
IMMUTABLE
RETURNS NULL ON NULL INPUT;

这个函数可以工作,但不幸的是,它的精度非常糟糕。似乎应该有一种更简单的方法来做到这一点。我只想将值传递给函数并让它将它们传递给 ST 函数。我完全无法找到一种方法来做到这一点,而不先将它们转换为字符串,这可能是精度损失的原因。

我这样做完全搞砸了吗?

I wrote the following code (after spending a few hours trying to get the quoting correct):

CREATE FUNCTION ast3angsep(double precision, double precision, double precision, double precision) RETURNS double precision AS $
SELECT ST_Distance( ST_GeographyFromText('SRID=4326;POINT('||$1||' '||$2||')'), ST_GeographyFromText('SRID=4326;POINT('||$3||' '||$4||')') )/6370986.0/PI()*180.0;
$
LANGUAGE SQL
IMMUTABLE
RETURNS NULL ON NULL INPUT;

This function works but, unfortunately, it's precision is HORRIBLE. It seems like there should be a much simpler way to do this. I just want to pass the values to the function and have it pass them to the ST functions. I was completely unable to find a way of doing this without converting them to string first, which is probably where the loss of precision enters.

Am I doing this totally screwed up?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡忘如思 2024-10-02 08:50:01

不要使用 ST_GeographyFromText 转换为字符串并创建点,而是尝试使用 ST_MakePoint< /a> 直接使用函数接收到的值。

Instead of converting to strings and creating a point using ST_GeographyFromText, try using ST_MakePoint directly with the values received by the funciton.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文