const shapefile = require('shapefile'); const { Pool } = require('pg'); const pool = new Pool({ user: 'enwelo_admin', host: '87.106.21.21', database: 'enwelo', password: 'WX1t1cgP1qK09', port: 5432, ssl: false }); async function run() { try { console.log("Reading shapefile..."); const geojson = await shapefile.read("Shapefile/Windeignungsgebiet.shp", "Shapefile/Windeignungsgebiet.dbf"); console.log(`Loaded ${geojson.features.length} features.`); if (geojson.features.length === 0) { console.log("No features found!"); return; } const client = await pool.connect(); try { await client.query('BEGIN'); // wir wollen die Shapefile-Geometrie für samern-ohne in die DB pushen const projektId = 'projekt_bw_samern-ohne'; // Zuerst bestehende löschen? await client.query('DELETE FROM geodaten."potentialflächen_wind" WHERE projekt_id = $1', [projektId]); let count = 0; for (const feature of geojson.features) { const geomJson = JSON.stringify(feature.geometry); await client.query( `INSERT INTO geodaten."potentialflächen_wind" (projekt_id, geom) VALUES ($1, ST_SetSRID(ST_GeomFromGeoJSON($2), 25832))`, [projektId, geomJson] ); count++; } await client.query('COMMIT'); console.log(`Erfolgreich ${count} Potentialflächen für ${projektId} importiert!`); } catch (e) { await client.query('ROLLBACK'); throw e; } finally { client.release(); } } catch(e) { console.error("Fehler:", e); } finally { await pool.end(); } } run();