Created
June 15, 2024 23:28
-
-
Save dzfranklin/aa964e173bb219037d8367ef7744af97 to your computer and use it in GitHub Desktop.
turf-sandbox snippet
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
// Paste into <https://turf-sandbox.netlify.app/> | |
function sampleLine(inputLine, distanceMeters) { | |
let inputLength = turf.length(inputLine, "m") | |
let samples = [] | |
for (let i = 0; i < Math.floor(inputLength); i+=distanceMeters) { | |
let point = turf.along(inputLine, i, 'm') | |
samples.push(point["geometry"]["coordinates"]) | |
} | |
samples.push(inputLine["geometry"]["coordinates"].at(-1)) | |
return turf.lineString(samples) | |
} | |
const l = turf.lineString( | |
[[-83, 30], [-84, 36]], | |
{'stroke-width': 3, stroke: '#00F'} | |
); | |
const samples = sampleLine(l, 10); | |
for (const sample of samples["geometry"]["coordinates"]) { | |
console.log(turf.pointToLineDistance(sample, l, {units: "meters"})) | |
} | |
const samplePoints = samples["geometry"]["coordinates"] | |
.map(c => turf.point(c, )) | |
return turf.featureCollection([l, turf.featureCollection(samplePoints)]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment