Created
December 15, 2020 14:13
-
-
Save ubergesundheit/7c41af66b9a22e34d3063d14d1560637 to your computer and use it in GitHub Desktop.
Find station furthest from Münster on openSenseMap
This file contains hidden or 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
// boxes.js is acquired by executing `curl "https://api.opensensemap.org/boxes?classify=true&minimal=true" > boxes.js` | |
// then prepend `export default ` in front of boxes.js | |
import { default as boxes } from "./boxes.js"; | |
import { default as distance } from "@turf/distance"; | |
import { default as helpers } from "@turf/helpers"; | |
const muenster = helpers.point([7.62, 51.96]); | |
for (let i = 0; i < boxes.length ; i++) { | |
const p = helpers.point(boxes[i].currentLocation.coordinates) | |
const d = distance.default(muenster, p) | |
boxes[i].distanceToMs = d; | |
} | |
boxes.sort((b1, b2) => { | |
return b2.distanceToMs - b1.distanceToMs; | |
}); | |
console.log(boxes[1]); |
This file contains hidden or 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
{ | |
"type": "module", | |
"dependencies": { | |
"@turf/distance": "^6.0.1", | |
"@turf/helpers": "^6.1.4" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment