building.js 993 B

1234567891011121314151617181920212223242526
  1. const fs = require('fs');
  2. function readFile(inFilePath, outFilePath) {
  3. try {
  4. // 同步读取GeoJSON文件
  5. const data = fs.readFileSync(inFilePath, 'utf8');
  6. // 解析GeoJSON数据
  7. const geojson = JSON.parse(data);
  8. for (let i = 0; i < 20; i++) {
  9. geojson.features.push(JSON.parse(JSON.stringify(geojson.features[0])));
  10. }
  11. for (let i = 0; i < geojson.features.length; i++) {
  12. geojson.features[i].properties["楼层"] = i + 1;
  13. geojson.features[i].properties["层高"] = 3;
  14. geojson.features[i].properties["高程"] = i * 3;
  15. }
  16. fs.writeFileSync(outFilePath, JSON.stringify(geojson, null, 2));
  17. console.log("输出")
  18. } catch (err) {
  19. console.error('操作GeoJSON文件时出错:', err);
  20. }
  21. }
  22. // readFile("./data/building/left_build.json", "./data/building/left_build1.json")
  23. readFile("./data/building/right_build.json", "./data/building/right_build1.json")