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

16
doc/CDB_GreatCircle.md Normal file
View File

@ -0,0 +1,16 @@
Based on Paul Ramsey's [blog post](http://blog.cartodb.com/jets-and-datelines/).
#### Using the function
Creates a great circle line.
```sql
SELECT CDB_GreatCircle(start_point, end_point) FROM table_name
-- Results a line reprsenting the great circle between the two points
```
#### Arguments
CDB_GreatCircle(start_point, end_point)
* **start_point** ST_Point indicating the start of the line.
* **end_point** ST_point indicating the end of the line.

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'

View File

@ -0,0 +1 @@
scripts-available/CDB_GreatCircle.sql

View File

@ -0,0 +1 @@
LINESTRING(4.259 55.858,5.6692453115051 56.0150275120673,7.10720375678704 56.157400475677,8.5718366560563 56.2842986378254,10.0619272412891 56.3949153508462,11.5760785994189 56.4884642014437,13.1127142001617 56.564185934303,14.6700812655504 56.6213555706215,16.2462571744128 56.6592896061102,17.8391590143095 56.6773531596105,19.4465562981665 56.6749669334121,21.0660867567155 56.6516138405427,22.6952750058883 56.6068451534252,24.3315537765309 56.540286032869,25.9722872888145 56.4516403065472,27.6147962622065 56.3406943817481,29.2563839799455 56.207320197769,30.8943627796619 56.0514771479657,32.5260803224591 55.8732129290618,34.1489450028345 55.6726633044968,35.7604499005266 55.4500507979281,37.3581947399686 55.2056823610616,38.9399054089486 54.9399460854786,40.5034506895044 54.6533070499613,42.0468559644411 54.3463024122038,43.5683137754523 54.0195358662507,45.066191217402 53.673671594382,46.5390342525062 53.3094278446298,47.9855691138079 52.9275702630659,49.4047010366934 52.5289051040742,50.7955106088955 52.1142724327331,52.1572480633875 51.6845394219955,53.4893258557794 51.2405938343407,54.7913098701049 50.7833377637432,56.0629095865715 50.3136816997865,57.3039675245588 49.8325389621027,58.5144482465496 49.3408205404538,59.6944271762829 48.8394303639846,60.8440794494795 48.329261012675,61.9636689799149 47.811189874886,63.0535378889196 47.2860757471582,64.1140964137264 46.7547558660385,65.1458133802427 46.2180433565989,66.1492072992903 45.676725078361,67.1248381223566 45.131559846414,68.0732996734468 44.583277003498,68.9952127576034 44.0325753175597,69.8912189338183 43.4801221786776,70.7619749300985 42.9265530691612,71.6081476710291 42.3724712809595,72.4304098829428 41.8184478551838,73.2294362384225 41.2650217194684,74.0059 40.7127)

1
test/CDB_GreatCircle.sql Normal file
View File

@ -0,0 +1 @@
select CDB_GreatCircle(CDB_LATLng(55.8580,4.2590), CDB_LatLng(40.7127,74.0059))