diff --git a/scripts/importscripts/zhv.ts b/scripts/importscripts/zhv.ts index e608196bc..b2f03cca0 100644 --- a/scripts/importscripts/zhv.ts +++ b/scripts/importscripts/zhv.ts @@ -21,10 +21,16 @@ class ZHVcsv2GeoJson extends Script { const text = readFileSync(csvFile, "utf-8") const parsed = parse(text, { header: true, - dynamicTyping: true, + dynamicTyping: false, }) console.log(`Parsed ${parsed.data.length} rows from ${csvFile}`) + console.log(`First row:`, parsed.data[0]) + + // Drop all rows that do not have a valid latitude and longitude + parsed.data = parsed.data.filter((row: any) => { + return row["Latitude"] && row["Longitude"] + }) // Convert the parsed data to GeoJSON format const geoJson: FeatureCollection = { @@ -33,12 +39,17 @@ class ZHVcsv2GeoJson extends Script { type: "Feature", geometry: { type: "Point", - coordinates: [row.longitude, row.latitude], + coordinates: [ + parseFloat(row["Longitude"].replace(",", ".")), + parseFloat(row["Latitude"].replace(",", ".")), + ], }, properties: row, })), } + console.log(`First feature:`, geoJson.features[0]) + // Write the GeoJSON output to the specified file writeFileSync(outputFile, JSON.stringify(geoJson), "utf-8") }