guanxian_paishui.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. const fs = require('fs');
  2. const turf = require('@turf/turf');
  3. const parse = require('wellknown');
  4. const wuShuiColor = "#628DB6";
  5. const wuShuiCircle = 500001;
  6. const wuShuiFang = 500003;
  7. const fangGuan=12010001;
  8. const yuanGuan=310000;
  9. const scaleYuan=3.1;
  10. const scaleFang=1;
  11. const yuanDefault=2.3;
  12. function readLineFile(inFilePath, outFilePath) {
  13. try {
  14. // 同步读取GeoJSON文件
  15. const data = fs.readFileSync(inFilePath, 'utf8');
  16. // 解析GeoJSON数据
  17. const geojson = JSON.parse(data);
  18. for (let i = 0; i < geojson.features.length; i++) {
  19. geojson.features[i].geometry.coordinates[0][0][2]=geojson.features[i].geometry.coordinates[0][0][2]-0.5
  20. let feature = geojson.features[i];
  21. if (geojson.features[i].properties["排口断"] !== null &&
  22. geojson.features[i].properties["排口断"].includes("×")) {
  23. // 方管
  24. geojson.features[i].properties["符号风格"] = fangGuan
  25. geojson.features[i].properties["符号颜色"] = wuShuiColor
  26. let ll = geojson.features[i].properties["排口断"].split("×")
  27. geojson.features[i].properties["x长"] = Number(ll[0]) / 1000
  28. geojson.features[i].properties["x宽"] = Number(ll[1]) / 1000
  29. } else {
  30. // 圆管
  31. geojson.features[i].properties["符号风格"] = yuanGuan
  32. geojson.features[i].properties["符号颜色"] = wuShuiColor
  33. geojson.features[i].properties["x长"] = Number(geojson.features[i].properties["排口断"]) / 2 / 1000
  34. geojson.features[i].properties["x宽"] = Number(geojson.features[i].properties["排口断"]) / 2 / 1000
  35. }
  36. }
  37. // 同步写入GeoJSON文件
  38. fs.writeFileSync(outFilePath, JSON.stringify(geojson, null, 2));
  39. console.log('GeoJSON文件已成功保存');
  40. } catch (err) {
  41. console.error('操作GeoJSON文件时出错:', err);
  42. }
  43. }
  44. readLineFile("./data/guanxian/雨水/原始数据/排水口_L.geojson", "./data/guanxian/雨水/符号字段/排水口_L.geojson");