Last active
May 13, 2016 08:56
-
-
Save petersen-poul/590c42cf3eb57bf10177784a4c474c4c 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 from a reference point", | |
"description": "Extends a dataset with the distance in meters between lat/long fields and a reference point.", | |
"inputs": [ | |
{ | |
"name": "dataset-in", | |
"type": "dataset-id", | |
"description": "Dataset for extending with distance calculation." | |
}, | |
{ | |
"name": "lat-field", | |
"type": "string", | |
"description": "The name/id of the latitude field." | |
}, | |
{ | |
"name": "long-field", | |
"type": "string", | |
"description": "The name/id of the longitude field." | |
}, | |
{ | |
"name": "lat-ref", | |
"type": "number", | |
"description": "The latitude of the reference point in signed degrees." | |
}, | |
{ | |
"name": "long-ref", | |
"type": "number", | |
"description": "The longitude of the reference point in signed degrees." | |
} | |
], | |
"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 lat/long coordinates and a reference point | |
; All lat/long coordinates must be in signed degrees (no N/W/S/E etc) | |
(define (latlong-ref-dist dataset-in lat-field long-field lat-ref long-ref) | |
(create-and-wait-dataset { | |
"origin_dataset" dataset-in | |
"new_fields" [ | |
{ | |
"field" ( flatline "( let (" | |
"R 6371000 " | |
"latA (to-radians {lat-ref}) " | |
"latB (to-radians ( field {{lat-field}} ) ) " | |
"latD ( - latB latA ) " | |
"longD ( to-radians ( - ( field {{long-field}} ) {long-ref} ) ) " | |
"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-ref-dist dataset-in lat-field long-field lat-ref long-ref)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment