Commit 27e7ce4c authored by Anne Blankert's avatar Anne Blankert

ignore null geometries

parent b45bb4cf
...@@ -24,7 +24,9 @@ let cacheMiddleWare = async(req, res, next) => { ...@@ -24,7 +24,9 @@ let cacheMiddleWare = async(req, res, next) => {
} else { } else {
res.sendResponse = res.send; res.sendResponse = res.send;
res.send = (body) => { res.send = (body) => {
cache.setCachedFile(cacheDir, key, body); if (res.statusCode >= 200 && res.statusCode < 300) {
cache.setCachedFile(cacheDir, key, body);
}
res.sendResponse(body); res.sendResponse(body);
} }
next(); next();
...@@ -35,33 +37,25 @@ const sql = (params, query) => { ...@@ -35,33 +37,25 @@ const sql = (params, query) => {
let bounds = merc.bbox(params.x, params.y, params.z, false, '900913') let bounds = merc.bbox(params.x, params.y, params.z, false, '900913')
return ` return `
SELECT SELECT ST_AsMVT(q, '${params.table}', 4096, 'geom')
ST_AsMVT(q, '${params.table}', 4096, 'geom') FROM
FROM ( (SELECT ${query.columns ? `${query.columns},` : ''}
SELECT
${query.columns ? `${query.columns},` : ''}
ST_AsMVTGeom( ST_AsMVTGeom(
ST_Transform(${query.geom_column}, 3857), ST_Transform(${query.geom_column}, 3857),
ST_MakeBox2D(ST_Point(${bounds[0]}, ${bounds[1]}), ST_Point(${ ST_MakeBox2D(ST_Point(${bounds[0]}, ${bounds[1]}), ST_Point(${bounds[2]}, ${bounds[3]}))
bounds[2]
}, ${bounds[3]}))
) geom ) geom
FROM ( FROM
SELECT (SELECT ${query.columns ? `${query.columns},` : ''} ${query.geom_column}, srid
${query.columns ? `${query.columns},` : ''} FROM
${query.geom_column}, ${sqlTableName(params.table)},
srid (SELECT ST_SRID(${query.geom_column}) AS srid FROM ${sqlTableName(params.table)}
FROM WHERE ${query.geom_column} is not null LIMIT 1) a
${sqlTableName(params.table)}, WHERE
(SELECT ST_SRID(${query.geom_column}) AS srid FROM ${ ${query.geom_column} is not null AND
sqlTableName(params.table) ST_transform(
} LIMIT 1) a ST_MakeEnvelope(${bounds.join()}, 3857),
WHERE srid
ST_transform( ) && ${query.geom_column}
ST_MakeEnvelope(${bounds.join()}, 3857),
srid
) &&
${query.geom_column}
-- Optional Filter -- Optional Filter
${query.filter ? `AND ${query.filter}` : ''} ${query.filter ? `AND ${query.filter}` : ''}
) r ) r
...@@ -136,15 +130,19 @@ module.exports = function(app, pool) { ...@@ -136,15 +130,19 @@ module.exports = function(app, pool) {
res.header('Content-Type', 'application/x-protobuf').send(mvt); res.header('Content-Type', 'application/x-protobuf').send(mvt);
} catch(err) { } catch(err) {
console.log(err); console.log(err);
let status = 500;
switch (err.code) { switch (err.code) {
case '42P01': case '42P01':
err.name = `table ${req.params.table} does not exist`; // table does not exist
break; status = 422;
case '42703': break;
err.name = `column does not exist`; case '42703':
break; // column does not exist
status = 422;
break;
default:
} }
res.status(422).json({error:err}) res.status(status).json({error:err.message})
} }
}) })
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment