52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
const { Pool } = require('pg');
|
|
require('dotenv').config();
|
|
|
|
const pool = new Pool({
|
|
host: process.env.DB_HOST,
|
|
port: parseInt(process.env.DB_PORT),
|
|
user: process.env.DB_USER,
|
|
password: process.env.DB_PASSWORD,
|
|
database: process.env.DB_NAME,
|
|
});
|
|
|
|
async function addUW() {
|
|
const client = await pool.connect();
|
|
try {
|
|
await client.query("SET search_path TO bw_scheddebrock, public;");
|
|
|
|
// Create Table for Infrastructure if not exists
|
|
await client.query(`
|
|
CREATE TABLE IF NOT EXISTS "Infrastruktur" (
|
|
id SERIAL PRIMARY KEY,
|
|
geom GEOMETRY(Point, 25832),
|
|
name TEXT,
|
|
type TEXT
|
|
)
|
|
`);
|
|
|
|
// Clear old UW if any
|
|
await client.query('DELETE FROM "Infrastruktur" WHERE name = \'UW\'');
|
|
|
|
// Insert UW at 52.179574293191095, 7.383016175998623 (WGS84)
|
|
// ST_SetSRID(ST_Point(lng, lat), 4326)
|
|
const query = `
|
|
INSERT INTO "Infrastruktur" (geom, name, type)
|
|
VALUES (
|
|
ST_Transform(ST_SetSRID(ST_Point($1, $2), 4326), 25832),
|
|
'UW',
|
|
'Umspannwerk'
|
|
)
|
|
`;
|
|
await client.query(query, [7.383016175998623, 52.179574293191095]);
|
|
|
|
console.log("UW Marker added to Infrastruktur table.");
|
|
} catch (err) {
|
|
console.error("Error:", err);
|
|
} finally {
|
|
client.release();
|
|
await pool.end();
|
|
}
|
|
}
|
|
|
|
addUW();
|