guanxian_wushui.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. const fs = require('fs');
  2. const turf = require('@turf/turf');
  3. const parse = require('wellknown');
  4. const wuShuiColor = "#AD835D";
  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=3.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=3.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. // function getJingLine(inFilePath, outFilePath) {
  100. // try {
  101. // // 同步读取GeoJSON文件
  102. // const data = fs.readFileSync(inFilePath, 'utf8');
  103. // // 铸铁 砼 地砖 复合 大理石 沥青覆盖 玻璃钢 钢
  104. // // 解析GeoJSON数据
  105. // const geojson = JSON.parse(data);
  106. // for (let i = 0; i < geojson.features.length; i++) {
  107. // let feature = geojson.features[i]
  108. // const lng = feature.geometry.coordinates[0]
  109. // const lat = feature.geometry.coordinates[1]
  110. // const z = feature.geometry.coordinates[2]
  111. // const zDepth=feature.properties["井底深"]
  112. // const zStart = z;
  113. // const zEnd =zStart-zDepth
  114. // const lineGeom = turf.lineString([
  115. // [lng, lat, zStart],
  116. // [lng, lat, zEnd]
  117. // ]);
  118. // geojson.features[i].properties["zScale"]=zEnd/1.2
  119. // geojson.features[i].geometry = lineGeom.geometry;
  120. // let gaiCai = geojson.features[i].properties["井盖材"]
  121. // if (gaiCai !== null) {
  122. // let gui = geojson.features[i].properties["井盖规"]
  123. // if (gui !== null) {
  124. // if (gui.includes("×")) {
  125. // // 方
  126. // let ll = gui.split("×")
  127. // geojson.features[i].properties["符号风格"] = wuShuiFangJing
  128. // geojson.features[i].properties["符号颜色"] = wuShuiColor
  129. // geojson.features[i].properties["x长"] = Number(ll[0])
  130. // geojson.features[i].properties["x宽"] = Number(ll[0])
  131. // } else {
  132. // // 圆
  133. // geojson.features[i].properties["符号风格"] = wuShuiCircleJing
  134. // geojson.features[i].properties["符号颜色"] = wuShuiColor
  135. // geojson.features[i].properties["x长"] = Number(gui) / 2
  136. // geojson.features[i].properties["x宽"] = Number(gui) / 2
  137. // }
  138. // }
  139. // } else {
  140. // geojson.features[i].properties["x长"] = 0.7
  141. // geojson.features[i].properties["x宽"] = 0.7
  142. // geojson.features[i].properties["符号风格"] = wuShuiCircleJing
  143. // geojson.features[i].properties["符号颜色"] = wuShuiColor
  144. // }
  145. // // console.log("");
  146. // }
  147. // // geojson.features = geojson.features.slice(0, 5000)
  148. // // 同步写入GeoJSON文件
  149. // fs.writeFileSync(outFilePath, JSON.stringify(geojson, null, 2));
  150. // console.log('GeoJSON文件已成功保存');
  151. // } catch (err) {
  152. // console.error('操作GeoJSON文件时出错:', err);
  153. // }
  154. // }
  155. // readLineFile("./data/guanxian/污水/原始数据/污水_L.geojson", "./data/guanxian/污水/符号字段/污水_L.geojson");
  156. readPointFile("./data/guanxian/污水/原始数据/污水_P.geojson", "./data/guanxian/污水/符号字段/污水_P.geojson");
  157. // getJingLine("./data/guanxian/污水/原始数据/污水_P.geojson", "./data/guanxian/污水/符号字段/污水_P_line.geojson");