Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
fordecyt_2019
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Rodrigo Tapia-McClung
fordecyt_2019
Commits
14e30206
Commit
14e30206
authored
Aug 15, 2019
by
Anne Blankert
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bbox now returns json bbox for lat/lon,srid and row counts
parent
3cff1d76
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
10 deletions
+23
-10
bbox.js
bbox.js
+23
-10
No files found.
bbox.js
View file @
14e30206
...
...
@@ -4,16 +4,18 @@ const sqlTableName = require('./utils/sqltablename.js');
const
sql
=
(
params
,
query
)
=>
{
return
`
SELECT
ST_Extent(ST_Transform(
${
query
.
geom_column
}
,
${
query
.
srid
}
)) as bbox
FROM
${
sqlTableName
(
params
.
table
)}
return
`
with srid as
(select st_srid(
${
query
.
geom_column
}
) srid from
${
sqlTableName
(
params
.
table
)}
where
${
query
.
geom_column
}
is not null limit 1)
,bboxll as
(select ST_Extent(ST_Transform(
${
query
.
geom_column
}
, 4326)) as bboxll, count(*) allrows, count(
${
query
.
geom_column
}
) geomrows from
${
sqlTableName
(
params
.
table
)}
-- Optional where filter
${
query
.
filter
?
`WHERE
${
query
.
filter
}
`
:
''
}
`
)
,bboxsrid as
(select st_extent(st_transform(st_setsrid(st_envelope(bboxll),4326),srid)) bboxsrid from bboxll,srid)
select allrows, geomrows, bboxll,srid,bboxsrid from bboxll,srid,bboxsrid
`
}
module
.
exports
=
function
(
app
,
pool
)
{
...
...
@@ -64,10 +66,21 @@ module.exports = function(app, pool) {
const
sqlString
=
sql
(
req
.
params
,
req
.
query
);
try
{
const
result
=
await
pool
.
query
(
sqlString
);
res
.
json
(
result
.
rows
);
if
(
result
.
rows
.
length
===
1
)
{
const
row
=
result
.
rows
[
0
];
res
.
json
({
allrows
:
Number
(
row
.
allrows
),
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
,
bboxsrid
:
row
.
bboxsrid
?
row
.
bboxsrid
.
match
(
/BOX
\((
.*
)\)
/
)[
1
].
split
(
','
).
map
(
coord
=>
coord
.
split
(
' '
).
map
(
c
=>
parseFloat
(
c
))):
null
})
}
else
{
throw
(
new
Error
(
'bbox query did not return 1 row'
));
}
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
status
(
500
).
json
({
error
:
err
});
res
.
status
(
500
).
json
({
error
:
err
.
message
});
}
})
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment