guanxian.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. const fs = require('fs');
  2. const turf = require('@turf/turf');
  3. const parse = require('wellknown');
  4. function readLineFile(inFilePath, outFilePath) {
  5. try {
  6. // 同步读取GeoJSON文件
  7. const data = fs.readFileSync(inFilePath, 'utf8');
  8. // 解析GeoJSON数据
  9. const geojson = JSON.parse(data);
  10. for (let i = 0; i < geojson.features.length; i++) {
  11. let feature = geojson.features[i];
  12. if (geojson.features[i].properties["断面尺"] !== null &&
  13. geojson.features[i].properties["断面尺"].includes("×")) {
  14. // 方管
  15. geojson.features[i].properties["符号风格"] = 130
  16. geojson.features[i].properties["符号颜色"] = "#717f82"
  17. let ll = geojson.features[i].properties["断面尺"].split("×")
  18. geojson.features[i].properties["x长"] = Number(ll[0]) / 1000
  19. geojson.features[i].properties["x宽"] = Number(ll[1]) / 1000
  20. } else {
  21. // 圆管
  22. geojson.features[i].properties["符号风格"] = 129
  23. geojson.features[i].properties["符号颜色"] = "#717f82"
  24. geojson.features[i].properties["x长"] = Number(geojson.features[i].properties["断面尺"]) / 2 / 1000
  25. geojson.features[i].properties["x宽"] = Number(geojson.features[i].properties["断面尺"]) / 2 / 1000
  26. }
  27. }
  28. // geojson.features = geojson.features.slice(0, 5000)
  29. // 同步写入GeoJSON文件
  30. fs.writeFileSync(outFilePath, JSON.stringify(geojson, null, 2));
  31. console.log('GeoJSON文件已成功保存');
  32. } catch (err) {
  33. console.error('操作GeoJSON文件时出错:', err);
  34. }
  35. }
  36. function readPointFile(inFilePath, outFilePath) {
  37. try {
  38. // 同步读取GeoJSON文件
  39. const data = fs.readFileSync(inFilePath, 'utf8');
  40. // 铸铁 砼 地砖 复合 大理石 沥青覆盖 玻璃钢 钢
  41. // 解析GeoJSON数据
  42. const geojson = JSON.parse(data);
  43. for (let i = 0; i < geojson.features.length; i++) {
  44. let feature = geojson.features[i]
  45. let gaiCai = geojson.features[i].properties["井盖材"]
  46. if (gaiCai !== null) {
  47. // if (gaiCai == "铸铁") {
  48. // }else if(gaiCai == "砼"){
  49. // }else if(gaiCai == "地砖"){
  50. // }else if(gaiCai == "复合"){
  51. // }else if(gaiCai == "大理石"){
  52. // }else if(gaiCai == "沥青覆盖"){
  53. // }else if(gaiCai == "玻璃钢"){
  54. // }else if(gaiCai == "钢"){
  55. // }
  56. let gui = geojson.features[i].properties["井盖规"]
  57. if (gui !== null) {
  58. if (gui.includes("×")) {
  59. let ll = gui.split("×")
  60. geojson.features[i].properties["符号风格"] = 100
  61. geojson.features[i].properties["符号颜色"] = "#717f82"
  62. geojson.features[i].properties["sf"] = 0.003
  63. } else {
  64. geojson.features[i].properties["符号风格"] = 99
  65. geojson.features[i].properties["符号颜色"] = "#717f82"
  66. // geojson.features[i].properties["x长"] = Number(gui) / 2/100
  67. // geojson.features[i].properties["x宽"] = Number(gui) / 2/100
  68. geojson.features[i].properties["sf"] = 0.01
  69. }
  70. }
  71. } else {
  72. geojson.features[i].properties["符号风格"] = 99
  73. geojson.features[i].properties["符号颜色"] = "#717f82"
  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. // geojson.features = geojson.features.slice(0, 5000)
  80. // 同步写入GeoJSON文件
  81. fs.writeFileSync(outFilePath, JSON.stringify(geojson, null, 2));
  82. console.log('GeoJSON文件已成功保存');
  83. } catch (err) {
  84. console.error('操作GeoJSON文件时出错:', err);
  85. }
  86. }
  87. function getJingLine(inFilePath, outFilePath) {
  88. try {
  89. // 同步读取GeoJSON文件
  90. const data = fs.readFileSync(inFilePath, 'utf8');
  91. // 铸铁 砼 地砖 复合 大理石 沥青覆盖 玻璃钢 钢
  92. // 解析GeoJSON数据
  93. const geojson = JSON.parse(data);
  94. for (let i = 0; i < geojson.features.length; i++) {
  95. let feature = geojson.features[i]
  96. const lng = feature.geometry.coordinates[0]
  97. const lat = feature.geometry.coordinates[1]
  98. const z = feature.geometry.coordinates[2]
  99. const zStart = z;
  100. const zEnd = feature.properties["井底深"]
  101. const lineGeom = turf.lineString([
  102. [lng, lat, zStart],
  103. [lng, lat, zEnd]
  104. ]);
  105. geojson.features[i].geometry = lineGeom.geometry;
  106. let gaiCai = geojson.features[i].properties["井盖材"]
  107. if (gaiCai !== null) {
  108. let gui = geojson.features[i].properties["井盖规"]
  109. if (gui !== null) {
  110. if (gui.includes("×")) {
  111. let ll = gui.split("×")
  112. geojson.features[i].properties["符号风格"] = 130
  113. geojson.features[i].properties["符号颜色"] = "#717f82"
  114. geojson.features[i].properties["x长"] = Number(ll[0])
  115. geojson.features[i].properties["x宽"] = Number(ll[0])
  116. } else {
  117. geojson.features[i].properties["符号风格"] = 129
  118. geojson.features[i].properties["符号颜色"] = "#717f82"
  119. geojson.features[i].properties["x长"] = Number(gui) / 2
  120. geojson.features[i].properties["x宽"] = Number(gui) / 2
  121. }
  122. }
  123. } else {
  124. geojson.features[i].properties["x长"] = 0.7
  125. geojson.features[i].properties["x宽"] = 0.7
  126. geojson.features[i].properties["符号风格"] = 129
  127. geojson.features[i].properties["符号颜色"] = "#717f82"
  128. }
  129. // console.log("");
  130. }
  131. // geojson.features = geojson.features.slice(0, 5000)
  132. // 同步写入GeoJSON文件
  133. fs.writeFileSync(outFilePath, JSON.stringify(geojson, null, 2));
  134. console.log('GeoJSON文件已成功保存');
  135. } catch (err) {
  136. console.error('操作GeoJSON文件时出错:', err);
  137. }
  138. }
  139. // readLineFile("./data/guanxian/污水_L.geojson", "./data/guanxian/污水_L1.geojson");
  140. readPointFile("./data/guanxian/污水_P.geojson", "./data/guanxian/污水_P1.geojson");
  141. // getJingLine("./data/guanxian/污水_P.geojson", "./data/guanxian/污水_P1_line.geojson");