2015-11-24 00:07:24 +08:00
|
|
|
-- Great circle point-to-point routes, based on:
|
|
|
|
-- http://blog.cartodb.com/jets-and-datelines/
|
|
|
|
--
|
2019-05-31 21:29:28 +08:00
|
|
|
CREATE OR REPLACE FUNCTION @extschema@.CDB_GreatCircle(start_point @postgisschema@.geometry, end_point @postgisschema@.geometry, max_segment_length NUMERIC DEFAULT 100000)
|
|
|
|
RETURNS @postgisschema@.geometry AS $$
|
2015-10-14 23:36:48 +08:00
|
|
|
DECLARE
|
2019-05-31 21:29:28 +08:00
|
|
|
line @postgisschema@.geometry;
|
2015-10-14 23:36:48 +08:00
|
|
|
BEGIN
|
2019-05-31 21:29:28 +08:00
|
|
|
line = @postgisschema@.ST_Segmentize(
|
|
|
|
@postgisschema@.ST_Makeline(
|
2015-11-23 23:51:34 +08:00
|
|
|
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
|
|
|
|
2019-05-31 21:29:28 +08:00
|
|
|
IF @postgisschema@.ST_XMax(line) - @postgisschema@.ST_XMin(line) > 180 THEN
|
|
|
|
line = @postgisschema@.ST_Difference(
|
|
|
|
@postgisschema@.ST_ShiftLongitude(line),
|
|
|
|
@postgisschema@.ST_Buffer(@postgisschema@.ST_GeomFromText('LINESTRING(180 90, 180 -90)', 4326), 0.00001)
|
2015-11-23 23:51:34 +08:00
|
|
|
);
|
|
|
|
END IF;
|
|
|
|
RETURN line;
|
|
|
|
END;
|
|
|
|
$$
|
2017-10-24 20:16:56 +08:00
|
|
|
LANGUAGE 'plpgsql' IMMUTABLE STRICT PARALLEL SAFE;
|