42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
function saveFile(name, data, out) {
|
|
const ret = {
|
|
type: "FeatureCollection",
|
|
name,
|
|
crs: { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
|
|
features: data.map(({ ADCD, NAME, level, lgtd, lttd }) => ({
|
|
type: "Feature",
|
|
properties: { ADCD, NAME, level, lgtd, lttd },
|
|
geometry: {
|
|
type: "Point",
|
|
coordinates: [lgtd, lttd]
|
|
}
|
|
}))
|
|
};
|
|
|
|
fs.writeFileSync(out, JSON.stringify(ret), 'utf-8');
|
|
}
|
|
|
|
function adlevel(adcd) {
|
|
if (adcd.endsWith('000000000')) {
|
|
return 4;
|
|
} else if (adcd.endsWith('000000')) {
|
|
return 5;
|
|
} else if (adcd.endsWith('000')) {
|
|
return 6;
|
|
}
|
|
return 7;
|
|
}
|
|
|
|
function main() {
|
|
let drpraw = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../public/data/adcd.json'), 'utf8'));
|
|
drpraw = drpraw.data.map(({ ADCD, NAME, lgtd, lttd }) => ({ ADCD, NAME, level: adlevel(ADCD), lgtd, lttd, }))
|
|
saveFile('adcd', drpraw, path.resolve(__dirname, '../public/data/adcd.geojson'));
|
|
}
|
|
|
|
main();
|
|
|
|
console.log('done')
|