Reformat all files with prettier

This commit is contained in:
Pieter Vander Vennet 2022-09-08 21:40:48 +02:00
parent e22d189376
commit b541d3eab4
382 changed files with 50893 additions and 35566 deletions

View file

@ -1,49 +1,70 @@
import * as fs from "fs";
import {existsSync, writeFileSync} from "fs";
import * as readline from "readline";
import ScriptUtils from "../ScriptUtils";
import * as fs from "fs"
import { existsSync, writeFileSync } from "fs"
import * as readline from "readline"
import ScriptUtils from "../ScriptUtils"
/**
* Converts an open-address CSV file into a big geojson file
*/
async function main(args: string[]) {
const inputFile = args[0]
const outputFile = args[1]
const fileStream = fs.createReadStream(inputFile);
const fileStream = fs.createReadStream(inputFile)
const perPostalCode = args[2] == "--per-postal-code"
const rl = readline.createInterface({
input: fileStream,
crlfDelay: Infinity
});
crlfDelay: Infinity,
})
// Note: we use the crlfDelay option to recognize all instances of CR LF
// ('\r\n') in input.txt as a single line break.
const fields = [
"EPSG:31370_x", "EPSG:31370_y", "EPSG:4326_lat", "EPSG:4326_lon",
"address_id", "box_number",
"house_number", "municipality_id", "municipality_name_de", "municipality_name_fr", "municipality_name_nl", "postcode", "postname_fr",
"postname_nl", "street_id", "streetname_de", "streetname_fr", "streetname_nl", "region_code", "status"
"EPSG:31370_x",
"EPSG:31370_y",
"EPSG:4326_lat",
"EPSG:4326_lon",
"address_id",
"box_number",
"house_number",
"municipality_id",
"municipality_name_de",
"municipality_name_fr",
"municipality_name_nl",
"postcode",
"postname_fr",
"postname_nl",
"street_id",
"streetname_de",
"streetname_fr",
"streetname_nl",
"region_code",
"status",
]
let i = 0;
let i = 0
let failed = 0
let createdFiles: string [] = []
let createdFiles: string[] = []
if (!perPostalCode) {
fs.writeFileSync(outputFile, "")
}
// @ts-ignore
for await (const line of rl) {
i++;
i++
if (i % 10000 == 0) {
ScriptUtils.erasableLog("Converted ", i, "features (of which ", failed, "features don't have a coordinate)")
ScriptUtils.erasableLog(
"Converted ",
i,
"features (of which ",
failed,
"features don't have a coordinate)"
)
}
const data = line.split(",")
const parsed: any = {}
for (let i = 0; i < fields.length; i++) {
const field = fields[i];
const field = fields[i]
parsed[field] = data[i]
}
const lat = Number(parsed["EPSG:4326_lat"])
@ -67,7 +88,7 @@ async function main(args: string[]) {
continue
}
if (isNaN(Number(parsed["postcode"]))) {
continue;
continue
}
targetFile = outputFile + "-" + parsed["postcode"] + ".geojson"
let isFirst = false
@ -81,29 +102,30 @@ async function main(args: string[]) {
fs.appendFileSync(targetFile, ",\n")
}
fs.appendFileSync(targetFile, JSON.stringify({
type: "Feature",
properties: parsed,
geometry: {
type: "Point",
coordinates: [lon, lat]
}
}))
fs.appendFileSync(
targetFile,
JSON.stringify({
type: "Feature",
properties: parsed,
geometry: {
type: "Point",
coordinates: [lon, lat],
},
})
)
} else {
fs.appendFileSync(outputFile, JSON.stringify({
type: "Feature",
properties: parsed,
geometry: {
type: "Point",
coordinates: [lon, lat]
}
}) + "\n")
fs.appendFileSync(
outputFile,
JSON.stringify({
type: "Feature",
properties: parsed,
geometry: {
type: "Point",
coordinates: [lon, lat],
},
}) + "\n"
)
}
}
console.log("Closing files...")
@ -113,8 +135,13 @@ async function main(args: string[]) {
fs.appendFileSync(createdFile, "]}")
}
console.log("Done! Converted ", i, "features (of which ", failed, "features don't have a coordinate)")
console.log(
"Done! Converted ",
i,
"features (of which ",
failed,
"features don't have a coordinate)"
)
}
let args = [...process.argv]
@ -123,5 +150,5 @@ args.splice(0, 2)
if (args.length == 0) {
console.log("USAGE: input-csv-file output.newline-delimited-geojson.json [--per-postal-code]")
} else {
main(args).catch(e => console.error(e))
main(args).catch((e) => console.error(e))
}