Adding function to produce a great circle between two points.

This commit is contained in:
Stuart Lynn
2015-10-14 11:36:48 -04:00
parent 913bfd72f8
commit eb475fe55f
5 changed files with 49 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
-- Return a line for the Great Circle between two points
--
-- start_point geometry : The origin of the line
-- end_point geometry : The distination of the line
-- retruns geometry
create or replace function CDB_GreatCircle(start_point geometry ,end_point geometry ) RETURNS geometry as
$$
DECLARE
line geometry;
BEGIN
line = ST_Segmentize(
ST_Makeline(
start_point,
end_point
)::geography,
100000
)::geometry;
if ST_XMax(line) - ST_XMin(line) > 180 then
line = ST_Difference(
ST_Shift_Longitude(line), ST_Buffer(ST_GeomFromText('LINESTRING(180 90, 180 -90)',4326), 0.00001));
end if;
return line;
END $$
LANGUAGE 'plpgsql'