Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
'use strict'
var fs = require('fs');
var jsonfile = require('jsonfile');
fs.readFile(__dirname + '/data/seoul-beobjeongdong.geojson', function(err, data) {
const dongs = JSON.parse(data);
fs.readFile(__dirname + '/data/buildings.json', function(err2, data2) {
const numbers = JSON.parse(data2);
const newFeatures = [];
for(const n in numbers) {
for(const feature of dongs.features) {
if (feature.properties.EMD_KOR_NM == numbers[n].kr_name) {
var trimmedDongCode = n.substring(0, n.length-2);
if(feature.properties.EMD_CD == trimmedDongCode) {
const newFeature = {}
newFeature.properties = {};
newFeature.type ='Feature';
newFeature.properties.en_name = feature.properties.EMD_ENG_NM;
newFeature.properties.kr_name = feature.properties.EMD_KOR_NM;
newFeature.geometry = feature.geometry;
newFeature.properties.average = numbers[n].ave;
newFeature.properties.numberWData = numbers[n].total;
newFeature.properties.numberWOdata = numbers[n].woData;
newFeatures.push(newFeature);
break;
} else {
console.log(feature.properties.EMD_KOR_NM)
console.log('what!');
}
}
}
}
const newGeojson = {
type:"FeatureCollection",
features: newFeatures
};
writeFile(newGeojson);
});
});
function writeFile(obj) {
console.log('write file');
jsonfile.writeFileSync(__dirname + '/data/test5.geojson', obj);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.