开发者

PostgreSQL+PostGIS function that gives angular seperation for a pair of (lat,long) points

开发者 https://www.devze.com 2023-01-17 15:34 出处:网络
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 d

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;
开发者_StackOverflow中文版

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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消