2015-11-24 00:07:24 +08:00
|
|
|
-- Great circle point-to-point routes, based on:
|
|
|
|
-- http://blog.cartodb.com/jets-and-datelines/
|
|
|
|
--
|
2015-11-24 00:13:17 +08:00
|
|
|
CREATE OR REPLACE FUNCTION CDB_GreatCircle(start_point geometry, end_point geometry, max_segment_length NUMERIC DEFAULT 100000)
|
2015-11-23 23:51:34 +08:00
|
|
|
RETURNS geometry AS $$
|
2015-10-14 23:36:48 +08:00
|
|
|
DECLARE
|
2015-11-23 23:51:34 +08:00
|
|
|
line geometry;
|
2015-10-14 23:36:48 +08:00
|
|
|
BEGIN
|
2015-11-23 23:51:34 +08:00
|
|
|
line = ST_Segmentize(
|
|
|
|
ST_Makeline(
|
|
|
|
start_point,
|
|
|
|
end_point
|
|
|
|
)::geography,
|
2015-11-24 00:13:17 +08:00
|
|
|
max_segment_length
|
2015-11-23 23:51:34 +08:00
|
|
|
)::geometry;
|
2015-10-14 23:36:48 +08:00
|
|
|
|
2015-11-23 23:51:34 +08:00
|
|
|
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;
|
|
|
|
$$
|
2017-10-24 20:16:56 +08:00
|
|
|
LANGUAGE 'plpgsql' IMMUTABLE STRICT PARALLEL SAFE;
|