123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- // 管井适配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);
|