forked from MapComplete/MapComplete
Fix: proper coordinate parsing in script
This commit is contained in:
parent
edf6e00a5e
commit
cf995e1820
1 changed files with 13 additions and 2 deletions
|
@ -21,10 +21,16 @@ class ZHVcsv2GeoJson extends Script {
|
||||||
const text = readFileSync(csvFile, "utf-8")
|
const text = readFileSync(csvFile, "utf-8")
|
||||||
const parsed = parse(text, {
|
const parsed = parse(text, {
|
||||||
header: true,
|
header: true,
|
||||||
dynamicTyping: true,
|
dynamicTyping: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(`Parsed ${parsed.data.length} rows from ${csvFile}`)
|
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
|
// Convert the parsed data to GeoJSON format
|
||||||
const geoJson: FeatureCollection<Point> = {
|
const geoJson: FeatureCollection<Point> = {
|
||||||
|
@ -33,12 +39,17 @@ class ZHVcsv2GeoJson extends Script {
|
||||||
type: "Feature",
|
type: "Feature",
|
||||||
geometry: {
|
geometry: {
|
||||||
type: "Point",
|
type: "Point",
|
||||||
coordinates: [row.longitude, row.latitude],
|
coordinates: [
|
||||||
|
parseFloat(row["Longitude"].replace(",", ".")),
|
||||||
|
parseFloat(row["Latitude"].replace(",", ".")),
|
||||||
|
],
|
||||||
},
|
},
|
||||||
properties: row,
|
properties: row,
|
||||||
})),
|
})),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(`First feature:`, geoJson.features[0])
|
||||||
|
|
||||||
// Write the GeoJSON output to the specified file
|
// Write the GeoJSON output to the specified file
|
||||||
writeFileSync(outputFile, JSON.stringify(geoJson), "utf-8")
|
writeFileSync(outputFile, JSON.stringify(geoJson), "utf-8")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue