Last active
December 25, 2019 19:12
-
-
Save dbauszus-glx/98f4160f08c11f5b30a4a1e8cf69cda3 to your computer and use it in GitHub Desktop.
Create an MVT with properties from PostGIS and store in MVT cache table.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INSERT INTO dev.natural_earth_countries__mvts (z, x, y, mvt, tile) | |
SELECT | |
5, | |
10, | |
13, | |
ST_AsMVT(tile, 'COUNTRIES', 4096, 'geom') mvt, | |
ST_MakeEnvelope( | |
${-m + (x * r)}, | |
${ m - (y * r)}, | |
${-m + (x * r) + r}, | |
${ m - (y * r) - r}, | |
3857 | |
) tile | |
FROM ( | |
SELECT | |
id id, | |
pop_est, | |
gdp_md_est, | |
gdp_md_est_edit :: NUMERIC / (pop_est_edit :: NUMERIC + 1) * 1000 AS gdp_pp, | |
(pop_est_edit / st_area(geom_3857)) * 1000 AS pop_dens, | |
ST_AsMVTGeom( | |
geom_3857, | |
ST_MakeEnvelope( | |
-7514065.6274999995, | |
3757032.8137500007, | |
-6261721.356249999, | |
2504688.5425000004, | |
3857 | |
), | |
4096, | |
256, | |
TRUE) geom | |
FROM dev.natural_earth_countries | |
WHERE | |
ST_DWithin( | |
ST_MakeEnvelope( | |
${-m + (x * r)}, | |
${ m - (y * r)}, | |
${-m + (x * r) + r}, | |
${ m - (y * r) - r}, | |
3857 | |
), | |
geom_3857, | |
${r/4} | |
) | |
) tile | |
RETURNING mvt; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment