-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvatspy.js
28 lines (22 loc) · 964 Bytes
/
vatspy.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
const fs = require('fs');
const turf = require('@turf/turf');
module.exports = {
initialize() {
if (!fs.existsSync('vatspy')) {
fs.mkdirSync('vatspy');
}
},
generateVatspyFile() {
// get fir
var geojsonFeatures = JSON.parse(fs.readFileSync('./database/airspace/FIR.geojson')).features;
var ret = [];
geojsonFeatures.forEach(e => {
var polygon = turf.polygon(e.geometry.coordinates[0]);
var center = turf.centerOfMass(polygon);
e.properties.label_lon = center.geometry.coordinates[0].toFixed(6);
e.properties.label_lat = center.geometry.coordinates[1].toFixed(6);
ret.push(e.properties.id + ": " + JSON.stringify(e, null, ' ').split("\n").join("").split(" ").join(" ").split(" ").join(" ").split(" ").join(" "));
});
fs.writeFileSync('vatspy/geojson.txt', ret.join("\n"));
}
};