osm2geojson-lite
Version:
a lightweight yet faster osm (either in xml or in json formats) to geojson convertor - 4x faster than xmldom + osmtogeojson in most situations - implemented in pure JavaScript without any 3rd party dependency
37 lines (36 loc) • 989 B
JavaScript
import { parseArgs } from "node:util";
import { readFile, writeFile } from "node:fs/promises";
import osm2geojson from "./index.js";
//#region src/cli.ts
function printHelp() {
process.stdout.write([
"Convert OpenStreetMap XML or JSON data to GeoJSON.",
"",
"Usage:",
" npx osm2geojson INPUT_FILE OUTPUT_FILE",
" npx osm2geojson < INPUT_FILE > OUTPUT_FILE",
""
].join("\n"));
}
async function main(positionals) {
const [inputFile = "/dev/stdin", outputFile = "/dev/stdout"] = positionals;
const geojson = osm2geojson(await readFile(inputFile, "utf-8"), {
completeFeature: true,
renderTagged: true
});
await writeFile(outputFile, `${JSON.stringify(geojson)}\n`);
}
const { values, positionals } = parseArgs({
args: process.argv.slice(2),
options: { help: {
short: "h",
type: "boolean"
} }
});
if (values.help) printHelp();
else main(positionals).catch((err) => {
process.stderr.write(`${err.stack}\n`);
process.exit(1);
});
//#endregion