Created
July 30, 2018 18:09
-
-
Save pwinston/3f70577d9f0fb6aa9a6578d4e7a93434 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'); | |
// Print the points | |
/* | |
points.features.forEach((pt) => { | |
console.log(pt.geometry.coordinates); | |
}); | |
hull.geometry.coordinates.forEach((polygon, index) => { | |
console.log("Polygon", index); | |
polygon.forEach((point, index) => { | |
console.log("Point", index, point); | |
}); | |
}); | |
*/ |
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'); | |
// Print the points | |
/* | |
points.features.forEach((pt) => { | |
console.log(pt.geometry.coordinates); | |
}); | |
hull.geometry.coordinates.forEach((polygon, index) => { | |
console.log("Polygon", index); | |
polygon.forEach((point, index) => { | |
console.log("Point", index, point); | |
}); | |
}); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment