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