forked from frozenexplorer/Hackenza_Website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsafe.js
34 lines (29 loc) · 1.32 KB
/
safe.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
const fs = require('fs');
// Read the GeoJSON file
const geojsonData = JSON.parse(fs.readFileSync('AllRoads.geojson', 'utf8'));
// Initialize an array to store the coordinates
const coordinatesWithLowFloodIntensity = [];
// Initialize a counter to track the number of coordinates added
let count = 0;
// Iterate over the road features
geojsonData.features.forEach(feature => {
if (count < 10 && feature.properties && feature.properties.flood_intensity && feature.properties.flood_intensity == 1) {
// Extract the first coordinate of the road
const coordinates = feature.geometry.coordinates;
if (coordinates.length > 0) {
const firstCoordinate = coordinates[0];
// Swap x and y coordinates
const swappedCoordinate = [firstCoordinate[1], firstCoordinate[0]];
// Push the swapped coordinate to the array
coordinatesWithLowFloodIntensity.push(swappedCoordinate);
// Increment the counter
count++;
}
}
// Exit the loop if count reaches 10 as we are checking best 10 safe nodes possible
if (count >= 10) {
return;
}
});
// Save the array of coordinates to a file or use it as needed
fs.writeFileSync('coordinates_with_low_flood_intensity.json', JSON.stringify(coordinatesWithLowFloodIntensity), 'utf8');