123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- const fs = require('fs');
- const turf = require('@turf/turf');
- const parse = require('wellknown');
- function readLineFile(inFilePath, outFilePath) {
- try {
- // 同步读取GeoJSON文件
- const data = fs.readFileSync(inFilePath, 'utf8');
- // 解析GeoJSON数据
- const geojson = JSON.parse(data);
- for (let i = 0; i < geojson.features.length; i++) {
- let feature = geojson.features[i];
- if (geojson.features[i].properties["断面尺"] !== null &&
- geojson.features[i].properties["断面尺"].includes("×")) {
- // 方管
- geojson.features[i].properties["符号风格"] = 130
- geojson.features[i].properties["符号颜色"] = "#717f82"
- let ll = geojson.features[i].properties["断面尺"].split("×")
- geojson.features[i].properties["x长"] = Number(ll[0]) / 1000
- geojson.features[i].properties["x宽"] = Number(ll[1]) / 1000
- } else {
- // 圆管
- geojson.features[i].properties["符号风格"] = 129
- geojson.features[i].properties["符号颜色"] = "#717f82"
- geojson.features[i].properties["x长"] = Number(geojson.features[i].properties["断面尺"]) / 2 / 1000
- geojson.features[i].properties["x宽"] = Number(geojson.features[i].properties["断面尺"]) / 2 / 1000
- }
- }
- // geojson.features = geojson.features.slice(0, 5000)
- // 同步写入GeoJSON文件
- fs.writeFileSync(outFilePath, JSON.stringify(geojson, null, 2));
- console.log('GeoJSON文件已成功保存');
- } catch (err) {
- console.error('操作GeoJSON文件时出错:', err);
- }
- }
- function readPointFile(inFilePath, outFilePath) {
- try {
- // 同步读取GeoJSON文件
- const data = fs.readFileSync(inFilePath, 'utf8');
- // 铸铁 砼 地砖 复合 大理石 沥青覆盖 玻璃钢 钢
- // 解析GeoJSON数据
- const geojson = JSON.parse(data);
- for (let i = 0; i < geojson.features.length; i++) {
- let feature = geojson.features[i]
- let gaiCai = geojson.features[i].properties["井盖材"]
- if (gaiCai !== null) {
- // if (gaiCai == "铸铁") {
- // }else if(gaiCai == "砼"){
- // }else if(gaiCai == "地砖"){
- // }else if(gaiCai == "复合"){
- // }else if(gaiCai == "大理石"){
- // }else if(gaiCai == "沥青覆盖"){
- // }else if(gaiCai == "玻璃钢"){
- // }else if(gaiCai == "钢"){
- // }
- let gui = geojson.features[i].properties["井盖规"]
- if (gui !== null) {
- if (gui.includes("×")) {
- let ll = gui.split("×")
- geojson.features[i].properties["符号风格"] = 100
- geojson.features[i].properties["符号颜色"] = "#717f82"
- geojson.features[i].properties["sf"] = 0.003
- } else {
- geojson.features[i].properties["符号风格"] = 99
- geojson.features[i].properties["符号颜色"] = "#717f82"
- // geojson.features[i].properties["x长"] = Number(gui) / 2/100
- // geojson.features[i].properties["x宽"] = Number(gui) / 2/100
- geojson.features[i].properties["sf"] = 0.01
- }
- }
- } else {
- geojson.features[i].properties["符号风格"] = 99
- geojson.features[i].properties["符号颜色"] = "#717f82"
- // geojson.features[i].properties["x长"] = Number(gui) / 2/100
- // geojson.features[i].properties["x宽"] = Number(gui) / 2/100
- geojson.features[i].properties["sf"] = 0.01
- }
- }
- // geojson.features = geojson.features.slice(0, 5000)
- // 同步写入GeoJSON文件
- fs.writeFileSync(outFilePath, JSON.stringify(geojson, null, 2));
- console.log('GeoJSON文件已成功保存');
- } catch (err) {
- console.error('操作GeoJSON文件时出错:', err);
- }
- }
- function getJingLine(inFilePath, outFilePath) {
- try {
- // 同步读取GeoJSON文件
- const data = fs.readFileSync(inFilePath, 'utf8');
- // 铸铁 砼 地砖 复合 大理石 沥青覆盖 玻璃钢 钢
- // 解析GeoJSON数据
- const geojson = JSON.parse(data);
- for (let i = 0; i < geojson.features.length; i++) {
- let feature = geojson.features[i]
- const lng = feature.geometry.coordinates[0]
- const lat = feature.geometry.coordinates[1]
- const z = feature.geometry.coordinates[2]
- const zStart = z;
- const zEnd = feature.properties["井底深"]
- const lineGeom = turf.lineString([
- [lng, lat, zStart],
- [lng, lat, zEnd]
- ]);
- geojson.features[i].geometry = lineGeom.geometry;
- let gaiCai = geojson.features[i].properties["井盖材"]
- if (gaiCai !== null) {
- let gui = geojson.features[i].properties["井盖规"]
- if (gui !== null) {
- if (gui.includes("×")) {
- let ll = gui.split("×")
- geojson.features[i].properties["符号风格"] = 130
- geojson.features[i].properties["符号颜色"] = "#717f82"
- geojson.features[i].properties["x长"] = Number(ll[0])
- geojson.features[i].properties["x宽"] = Number(ll[0])
- } else {
- geojson.features[i].properties["符号风格"] = 129
- geojson.features[i].properties["符号颜色"] = "#717f82"
- geojson.features[i].properties["x长"] = Number(gui) / 2
- geojson.features[i].properties["x宽"] = Number(gui) / 2
- }
- }
- } else {
- geojson.features[i].properties["x长"] = 0.7
- geojson.features[i].properties["x宽"] = 0.7
- geojson.features[i].properties["符号风格"] = 129
- geojson.features[i].properties["符号颜色"] = "#717f82"
- }
- // console.log("");
- }
- // geojson.features = geojson.features.slice(0, 5000)
- // 同步写入GeoJSON文件
- fs.writeFileSync(outFilePath, JSON.stringify(geojson, null, 2));
- console.log('GeoJSON文件已成功保存');
- } catch (err) {
- console.error('操作GeoJSON文件时出错:', err);
- }
- }
- // readLineFile("./data/guanxian/污水_L.geojson", "./data/guanxian/污水_L1.geojson");
- readPointFile("./data/guanxian/污水_P.geojson", "./data/guanxian/污水_P1.geojson");
- // getJingLine("./data/guanxian/污水_P.geojson", "./data/guanxian/污水_P1_line.geojson");
|