forked from frozenexplorer/Hackenza_Website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
54 lines (46 loc) · 1.75 KB
/
App.js
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
43
44
45
46
47
48
49
50
51
52
53
54
const fs = require("fs");
const csv = require("csv-parser");
// Read the GeoJSON file
const geojsonData = JSON.parse(fs.readFileSync("mapp.geojson", "utf8"));
// Function to filter road features
function filterRoads(feature) {
// Check if the feature represents a road (LineString or MultiLineString)
return (
feature.geometry &&
(feature.geometry.type === "LineString" ||
feature.geometry.type === "MultiLineString") &&
feature.properties &&
feature.properties.highway
);
}
// Read Flood_Intensity from Rainfall.csv and store it in an array
const floodIntensity = [];
fs.createReadStream("Rainfall.csv")
.pipe(csv())
.on("data", (row) => {
// Assuming 'Flood_Intensity' is the column name in Rainfall.csv
floodIntensity.push(row.Flood_Intensity);
})
.on("end", () => {
// Filter road features
const roads = geojsonData.features.filter(filterRoads);
// Create a new GeoJSON object containing only road features
const roadsGeoJSON = {
type: "FeatureCollection",
features: roads,
};
// Assign a random number between 1 to 10 to a new property for each road feature
roadsGeoJSON.features.forEach((feature, index) => {
// Check if the feature has a name property
if (!feature.properties.name) {
// If name property doesn't exist, set it to "unnamed road"
feature.properties.name = "unnamed road";
}
// Assign flood intensity from the array sequentially
feature.properties.flood_intensity =
floodIntensity[index % floodIntensity.length];
});
// Write the filtered GeoJSON data to a file
fs.writeFileSync("AllRoads.geojson", JSON.stringify(roadsGeoJSON), "utf8");
console.log("Roads identified and saved to roads.geojson file.");
});