guanxian.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. const fs = require('fs');
  2. const turf = require('@turf/turf');
  3. function readLineFile(inFilePath, outFilePath) {
  4. try {
  5. // 同步读取GeoJSON文件
  6. const data = fs.readFileSync(inFilePath, 'utf8');
  7. // 解析GeoJSON数据
  8. const geojson = JSON.parse(data);
  9. for (let i = 0; i < geojson.features.length; i++) {
  10. let feature = geojson.features[i];
  11. if (geojson.features[i].properties["断面尺"] !== null &&
  12. geojson.features[i].properties["断面尺"].includes("×")) {
  13. // 方管
  14. geojson.features[i].properties["符号风格"] = 130
  15. geojson.features[i].properties["符号颜色"] = "#FF0000"
  16. let ll = geojson.features[i].properties["断面尺"].split("×")
  17. geojson.features[i].properties["宽度"] = Number(ll[0]) / 1000
  18. } else {
  19. // 圆管
  20. geojson.features[i].properties["符号风格"] = 129
  21. geojson.features[i].properties["符号颜色"] = "#00FF00"
  22. geojson.features[i].properties["宽度"] = Number(geojson.features[i].properties["断面尺"]) / 2 / 1000
  23. }
  24. }
  25. // 同步写入GeoJSON文件
  26. fs.writeFileSync(outFilePath, JSON.stringify(geojson, null, 2));
  27. console.log('GeoJSON文件已成功保存');
  28. } catch (err) {
  29. console.error('操作GeoJSON文件时出错:', err);
  30. }
  31. }
  32. function readPointFile(inFilePath, outFilePath) {
  33. try {
  34. // 同步读取GeoJSON文件
  35. const data = fs.readFileSync(inFilePath, 'utf8');
  36. // 铸铁 砼 地砖 复合 大理石 沥青覆盖 玻璃钢 钢
  37. // 解析GeoJSON数据
  38. const geojson = JSON.parse(data);
  39. for (let i = 0; i < geojson.features.length; i++) {
  40. let feature = geojson.features[i]
  41. let gaiCai = geojson.features[i].properties["井盖材"]
  42. if (gaiCai !== null) {
  43. // if (gaiCai == "铸铁") {
  44. // }else if(gaiCai == "砼"){
  45. // }else if(gaiCai == "地砖"){
  46. // }else if(gaiCai == "复合"){
  47. // }else if(gaiCai == "大理石"){
  48. // }else if(gaiCai == "沥青覆盖"){
  49. // }else if(gaiCai == "玻璃钢"){
  50. // }else if(gaiCai == "钢"){
  51. // }
  52. let gui = geojson.features[i].properties["井盖规"]
  53. if (gui !== null) {
  54. if (gui.includes("×")) {
  55. let ll = gui.split("×")
  56. geojson.features[i].properties["符号风格"] = 54440
  57. geojson.features[i].properties["符号颜色"] = "#0000FF"
  58. geojson.features[i].properties["宽度"] = Number(ll[0])
  59. } else {
  60. geojson.features[i].properties["符号风格"] = 54440
  61. geojson.features[i].properties["符号颜色"] = "#0000FF"
  62. geojson.features[i].properties["宽度"] = Number(gui) / 2
  63. }
  64. }
  65. } else {
  66. geojson.features[i].properties["符号风格"] = 96
  67. geojson.features[i].properties["符号颜色"] = "#FFFFFF"
  68. }
  69. }
  70. // 同步写入GeoJSON文件
  71. fs.writeFileSync(outFilePath, JSON.stringify(geojson, null, 2));
  72. console.log('GeoJSON文件已成功保存');
  73. } catch (err) {
  74. console.error('操作GeoJSON文件时出错:', err);
  75. }
  76. }
  77. readLineFile("./data/guanxian/L.geojson", "./data/guanxian/L1.geojson");
  78. readPointFile("./data/guanxian/P.geojson", "./data/guanxian/P1.geojson");