Skip to content

Instantly share code, notes, and snippets.

@ubergesundheit
Created December 15, 2020 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ubergesundheit/7c41af66b9a22e34d3063d14d1560637 to your computer and use it in GitHub Desktop.
Save ubergesundheit/7c41af66b9a22e34d3063d14d1560637 to your computer and use it in GitHub Desktop.
Find station furthest from Münster on openSenseMap
// 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]);
{
"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