Created
July 30, 2018 17:53
-
-
Save pwinston/58533aaa8cec381808a2f23af73e2f22 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
#!/usr/bin/env node | |
var fs = require('fs'); | |
var turf = require('@turf/turf'); | |
function readFile(path) { | |
console.log("Reading:", path); | |
var data = fs.readFileSync(path); | |
return JSON.parse(data); | |
} | |
function writeFile(data, path) { | |
console.log("Writing:", path); | |
fs.writeFileSync(path, JSON.stringify(data, null, 2)); | |
} | |
function writeOutput(points, hull, path) { | |
if (!hull) { | |
console.log("Cannot write", path, "because hull is undefined"); | |
return; | |
} | |
var resultFeatures = points.features.concat(hull); | |
var result = { | |
"type": "FeatureCollection", | |
"features": resultFeatures | |
}; | |
writeFile(result, path); | |
} | |
var points = readFile('./points_dc.geojson'); | |
var convexHull = turf.convex(points); | |
writeOutput(points, convexHull, './convex.geojson'); | |
var concaveHull = turf.concave(points); | |
writeOutput(points, concaveHull, './concave_default.geojson'); | |
var options = {'maxEdge': 1, 'units': 'miles'}; | |
var concaveHull_1 = turf.concave(points, options); | |
writeOutput(points, concaveHull_1, './concave_1.geojson'); | |
options = {'maxEdge': 0.1, 'units': 'miles'}; | |
var concaveHull_point1 = turf.concave(points); | |
writeOutput(points, concaveHull_point1, './concave_0.1.geojson'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment