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
27e7ce4c
Commit
27e7ce4c
authored
Aug 15, 2019
by
Anne Blankert
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ignore null geometries
parent
b45bb4cf
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
32 deletions
+30
-32
mvt.js
mvt.js
+30
-32
No files found.
mvt.js
View file @
27e7ce4c
...
...
@@ -24,7 +24,9 @@ let cacheMiddleWare = async(req, res, next) => {
}
else
{
res
.
sendResponse
=
res
.
send
;
res
.
send
=
(
body
)
=>
{
if
(
res
.
statusCode
>=
200
&&
res
.
statusCode
<
300
)
{
cache
.
setCachedFile
(
cacheDir
,
key
,
body
);
}
res
.
sendResponse
(
body
);
}
next
();
...
...
@@ -35,33 +37,25 @@ const sql = (params, query) => {
let
bounds
=
merc
.
bbox
(
params
.
x
,
params
.
y
,
params
.
z
,
false
,
'900913'
)
return
`
SELECT
ST_AsMVT(q, '
${
params
.
table
}
', 4096, 'geom')
FROM (
SELECT
${
query
.
columns
?
`
${
query
.
columns
}
,`
:
''
}
SELECT ST_AsMVT(q, '
${
params
.
table
}
', 4096, 'geom')
FROM
(SELECT
${
query
.
columns
?
`
${
query
.
columns
}
,`
:
''
}
ST_AsMVTGeom(
ST_Transform(
${
query
.
geom_column
}
, 3857),
ST_MakeBox2D(ST_Point(
${
bounds
[
0
]}
,
${
bounds
[
1
]}
), ST_Point(
${
bounds
[
2
]
}
,
${
bounds
[
3
]}
))
ST_MakeBox2D(ST_Point(
${
bounds
[
0
]}
,
${
bounds
[
1
]}
), ST_Point(
${
bounds
[
2
]}
,
${
bounds
[
3
]}
))
) geom
FROM (
SELECT
${
query
.
columns
?
`
${
query
.
columns
}
,`
:
''
}
${
query
.
geom_column
}
,
srid
FROM
(SELECT
${
query
.
columns
?
`
${
query
.
columns
}
,`
:
''
}
${
query
.
geom_column
}
, srid
FROM
${
sqlTableName
(
params
.
table
)}
,
(SELECT ST_SRID(
${
query
.
geom_column
}
) AS srid FROM
${
sqlTableName
(
params
.
table
)
}
LIMIT 1) a
(SELECT ST_SRID(
${
query
.
geom_column
}
) AS srid FROM
${
sqlTableName
(
params
.
table
)}
WHERE
${
query
.
geom_column
}
is not null LIMIT 1) a
WHERE
${
query
.
geom_column
}
is not null AND
ST_transform(
ST_MakeEnvelope(
${
bounds
.
join
()}
, 3857),
srid
) &&
${
query
.
geom_column
}
) &&
${
query
.
geom_column
}
-- Optional Filter
${
query
.
filter
?
`AND
${
query
.
filter
}
`
:
''
}
) r
...
...
@@ -136,15 +130,19 @@ module.exports = function(app, pool) {
res
.
header
(
'Content-Type'
,
'application/x-protobuf'
).
send
(
mvt
);
}
catch
(
err
)
{
console
.
log
(
err
);
let
status
=
500
;
switch
(
err
.
code
)
{
case
'42P01'
:
err
.
name
=
`table
${
req
.
params
.
table
}
does not exist`
;
// table does not exist
status
=
422
;
break
;
case
'42703'
:
err
.
name
=
`column does not exist`
;
// 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
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