guanxian_yushui.js 4.9 KB

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