forked from mwgg/Airports
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.js
68 lines (58 loc) · 1.44 KB
/
convert.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"use strict";
var airports = require("./airports.json");
var fs = require("fs");
class AirportFeature {
constructor(aAirport) {
const airport = aAirport[1];
this.icao = airport.icao;
this.iata = airport.iata;
this.name = airport.name;
this.city = airport.city;
this.state = airport.state;
this.country = airport.country;
this.elevation = airport.elevation;
this.lat = airport.lat;
this.lon = airport.lon;
this.tz = airport.tz;
}
}
var features = [];
var collection = {
type: "FeatureCollection",
features: features,
};
var airportArray = [];
for (var i in airports) airportArray.push([i, airports[i]]);
airportArray.forEach((aAirport) => {
const airport = new AirportFeature(aAirport);
let feature = {
type: "Feature",
properties: {
icao: airport.icao,
iata: airport.iata,
name: airport.name,
city: airport.city,
state: airport.state,
country: airport.country,
elevation: airport.elevation,
tz: airport.tz,
},
geometry: {
type: "Point",
coordinates: [airport.lon, airport.lat],
},
};
features.push(feature);
});
if (fs.existsSync("airports.geojson")) {
try {
fs.unlinkSync("airports.geojson");
//file removed
} catch (err) {
console.error(err);
}
}
fs.writeFile("airports.geojson", JSON.stringify(collection), function (err) {
if (err) return console.log(err);
console.log("Created airports.geojson");
});