-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
42 lines (37 loc) · 1.06 KB
/
Copy pathscript.js
File metadata and controls
42 lines (37 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const fs = require('fs');
const csv = require('csvtojson');
const toKml = require('tokml');
// Read the CSV file
const csvFilePath = './input.csv';
// Convert CSV to JSON
csv()
.fromFile(csvFilePath)
.then((jsonArray) => {
// Create KML content
const kmlPlacemarks = jsonArray.map((item) => {
const { latitude, longitude, placeName, arrivalDate, departureDate } = item;
return `
<Placemark>
<name>${placeName}</name>
<Point>
<coordinates>${longitude},${latitude}</coordinates>
</Point>
<TimeSpan>
<begin>${arrivalDate}</begin>
<end>${departureDate}</end>
</TimeSpan>
</Placemark>
`;
});
const kmlContent = `
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
${kmlPlacemarks.join('\n')}
</Document>
</kml>
`;
// Save KML to a file
fs.writeFileSync('output.kml', kmlContent);
console.log('KML file has been created successfully.');
})
.catch((error) => console.error(error));