Last active
September 18, 2019 01:46
-
-
Save petersen-poul/e11ec6ae74912dd219ce554eff998db4 to your computer and use it in GitHub Desktop.
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
{ | |
"name": "Lat/Long Distance between a pair of points", | |
"description": "Extends a dataset with the distance in meters between pairs of lat/long fields.", | |
"inputs": [ | |
{ | |
"name": "dataset-in", | |
"type": "dataset-id", | |
"description": "Dataset for extending with distance calculation." | |
}, | |
{ | |
"name": "latA-field", | |
"type": "string", | |
"description": "The name/id of the latitude A field." | |
}, | |
{ | |
"name": "longA-field", | |
"type": "string", | |
"description": "The name/id of the longitude A field." | |
}, | |
{ | |
"name": "latB-field", | |
"type": "string", | |
"description": "The name/id of the latitude B field." | |
}, | |
{ | |
"name": "longB-field", | |
"type": "string", | |
"description": "The name/id of the longitude B field." | |
} | |
], | |
"outputs": [ | |
{ | |
"name": "dataset-out", | |
"type": "dataset-id", | |
"description": "The ID of the extended dataset" | |
} | |
] | |
} |
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
; Computes the distance between pairs of lat/long coordinates. | |
; All lat/long coordinates must be in signed degrees (no N/W/S/E etc) | |
(define (latlong-pair-dist dataset-in latA-field longA-field latB-field longB-field) | |
(create-and-wait-dataset { | |
"origin_dataset" dataset-in | |
"new_fields" [ | |
{ | |
"field" ( flatline "( let (" | |
"R 6371000 " | |
"latA (to-radians ( field {{latA-field}}) )" | |
"latB (to-radians ( field {{latB-field}}) )" | |
"latD ( - latB latA ) " | |
"longD ( to-radians ( - ( field {{longA-field}} ) ( field {{longB-field}} ) ) )" | |
"a ( + ( square ( sin ( / latD 2 ) ) ) ( * (cos latA) (cos latB) (square ( sin ( / longD 2))) ) ) " | |
"c ( * 2 ( asin ( min (list 1 (sqrt a)) ) ) ) ) " | |
"( * R c ) )" ) | |
"name" "Distance (m)" | |
} | |
] | |
} | |
) | |
) | |
(define dataset-out (latlong-pair-dist dataset-in latA-field longA-field latB-field longB-field)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment