const fs = require('fs'); const turf = require('@turf/turf'); const parse = require('wellknown'); const wuShuiColor = "#AD835D"; const wuShuiCircle = 500005; const wuShuiFang = 500003; const fangGuan=12010001; const yuanGuan=510000; 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["符号风格"] = fangGuan geojson.features[i].properties["符号颜色"] = wuShuiColor 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["符号风格"] = yuanGuan geojson.features[i].properties["符号颜色"] = wuShuiColor 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] // const z = feature.geometry.coordinates[2] let zDepth=feature.properties["井底深"] // const zStart = z; // const zEnd =zStart-zDepth let gaiCai = geojson.features[i].properties["井盖材"] if (gaiCai !== null) { let gui = geojson.features[i].properties["井盖规"] if (gui !== null) { if (gui.includes("×")) { if (zDepth===0){ zDepth=2 } geojson.features[i].properties["zScale"]=zDepth/1.2 let ll = gui.split("×") geojson.features[i].properties["符号风格"] = wuShuiFang geojson.features[i].properties["符号颜色"] = wuShuiColor geojson.features[i].properties["sf"] = 0.005 } else { if (zDepth===0){ zDepth=3.5 } geojson.features[i].properties["zScale"]=zDepth/1.2 geojson.features[i].properties["符号风格"] = wuShuiCircle geojson.features[i].properties["符号颜色"] = wuShuiColor // 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 { if (zDepth===0){ zDepth=3.5 } geojson.features[i].properties["zScale"]=zDepth/1.2 geojson.features[i].properties["符号风格"] = wuShuiCircle geojson.features[i].properties["符号颜色"] = wuShuiColor // 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 zDepth=feature.properties["井底深"] // const zStart = z; // const zEnd =zStart-zDepth // const lineGeom = turf.lineString([ // [lng, lat, zStart], // [lng, lat, zEnd] // ]); // geojson.features[i].properties["zScale"]=zEnd/1.2 // 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["符号风格"] = wuShuiFangJing // geojson.features[i].properties["符号颜色"] = wuShuiColor // geojson.features[i].properties["x长"] = Number(ll[0]) // geojson.features[i].properties["x宽"] = Number(ll[0]) // } else { // // 圆 // geojson.features[i].properties["符号风格"] = wuShuiCircleJing // geojson.features[i].properties["符号颜色"] = wuShuiColor // 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["符号风格"] = wuShuiCircleJing // geojson.features[i].properties["符号颜色"] = wuShuiColor // } // // 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/污水/符号字段/污水_L.geojson"); readPointFile("./data/guanxian/污水/原始数据/污水_P.geojson", "./data/guanxian/污水/符号字段/污水_P.geojson"); // getJingLine("./data/guanxian/污水/原始数据/污水_P.geojson", "./data/guanxian/污水/符号字段/污水_P_line.geojson");