Skip to content

Instantly share code, notes, and snippets.

@dbauszus-glx
Created March 7, 2020 17:15
Show Gist options
  • Select an option

  • Save dbauszus-glx/282fdd658ef79439844a5b42c10a6e5e to your computer and use it in GitHub Desktop.

Select an option

Save dbauszus-glx/282fdd658ef79439844a5b42c10a6e5e to your computer and use it in GitHub Desktop.
const auth = require('../../mod/auth/handler')({
public: true
})
const dbs = require('../../mod/pg/dbs')()
const _layers = require('../../mod/workspace/layers')
const layers = []
module.exports = async (req, res) => {
await auth(req, res)
Object.assign(layers, [], await _layers(req, res))
if (res.finished) return
const layer = layers[req.params.layer]
var q = `
SELECT
${layer.qID || null} AS id,
ST_asGeoJson(${layer.geom}) AS geomj
FROM ${req.query.table};`
var rows = await dbs[layer.dbs](q)
if (rows instanceof Error) return res.status(500).send('Failed to query PostGIS table.')
res.send(rows.map(row => ({
type: 'Feature',
geometry: JSON.parse(row.geomj),
properties: {
id: row.id
}
})))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment