-
Notifications
You must be signed in to change notification settings - Fork 1
/
indonesia.js
63 lines (52 loc) · 1.55 KB
/
indonesia.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
const fs = require('fs');
const util = require('util');
const readFile = util.promisify(fs.readFile);
const writeFile = util.promisify(fs.writeFile);
(async () => {
const inputString = await readFile('./json/indonesia.json', 'utf8');
const inputJson = JSON.parse(inputString);
const { type, arcs, transform, objects } = inputJson;
const { subunits, states_provinces, places } = objects;
const countries = { type: subunits.type };
countries.geometries = subunits.geometries.map(g => {
return {
type: g.type,
id: g.id,
properties: {
name: g.properties['NAME_LONG']
},
arcs: g.arcs,
};
});
const provinces = { type: states_provinces.type };
provinces.geometries = states_provinces.geometries.map(g => {
return {
type: g.type,
properties: {
name: g.properties.name
},
arcs: g.arcs,
};
});
const cities = { type: places.type };
cities.geometries = places.geometries.map(g => {
return {
type: g.type,
properties: {
name: g.properties['LS_NAME'],
province: g.properties['ADM1NAME'],
country: g.properties['ADM0NAME']
},
coordinates: g.coordinates,
};
});
const outputJson = { type, objects: {
// countries,
provinces,
cities
}, arcs, transform };
const outputString = JSON.stringify(outputJson);
const result = await writeFile('./json/indonesia-provinces-cities-topo.json', outputString, 'utf8');
console.log('result: ', result);
// console.log(JSON.stringify(outputJson.objects.cities));
})();