Fix: proper coordinate parsing in script

This commit is contained in:
Robin van der Linde 2025-07-25 00:22:59 +02:00
parent edf6e00a5e
commit cf995e1820

View file

@ -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<Point> = {
@ -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")
}