mapcomplete/scripts/makeConvex.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

29 lines
789 B
TypeScript
Raw Normal View History

import fs from "fs"
import { GeoOperations } from "../Logic/GeoOperations"
import ScriptUtils from "./ScriptUtils"
/**
* Given one of more files, calculates a somewhat convex hull for them
* @param file
*/
function makeConvex(file) {
ScriptUtils.erasableLog("Handling", file)
2023-01-15 23:28:02 +01:00
const geoJson = JSON.parse(fs.readFileSync(file, { encoding: "utf8" }))
const convex = GeoOperations.convexHull(geoJson, { concavity: 2 })
if (convex.properties === undefined) {
convex.properties = {}
}
fs.writeFileSync(file + ".convex.geojson", JSON.stringify(convex))
}
let args = [...process.argv]
args.splice(0, 2)
args.forEach((file) => {
try {
makeConvex(file)
} catch (e) {
console.error("Could not handle file ", file, " due to ", e)
}
})