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
Show 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
...
@@ -5,14 +5,16 @@ const sqlTableName = require('./utils/sqltablename.js');
...
@@ -5,14 +5,16 @@ const sqlTableName = require('./utils/sqltablename.js');
const
sql
=
(
params
,
query
)
=>
{
const
sql
=
(
params
,
query
)
=>
{
return
`
return
`
SELECT
with srid as
ST_Extent(ST_Transform(
${
query
.
geom_column
}
,
${
query
.
srid
}
)) as bbox
(select st_srid(
${
query
.
geom_column
}
) srid from
${
sqlTableName
(
params
.
table
)}
where
${
query
.
geom_column
}
is not null limit 1)
,bboxll as
FROM
(select ST_Extent(ST_Transform(
${
query
.
geom_column
}
, 4326)) as bboxll, count(*) allrows, count(
${
query
.
geom_column
}
) geomrows from
${
sqlTableName
(
params
.
table
)}
${
sqlTableName
(
params
.
table
)}
-- Optional where filter
-- Optional where filter
${
query
.
filter
?
`WHERE
${
query
.
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
`
`
}
}
...
@@ -64,10 +66,21 @@ module.exports = function(app, pool) {
...
@@ -64,10 +66,21 @@ module.exports = function(app, pool) {
const
sqlString
=
sql
(
req
.
params
,
req
.
query
);
const
sqlString
=
sql
(
req
.
params
,
req
.
query
);
try
{
try
{
const
result
=
await
pool
.
query
(
sqlString
);
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
)
{
}
catch
(
err
)
{
console
.
log
(
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