Skip to content

Instantly share code, notes, and snippets.

@rgdonohue
Last active August 29, 2015 14:27
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 rgdonohue/2d32f71bab03e9970467 to your computer and use it in GitHub Desktop.
Save rgdonohue/2d32f71bab03e9970467 to your computer and use it in GitHub Desktop.
Create Mile Marker Features Along Race
var turf = require('turf');
var fs = require('fs');
var gp = require("geojson-precision");
fs.readFile('race_route.geojson', 'utf8', function(err,data){
if(err) throw err;
processData(JSON.parse(data))
});
function processData(data){
var line = data.features[0];
var result = {
"type": "FeatureCollection",
"features": [line]
};
var i = 0;
while(i <= 26){
var along = turf.along(line,i,'miles');
if(i == 0) {
along.properties = { 'distance': 'start' };
} else if(i == 26) {
along.properties = { 'distance': 'finish' };
} else {
along.properties = { 'distance':'mile ' + i };
}
result.features.push(along);
i++;
}
// trim ridiculous precison thnx to https://github.com/jczaplew/geojson-precision
gp.parse(result,4);
writeToFile(result);
}
function writeToFile(output){
fs.writeFile('route_with_markers.json', JSON.stringify(output), function(err){
if(err){
return console.log(err);
}
console.log('success!')
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment