Commit 3f99b45c authored by Anne Blankert's avatar Anne Blankert

guess geomtype from first non-null geom

parent 580141b7
......@@ -29,7 +29,7 @@ const sqlEstimateBbox = (params, query, estimatedRows) => {
const ts = splitTableName(params);
return `
with srid as
(select st_srid(${query.geom_column}) srid
(select st_srid(${query.geom_column}) srid, geometrytype(${query.geom_column}) geomtype
from ${sqlTableName(params.table)}
where ${query.geom_column} is not null limit 1)
,bboxsrid as
......@@ -37,7 +37,7 @@ const sqlEstimateBbox = (params, query, estimatedRows) => {
,bboxll as
(select st_extent(st_transform(st_setsrid(st_envelope(bboxsrid), srid),4326)) bboxll
from bboxsrid, srid)
select ${estimatedRows} as allrows, ${estimatedRows} as geomrows, bboxll,srid,bboxsrid
select ${estimatedRows} as allrows, ${estimatedRows} as geomrows,bboxll,srid,bboxsrid,geomtype
from bboxll,srid,bboxsrid
`;
}
......@@ -45,7 +45,7 @@ const sqlEstimateBbox = (params, query, estimatedRows) => {
const sqlBbox = (params, query) => {
return `
with srid as
(select st_srid(${query.geom_column}) srid
(select st_srid(${query.geom_column}) srid, geometrytype(${query.geom_column}) geomtype
from ${sqlTableName(params.table)}
where ${query.geom_column} is not null limit 1)
,bboxll as
......@@ -57,7 +57,7 @@ const sqlBbox = (params, query) => {
,bboxsrid as
(select st_extent(st_transform(st_setsrid(st_envelope(bboxll),4326),srid)) bboxsrid
from bboxll,srid)
select allrows, geomrows, bboxll,srid,bboxsrid
select allrows, geomrows, bboxll,srid,bboxsrid,geomtype
from bboxll,srid,bboxsrid
`;
}
......@@ -183,9 +183,10 @@ module.exports = function(app, pool, cache) {
res.json({
estimated: estimated,
allrows: Number(row.allrows),
geomtype: row.geomtype,
geomrows: Number(row.geomrows),
bboxll: row.bboxll?row.bboxll.match(/BOX\((.*)\)/)[1].split(',').map(coord=>coord.split(' ').map(c=>parseFloat(c))):null,
srid: row.srid,
bboxll: row.bboxll?row.bboxll.match(/BOX\((.*)\)/)[1].split(',').map(coord=>coord.split(' ').map(c=>parseFloat(c))):null,
bboxsrid: row.bboxsrid?row.bboxsrid.match(/BOX\((.*)\)/)[1].split(',').map(coord=>coord.split(' ').map(c=>parseFloat(c))):null
})
} else if (result.rows.length === 0) {
......
......@@ -7,11 +7,25 @@
<title>Info</title>
<script>
function addBboxllToLinks(bboxll)
function replaceGeomType(url, geomtype) {
if (geomtype) {
const parts = url.split('&')
.map(part=>{
if (part.startsWith('geomtype=')) {
part = `geomtype=${geomtype}`
}
return part;
})
url = parts.join('&');
}
return url;
}
function addBboxllToLinks(bboxll,geomtype)
{
if (bboxll) {
document.querySelectorAll('#columns > li > a')
.forEach(a=>(a.setAttribute('href', a.getAttribute('href') + '&bboxll='+JSON.stringify(bboxll))))
.forEach(a=>(a.setAttribute('href', replaceGeomType(a.getAttribute('href'),geomtype) + '&bboxll='+JSON.stringify(bboxll))))
}
}
......@@ -37,7 +51,7 @@
const bbox = document.querySelector('#bbox');
if (response.ok) {
response.json().then(json=> {
addBboxllToLinks(json.bboxll);
addBboxllToLinks(json.bboxll,json.geomtype);
bbox.innerHTML = `number of rows: ${json.allrows}<br>
number of geometries: ${json.geomrows}<br>
srid: EPSG:${json.srid}<br>
......
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