Quellcode durchsuchen

添加井盖高程数据查询

gushoubang vor 1 Jahr
Ursprung
Commit
d48b7289b2

+ 105 - 0
index/pipeline/adaptDem.js

@@ -0,0 +1,105 @@
+// 管井适配dem
+
+const Database = require('../db');
+const turf = require('@turf/turf');
+const fs = require('fs');
+const wkt = require('wkt');
+
+
+const pool = new Database({
+    host: '192.168.100.30',
+    database: 'real3d',
+    user: 'postgres',
+    password: 'postgis',
+    port: 5432,
+});
+
+const inputPointPath = "./data/guanxian/雨水/符号字段/雨水_P.geojson"
+const inputLinePath = "./data/guanxian/雨水/符号字段/雨水_P.geojson"
+
+
+
+// 获取dem的矢量范围
+async function getDemExtent() {
+    await pool.connect();
+    await pool.setSchema('base');
+
+    const sql =
+        `SELECT
+            PUBLIC.st_asgeojson(
+                PUBLIC.st_transform(
+                    PUBLIC.ST_SetSRID(
+                        PUBLIC.ST_Extent(
+                            PUBLIC.ST_Envelope(rast)
+                        ),
+                        3857
+                    ),
+                    4326
+                )
+            ) AS extent
+        FROM
+            vector."RASTER_DEM_BP";
+        `;
+    // console.log(sql);
+    const result = await pool.query(sql);
+    return result.rows[0].extent;
+}
+// 获取给定点的高程值
+// 获取给定点的高程值
+async function getDemHeight(wktStr) {
+    const transformedGeom = `PUBLIC.ST_Transform(PUBLIC.ST_SetSRID(PUBLIC.ST_GeomFromText($1), 4326), 3857)`;
+
+    const sql = `
+        SELECT PUBLIC.ST_Value(rast, ${transformedGeom}) AS height
+        FROM vector."RASTER_DEM_BP"
+        WHERE PUBLIC.ST_Intersects(rast, ${transformedGeom})
+    `;
+
+    // console.log(`Executing SQL: ${sql} with parameter: ${wktStr}`);
+    const result = await pool.query(sql, [wktStr]);
+    return result.rows[0].height;
+}
+
+// 重新设置井盖的高度
+async function setPointHeight(geoJson, filePath) {
+    const data = fs.readFileSync(filePath, 'utf8');
+    // 解析GeoJSON数据
+    const collect = JSON.parse(data);
+    for (let i = 0; i < collect.features.length; i++) {
+        let pointFeature = collect.features[i]
+        const polygon = JSON.parse(geoJson);
+        const point = turf.point([pointFeature.geometry.coordinates[0], pointFeature.geometry.coordinates[1]]);
+
+        const isContain = turf.booleanContains(polygon, point);
+        if (isContain) {
+            const pointWkt = wkt.stringify(point);
+            const height = await getDemHeight(pointWkt);
+            if (height !== null) {
+                console.log("包含:" + pointWkt);
+                console.log(height);
+            }
+        } else {
+            console.log("不包含");
+        }
+    }
+
+
+
+    // const sql =
+    //     `UPDATE base."t_gj" SET "z" = 0 WHERE "z" < 0;`;
+    // console.log(sql);
+    // const result = await pool.query(sql);
+    // return result.rows[0].extent;
+}
+
+async function adaptDem(pointFilePath) {
+    // 获取抱坡范围
+    const bpGeom = await getDemExtent();
+    // console.log(bpGeom);
+    // 设置井盖高度
+    await setPointHeight(bpGeom, pointFilePath);
+
+    pool.disconnect();
+}
+
+adaptDem(inputPointPath);

+ 0 - 0
index/guanxian_gongyeguanxian.js → index/pipeline/guanxian_gongyeguanxian.js


+ 0 - 0
index/guanxian_paishui.js → index/pipeline/guanxian_paishui.js


+ 0 - 0
index/guanxian_paishui_hunjiedian.js → index/pipeline/guanxian_paishui_hunjiedian.js


+ 0 - 0
index/guanxian_paishui_jierudian.js → index/pipeline/guanxian_paishui_jierudian.js


+ 0 - 0
index/guanxian_wushui.js → index/pipeline/guanxian_wushui.js


+ 0 - 0
index/guanxian_yushui.js → index/pipeline/guanxian_yushui.js


+ 0 - 0
index/guanxian_yuwu.js → index/pipeline/guanxian_yuwu.js


+ 5 - 0
package-lock.json

@@ -1805,6 +1805,11 @@
         "minimist": "~1.2.0"
       }
     },
+    "wkt": {
+      "version": "0.1.1",
+      "resolved": "https://registry.npmmirror.com/wkt/-/wkt-0.1.1.tgz",
+      "integrity": "sha512-2vtzYZOqN0VZdtDTMDUgbpXpE+MXRdsFTiCpS08FZ4yktT9pPylVMZaLxcIqT9pRkBp5FIAGVQyJ/kJa9b8uGg=="
+    },
     "wkx": {
       "version": "0.5.0",
       "resolved": "https://registry.npmjs.org/wkx/-/wkx-0.5.0.tgz",

+ 1 - 0
package.json

@@ -14,6 +14,7 @@
     "pg": "^8.12.0",
     "uuid": "^10.0.0",
     "wellknown": "^0.5.0",
+    "wkt": "^0.1.1",
     "wkx": "^0.5.0"
   }
 }