Last active
July 19, 2018 23:08
-
-
Save chanmix51/1999886 to your computer and use it in GitHub Desktop.
Latitude, longitude and orthodromic distance in PgSQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE DOMAIN latlong AS point CHECK (VALUE[0] BETWEEN -90.0 AND 90.0 AND VALUE[1] BETWEEN -180 AND 180); | |
CREATE OR REPLACE FUNCTION orthodromic_distance(latlong, latlong) RETURNS float AS $_$ | |
SELECT acos( | |
sin(radians($1[0])) | |
* | |
sin(radians($2[0])) | |
+ | |
cos(radians($1[0])) | |
* | |
cos(radians($2[0])) | |
* | |
cos(radians($2[1]) | |
- | |
radians($1[1])) | |
) * 6370.0; | |
$_$ LANGUAGE sql IMMUTABLE; | |
CREATE OPERATOR <-> ( PROCEDURE = orthodromic_distance | |
, LEFTARG = latlong, RIGHTARG = latlong | |
); |
Va falloir benchmarker !
Så skriv dog på engelsk!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Aevc PostGIS, il doit falloir un truc comme ça :
select st_distance_spheroid(
st_setsrid(st_makepoint(22,34),4326),
st_setsrid(st_makepoint(33,44),4326),
'SPHEROID["WGS 84",6378137,298.257223563]'
);
Je sais pas à quel point c'est plus précis que la proposition initiale