guanxian_yuwu.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. const fs = require('fs');
  2. const turf = require('@turf/turf');
  3. const parse = require('wellknown');
  4. const wuShuiColor = "#34A853";
  5. const wuShuiCircle = 500005;
  6. const wuShuiFang = 500003;
  7. const fangGuan=12010001;
  8. const yuanGuan=510000;
  9. function readLineFile(inFilePath, outFilePath) {
  10. try {
  11. // 同步读取GeoJSON文件
  12. const data = fs.readFileSync(inFilePath, 'utf8');
  13. // 解析GeoJSON数据
  14. const geojson = JSON.parse(data);
  15. for (let i = 0; i < geojson.features.length; i++) {
  16. let feature = geojson.features[i];
  17. if (geojson.features[i].properties["断面尺"] !== null &&
  18. geojson.features[i].properties["断面尺"].includes("×")) {
  19. // 方管
  20. geojson.features[i].properties["符号风格"] = fangGuan
  21. geojson.features[i].properties["符号颜色"] = wuShuiColor
  22. let ll = geojson.features[i].properties["断面尺"].split("×")
  23. geojson.features[i].properties["x长"] = Number(ll[0]) / 1000
  24. geojson.features[i].properties["x宽"] = Number(ll[1]) / 1000
  25. } else {
  26. // 圆管
  27. geojson.features[i].properties["符号风格"] = yuanGuan
  28. geojson.features[i].properties["符号颜色"] = wuShuiColor
  29. geojson.features[i].properties["x长"] = Number(geojson.features[i].properties["断面尺"]) / 2 / 1000
  30. geojson.features[i].properties["x宽"] = Number(geojson.features[i].properties["断面尺"]) / 2 / 1000
  31. }
  32. }
  33. // geojson.features = geojson.features.slice(0, 5000)
  34. // 同步写入GeoJSON文件
  35. fs.writeFileSync(outFilePath, JSON.stringify(geojson, null, 2));
  36. console.log('GeoJSON文件已成功保存');
  37. } catch (err) {
  38. console.error('操作GeoJSON文件时出错:', err);
  39. }
  40. }
  41. function readPointFile(inFilePath, outFilePath) {
  42. try {
  43. // 同步读取GeoJSON文件
  44. const data = fs.readFileSync(inFilePath, 'utf8');
  45. // 铸铁 砼 地砖 复合 大理石 沥青覆盖 玻璃钢 钢
  46. // 解析GeoJSON数据
  47. const geojson = JSON.parse(data);
  48. for (let i = 0; i < geojson.features.length; i++) {
  49. let feature = geojson.features[i]
  50. // const z = feature.geometry.coordinates[2]
  51. let zDepth=feature.properties["井底深"]
  52. // const zStart = z;
  53. // const zEnd =zStart-zDepth
  54. let gaiCai = geojson.features[i].properties["井盖材"]
  55. if (gaiCai !== null) {
  56. let gui = geojson.features[i].properties["井盖规"]
  57. if (gui !== null) {
  58. if (gui.includes("×")) {
  59. if (zDepth===0){
  60. zDepth=2
  61. }
  62. geojson.features[i].properties["zScale"]=zDepth/1.2
  63. let ll = gui.split("×")
  64. geojson.features[i].properties["符号风格"] = wuShuiFang
  65. geojson.features[i].properties["符号颜色"] = wuShuiColor
  66. geojson.features[i].properties["sf"] = 0.005
  67. } else {
  68. if (zDepth===0){
  69. zDepth=2.5
  70. }
  71. geojson.features[i].properties["zScale"]=zDepth/1.2
  72. geojson.features[i].properties["符号风格"] = wuShuiCircle
  73. geojson.features[i].properties["符号颜色"] = wuShuiColor
  74. // geojson.features[i].properties["x长"] = Number(gui) / 2/100
  75. // geojson.features[i].properties["x宽"] = Number(gui) / 2/100
  76. geojson.features[i].properties["sf"] = 0.01
  77. }
  78. }
  79. } else {
  80. if (zDepth===0){
  81. zDepth=2.5
  82. }
  83. geojson.features[i].properties["zScale"]=zDepth/1.2
  84. geojson.features[i].properties["符号风格"] = wuShuiCircle
  85. geojson.features[i].properties["符号颜色"] = wuShuiColor
  86. // geojson.features[i].properties["x长"] = Number(gui) / 2/100
  87. // geojson.features[i].properties["x宽"] = Number(gui) / 2/100
  88. geojson.features[i].properties["sf"] = 0.01
  89. }
  90. }
  91. // geojson.features = geojson.features.slice(0, 5000)
  92. // 同步写入GeoJSON文件
  93. fs.writeFileSync(outFilePath, JSON.stringify(geojson, null, 2));
  94. console.log('GeoJSON井盖文件已成功保存');
  95. } catch (err) {
  96. console.error('操作GeoJSON文件时出错:', err);
  97. }
  98. }
  99. readLineFile("./data/guanxian/雨污合流/原始数据/雨污合流_L.geojson", "./data/guanxian/雨污合流/符号字段/雨污合流_L.geojson");
  100. readPointFile("./data/guanxian/雨污合流/原始数据/雨污合流_P.geojson", "./data/guanxian/雨污合流/符号字段/雨污合流_P.geojson");