97 lines
2.4 KiB
JavaScript
97 lines
2.4 KiB
JavaScript
|
|
||
|
|
||
|
async function merge(geo, data, correction_arrondissement = false) {
|
||
|
const features = {};
|
||
|
for( const f of geo.features ) {
|
||
|
// les arrondissements ont un code type "91001"
|
||
|
// dans ce dataset ; c'est faux. Les codes
|
||
|
// d'arrondissements sont de type 911.
|
||
|
if( correction_arrondissement ) {
|
||
|
const code = f.properties.code.substring(0, 2) + f.properties.code.at(-1);
|
||
|
f.properties.code = code;
|
||
|
features[code] = f;
|
||
|
}
|
||
|
else {
|
||
|
features[f.properties.code] = f;
|
||
|
}
|
||
|
}
|
||
|
console.log(`Got ${Object.keys(features).length} features`)
|
||
|
|
||
|
|
||
|
// cet objet contiendra un sous-ensemble des zones
|
||
|
// présentes dans features.
|
||
|
const impots_dataset = {}
|
||
|
for( const node of data ) {
|
||
|
if( node !== null ) {
|
||
|
impots_dataset[node.code] = node;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
const results = []
|
||
|
for( const [code, feature] of Object.entries(features) ) {
|
||
|
const node = impots_dataset[code];
|
||
|
|
||
|
if( node ) {
|
||
|
results.push({
|
||
|
...feature,
|
||
|
properties: node,
|
||
|
});
|
||
|
}
|
||
|
else {
|
||
|
results.push(feature);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//for( const node of data ) {
|
||
|
// try {
|
||
|
// if(node === null) {
|
||
|
// continue;
|
||
|
// }
|
||
|
|
||
|
// const obj = features[node.code];
|
||
|
|
||
|
// // node contient déjà "code" et "nom",
|
||
|
// // les deux seules propriétés présentes
|
||
|
// // dans le GeoJSON
|
||
|
// obj.properties = node;
|
||
|
|
||
|
// results.push(obj);
|
||
|
// }
|
||
|
// catch(e) {
|
||
|
// error_count++;
|
||
|
// //console.error(node.code)
|
||
|
// //console.error(features[node.code])
|
||
|
// //console.error(e);
|
||
|
// //process.exit()
|
||
|
// }
|
||
|
//}
|
||
|
|
||
|
//console.log('Got ' + error_count + ' errors.')
|
||
|
|
||
|
return {
|
||
|
...geo,
|
||
|
features: results
|
||
|
};
|
||
|
}
|
||
|
|
||
|
|
||
|
(async () => {
|
||
|
const dep_geo = await Bun.file("./departements.geojson").json();
|
||
|
const arr_geo = await Bun.file("./arrondissements.geojson").json();
|
||
|
const com_geo = await Bun.file("./communes.geojson").json();
|
||
|
|
||
|
const departements = await Bun.file("./full-data_departements.json").json();
|
||
|
const arrondissements = await Bun.file("./full-data_arrondissements.json").json();
|
||
|
const communes = await Bun.file("./full-data_communes.json").json();
|
||
|
|
||
|
const deps = await merge(dep_geo, departements);
|
||
|
const arrs = await merge(arr_geo, arrondissements, true);
|
||
|
const coms = await merge(com_geo, communes);
|
||
|
|
||
|
|
||
|
await Bun.write(`./_DEPARTEMENTS.geojson`, JSON.stringify(deps, null, 4));
|
||
|
await Bun.write(`./_ARRONDISSEMENTS.geojson`, JSON.stringify(arrs, null, 4));
|
||
|
await Bun.write(`./_COMMUNES.geojson`, JSON.stringify(coms, null, 4));
|
||
|
})();
|