diff --git a/server.js b/server.js index 53c0f78..bd4a500 100644 --- a/server.js +++ b/server.js @@ -49,7 +49,7 @@ app.get('/api/owners', async (req, res) => { const query = ` SELECT *, - ST_AsGeoJSON(ST_Transform(ST_SetSRID(geom, 25832), 4326)) as geometry + ST_AsGeoJSON(ST_Transform(geom, 4326)) as geometry FROM bw_scheddebrock."Eigentuemerdaten" `; const result = await client.query(query); @@ -89,7 +89,7 @@ app.get('/api/usage', async (req, res) => { const query = ` SELECT *, - ST_AsGeoJSON(ST_Transform(ST_SetSRID(geom, 25832), 4326)) as geometry + ST_AsGeoJSON(ST_Transform(geom, 4326)) as geometry FROM bw_scheddebrock."Nutzung" `; const result = await client.query(query); @@ -121,13 +121,18 @@ app.get('/api/wea', async (req, res) => { const client = await pool.connect(); try { await setSchema(client); - const query = ` - SELECT - *, - ST_AsGeoJSON(ST_Transform(ST_SetSRID(geom, 25832), 4326)) as geometry - FROM bw_scheddebrock."WEA" - `; - const result = await client.query(query); + let result; + try { + result = await client.query(` + SELECT + *, + ST_AsGeoJSON(ST_Transform(geom, 4326)) as geometry + FROM bw_scheddebrock."WEA" + `); + } catch (dbErr) { + console.log("WEA Tabelle fehlt oder nicht abrufbar."); + result = { rows: [], rowCount: 0 }; + } const geojson = { type: "FeatureCollection", @@ -155,18 +160,24 @@ app.get('/api/infrastructure', async (req, res) => { const client = await pool.connect(); try { await setSchema(client); - const result = await client.query(` - SELECT - *, - ST_AsGeoJSON(ST_Transform(ST_SetSRID(geom, 25832), 4326)) as geometry - FROM bw_scheddebrock."Infrastruktur" - `); + let result; + try { + result = await client.query(` + SELECT + *, + ST_AsGeoJSON(ST_Transform(geom, 4326)) as geometry + FROM bw_scheddebrock."Infrastruktur" + `); + } catch (dbErr) { + console.log("Infrastruktur Tabelle fehlt oder nicht abrufbar."); + result = { rows: [], rowCount: 0 }; + } const geojson = { type: "FeatureCollection", features: result.rows.map(row => { const { geometry, geom, ...properties } = row; - const geomObj = JSON.parse(geometry); + const geomObj = typeof geometry === 'string' ? JSON.parse(geometry) : (geometry || null); return { type: "Feature", geometry: geomObj,