한국공항공사(KAC) - 서버
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

117 lines
4.7 KiB

const fs = require('fs');
const reset = require('./util/reset')
const geoJsonModel = require('./model/geoJsonModel');
const coordinate = require('./GeoJson/ctprvn_sig_emd_li.json');
const codeService = require('./service/codeService');
reset.init('./');
reset.makeCodeFolder(false, coordinate.features); // false로 하면 시도시군구읍면동리 법정동 코드가 나옴
let basepath ='./' + reset.mainFoler;
// 시작
// 전체파일 만들기
let allCtprvnCoordinate = codeService.allLocationCodeMathingService(reset.cdLength[0], coordinate.features)
let ctprvnFile = new geoJsonModel(coordinate.type, reset.baseProperties.get(reset.cdLength[0]), coordinate.crs, allCtprvnCoordinate);
makeFile(basepath + '/all_location' + reset.extension, JSON.stringify(ctprvnFile));
// 시도 폴더만들기 및 파일만들기
let codes = codeService.allCodeServcie(reset.cdLength[0], coordinate.features); // 코드가 2글자인 목록 뽑아오기
for(let i = 0; i < codes.length; i++){
let ctprvnPath = basepath + '/' + codes[i]; // EX => /Coordinate/11
// 폴더만들기
makeFolder(ctprvnPath)
// 시도파일 한개분량 파일만들기
let aloneCoord = codeService.locationCodeMathingService(codes[i], reset.cdLength[0], ctprvnFile.features);
let aloneCoordiFile = new geoJsonModel(coordinate.type, reset.baseProperties.get(reset.cdLength[0]), coordinate.crs, aloneCoord);
let ctprvnFilePath = ctprvnPath + '/' + codes[i] + reset.extension;
makeFile(ctprvnFilePath, JSON.stringify(aloneCoordiFile));
// 시도안에 있는 [시군구] 전체 파일
let allSigCoordinate = codeService.locationCodeMathingService(codes[i], reset.cdLength[1], coordinate.features);
let allSigFile = new geoJsonModel(coordinate.type, reset.baseProperties.get(reset.cdLength[1]), coordinate.crs, allSigCoordinate);
makeFile(ctprvnPath + '/all_location' + reset.extension, JSON.stringify(allSigFile));
let sigCodes = codeService.codeService(codes[i], reset.cdLength[1], coordinate.features);
for(let j = 0; j < sigCodes.length; j ++){
let sigPath = ctprvnPath + "/" + sigCodes[j];
// 폴더만들기
makeFolder(sigPath)
// 시군구파일 한개분량 파일만들기
let aloneSigCoord = codeService.locationCodeMathingService(sigCodes[j], reset.cdLength[1], allSigFile.features);
let aloneSigCoordiFile = new geoJsonModel(coordinate.type, reset.baseProperties.get(reset.cdLength[1]), coordinate.crs, aloneSigCoord);
let sigFilePath = sigPath + '/' + sigCodes[j] + reset.extension;
makeFile(sigFilePath, JSON.stringify(aloneSigCoordiFile));
// 시군구안에 있는 읍면동 전체파일
let allEmdCoordinate = codeService.locationCodeMathingService(sigCodes[j], reset.cdLength[2], coordinate.features);
let allEmdFile = new geoJsonModel(coordinate.type, reset.baseProperties.get(reset.cdLength[2]), coordinate.crs, allEmdCoordinate);
makeFile(sigPath + '/all_location' + reset.extension, JSON.stringify(allEmdFile));
let emdCodes = codeService.codeService(sigCodes[j], reset.cdLength[2], coordinate.features);
for(let k = 0; k < emdCodes.length; k++){
let emdPath = sigPath + "/" + emdCodes[k];
// 폴더만들기
makeFolder(emdPath)
// 읍면동파일 한개분량 파일만들기
let aloneEmdCoord = codeService.locationCodeMathingService(emdCodes[k], reset.cdLength[2], allEmdFile.features);
let aloneEmdCoordiFile = new geoJsonModel(coordinate.type, reset.baseProperties.get(reset.cdLength[2]), coordinate.crs, aloneEmdCoord);
let emdFilePath = emdPath + '/' + emdCodes[k] + reset.extension;
makeFile(emdFilePath, JSON.stringify(aloneEmdCoordiFile));
// 읍면동안에 있는 리 전체파일
let allLiCoordinate = codeService.locationCodeMathingService(emdCodes[k], reset.cdLength[3], coordinate.features);
if(allLiCoordinate.length == 0){
continue;
}
let allLiFile = new geoJsonModel(coordinate.type, reset.baseProperties.get(reset.cdLength[3]), coordinate.crs, allLiCoordinate);
makeFile(emdPath + '/all_location' + reset.extension, JSON.stringify(allLiFile));
}
}
}
function makeFolder(path){
let directoryCheck = fs.existsSync(path)
if(!directoryCheck) {
fs.mkdirSync(path)
}
}
function makeFile(fileName, fileData){
fs.writeFileSync(fileName, fileData, (err) => {
console.log(err)
})
}
// fs.writeFileSync('./' + reset.mainFoler + '/test' + reset.extension, ctprvn, (err) => {
// console.log(err)
// })