Skip to content

Commit

Permalink
Bug fix tile_to_bbox(): use pixel_width instead of extent. (#333)
Browse files Browse the repository at this point in the history
When PgQuery makes a query into postgres it uses smaller tile buffer than Mapnik.
In example below layer `place` has a `buffer_size` set to 256.

Example: 
Queried tile: 7/69/43
Queried layer: `layer_place`
Green: bbox of tile
Purple: bbox of PgQuery query of `layer_place` before bug fix
Blue dash: bbox of PgQuery query of `layer_place` after bug fix
Red dot dash: bbox of Mapnik query of `layer_place`
Blue: 
![image](https://user-images.githubusercontent.com/19833762/97620293-a9350800-1a21-11eb-9c85-0488539d2b82.png)
  • Loading branch information
lazaa32 authored Oct 30, 2020
1 parent 5bb5ea0 commit c0cb6df
Show file tree
Hide file tree
Showing 17 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions openmaptiles/sqltomvt.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ def tile_to_bbox(self, layer: Layer, zoom, x, y):
# Every subsequent zoom divides it by 2
if layer.buffer_size > 0:
if not self.tile_envelope_margin:
percentage = 40075016.6855785 * layer.buffer_size / self.extent
percentage = 40075016.6855785 * layer.buffer_size / self.pixel_width
return f"ST_Expand({self.bbox(zoom, x, y)}, {percentage}/2^{zoom})"
else:
# Once https://github.com/postgis/postgis/pull/514 is merged
return self.bbox(zoom, x, y, float(layer.buffer_size) / self.extent)
return self.bbox(zoom, x, y, float(layer.buffer_size) / self.pixel_width)
else:
return self.bbox(zoom, x, y)

Expand Down
2 changes: 1 addition & 1 deletion tests/expected/mvttile_func.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ DROP FUNCTION IF EXISTS gettile(integer, integer, integer);
CREATE FUNCTION gettile(zoom integer, x integer, y integer)
RETURNS bytea AS $$
SELECT STRING_AGG(mvtl, '') AS mvt FROM (
SELECT COALESCE(ST_AsMVT(t, 'housenumber', 4096, 'mvtgeometry'), '') as mvtl FROM (SELECT ST_Expand(ST_TileEnvelope(zoom, x, y), 78271.51696402051/2^zoom) as ST_AsMVTGeom(geometry, ST_TileEnvelope(zoom, x, y), 4096, 8, true) AS mvtgeometry, zoom AS housenumber, NULLIF(tags->'name:en', '') AS "name:en", NULLIF(tags->'name:de', '') AS "name:de", NULLIF(tags->'name:cs', '') AS "name:cs", NULLIF(tags->'name_int', '') AS "name_int", NULLIF(tags->'name:latin', '') AS "name:latin", NULLIF(tags->'name:nonlatin', '') AS "name:nonlatin" FROM (SELECT 'name:en=>"enname"'::hstore as tags) AS tt) AS t
SELECT COALESCE(ST_AsMVT(t, 'housenumber', 4096, 'mvtgeometry'), '') as mvtl FROM (SELECT ST_Expand(ST_TileEnvelope(zoom, x, y), 1252344.2714243282/2^zoom) as ST_AsMVTGeom(geometry, ST_TileEnvelope(zoom, x, y), 4096, 8, true) AS mvtgeometry, zoom AS housenumber, NULLIF(tags->'name:en', '') AS "name:en", NULLIF(tags->'name:de', '') AS "name:de", NULLIF(tags->'name:cs', '') AS "name:cs", NULLIF(tags->'name_int', '') AS "name_int", NULLIF(tags->'name:latin', '') AS "name:latin", NULLIF(tags->'name:nonlatin', '') AS "name:nonlatin" FROM (SELECT 'name:en=>"enname"'::hstore as tags) AS tt) AS t
UNION ALL
SELECT COALESCE(ST_AsMVT(t, 'enumfield', 4096, 'mvtgeometry', 'osm_id'), '') as mvtl FROM (SELECT ST_TileEnvelope(zoom, x, y) as ST_AsMVTGeom(geometry, ST_TileEnvelope(zoom, x, y), 4096, 0, true) AS mvtgeometry, zoom AS osm_id, 'foo' AS class) AS t
) AS all_layers
Expand Down
2 changes: 1 addition & 1 deletion tests/expected/mvttile_func_key.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ DROP FUNCTION IF EXISTS gettile(integer, integer, integer);
CREATE FUNCTION gettile(zoom integer, x integer, y integer)
RETURNS TABLE(mvt bytea, key text) AS $$
SELECT mvt, md5(mvt) AS key FROM (SELECT STRING_AGG(mvtl, '') AS mvt FROM (
SELECT COALESCE(ST_AsMVT(t, 'housenumber', 4096, 'mvtgeometry'), '') as mvtl FROM (SELECT ST_Expand(ST_TileEnvelope(zoom, x, y), 78271.51696402051/2^zoom) as ST_AsMVTGeom(geometry, ST_TileEnvelope(zoom, x, y), 4096, 8, true) AS mvtgeometry, zoom AS housenumber, NULLIF(tags->'name:en', '') AS "name:en", NULLIF(tags->'name:de', '') AS "name:de", NULLIF(tags->'name:cs', '') AS "name:cs", NULLIF(tags->'name_int', '') AS "name_int", NULLIF(tags->'name:latin', '') AS "name:latin", NULLIF(tags->'name:nonlatin', '') AS "name:nonlatin" FROM (SELECT 'name:en=>"enname"'::hstore as tags) AS tt) AS t
SELECT COALESCE(ST_AsMVT(t, 'housenumber', 4096, 'mvtgeometry'), '') as mvtl FROM (SELECT ST_Expand(ST_TileEnvelope(zoom, x, y), 1252344.2714243282/2^zoom) as ST_AsMVTGeom(geometry, ST_TileEnvelope(zoom, x, y), 4096, 8, true) AS mvtgeometry, zoom AS housenumber, NULLIF(tags->'name:en', '') AS "name:en", NULLIF(tags->'name:de', '') AS "name:de", NULLIF(tags->'name:cs', '') AS "name:cs", NULLIF(tags->'name_int', '') AS "name_int", NULLIF(tags->'name:latin', '') AS "name:latin", NULLIF(tags->'name:nonlatin', '') AS "name:nonlatin" FROM (SELECT 'name:en=>"enname"'::hstore as tags) AS tt) AS t
UNION ALL
SELECT COALESCE(ST_AsMVT(t, 'enumfield', 4096, 'mvtgeometry', 'osm_id'), '') as mvtl FROM (SELECT ST_TileEnvelope(zoom, x, y) as ST_AsMVTGeom(geometry, ST_TileEnvelope(zoom, x, y), 4096, 0, true) AS mvtgeometry, zoom AS osm_id, 'foo' AS class) AS t
) AS all_layers) AS mvt_data
Expand Down
2 changes: 1 addition & 1 deletion tests/expected/mvttile_prep.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ END $$;
-- Run this statement with EXECUTE gettile(zoom, x, y)
PREPARE gettile(integer, integer, integer) AS
SELECT STRING_AGG(mvtl, '') AS mvt FROM (
SELECT COALESCE(ST_AsMVT(t, 'housenumber', 4096, 'mvtgeometry'), '') as mvtl FROM (SELECT ST_Expand(ST_TileEnvelope($1, $2, $3), 78271.51696402051/2^$1) as ST_AsMVTGeom(geometry, ST_TileEnvelope($1, $2, $3), 4096, 8, true) AS mvtgeometry, $1 AS housenumber, NULLIF(tags->'name:en', '') AS "name:en", NULLIF(tags->'name:de', '') AS "name:de", NULLIF(tags->'name:cs', '') AS "name:cs", NULLIF(tags->'name_int', '') AS "name_int", NULLIF(tags->'name:latin', '') AS "name:latin", NULLIF(tags->'name:nonlatin', '') AS "name:nonlatin" FROM (SELECT 'name:en=>"enname"'::hstore as tags) AS tt) AS t
SELECT COALESCE(ST_AsMVT(t, 'housenumber', 4096, 'mvtgeometry'), '') as mvtl FROM (SELECT ST_Expand(ST_TileEnvelope($1, $2, $3), 1252344.2714243282/2^$1) as ST_AsMVTGeom(geometry, ST_TileEnvelope($1, $2, $3), 4096, 8, true) AS mvtgeometry, $1 AS housenumber, NULLIF(tags->'name:en', '') AS "name:en", NULLIF(tags->'name:de', '') AS "name:de", NULLIF(tags->'name:cs', '') AS "name:cs", NULLIF(tags->'name_int', '') AS "name_int", NULLIF(tags->'name:latin', '') AS "name:latin", NULLIF(tags->'name:nonlatin', '') AS "name:nonlatin" FROM (SELECT 'name:en=>"enname"'::hstore as tags) AS tt) AS t
UNION ALL
SELECT COALESCE(ST_AsMVT(t, 'enumfield', 4096, 'mvtgeometry', 'osm_id'), '') as mvtl FROM (SELECT ST_TileEnvelope($1, $2, $3) as ST_AsMVTGeom(geometry, ST_TileEnvelope($1, $2, $3), 4096, 0, true) AS mvtgeometry, $1 AS osm_id, 'foo' AS class) AS t
) AS all_layers
Expand Down
2 changes: 1 addition & 1 deletion tests/expected/mvttile_psql.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SELECT STRING_AGG(mvtl, '') AS mvt FROM (
SELECT COALESCE(ST_AsMVT(t, 'housenumber', 4096, 'mvtgeometry'), '') as mvtl FROM (SELECT ST_Expand(ST_TileEnvelope(:zoom, :x, :y), 78271.51696402051/2^:zoom) as ST_AsMVTGeom(geometry, ST_TileEnvelope(:zoom, :x, :y), 4096, 8, true) AS mvtgeometry, :zoom AS housenumber, NULLIF(tags->'name:en', '') AS "name:en", NULLIF(tags->'name:de', '') AS "name:de", NULLIF(tags->'name:cs', '') AS "name:cs", NULLIF(tags->'name_int', '') AS "name_int", NULLIF(tags->'name:latin', '') AS "name:latin", NULLIF(tags->'name:nonlatin', '') AS "name:nonlatin" FROM (SELECT 'name:en=>"enname"'::hstore as tags) AS tt) AS t
SELECT COALESCE(ST_AsMVT(t, 'housenumber', 4096, 'mvtgeometry'), '') as mvtl FROM (SELECT ST_Expand(ST_TileEnvelope(:zoom, :x, :y), 1252344.2714243282/2^:zoom) as ST_AsMVTGeom(geometry, ST_TileEnvelope(:zoom, :x, :y), 4096, 8, true) AS mvtgeometry, :zoom AS housenumber, NULLIF(tags->'name:en', '') AS "name:en", NULLIF(tags->'name:de', '') AS "name:de", NULLIF(tags->'name:cs', '') AS "name:cs", NULLIF(tags->'name_int', '') AS "name_int", NULLIF(tags->'name:latin', '') AS "name:latin", NULLIF(tags->'name:nonlatin', '') AS "name:nonlatin" FROM (SELECT 'name:en=>"enname"'::hstore as tags) AS tt) AS t
UNION ALL
SELECT COALESCE(ST_AsMVT(t, 'enumfield', 4096, 'mvtgeometry', 'osm_id'), '') as mvtl FROM (SELECT ST_TileEnvelope(:zoom, :x, :y) as ST_AsMVTGeom(geometry, ST_TileEnvelope(:zoom, :x, :y), 4096, 0, true) AS mvtgeometry, :zoom AS osm_id, 'foo' AS class) AS t
) AS all_layers
Expand Down
2 changes: 1 addition & 1 deletion tests/expected/mvttile_query.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SELECT STRING_AGG(mvtl, '') AS mvt FROM (
SELECT COALESCE(ST_AsMVT(t, 'housenumber', 4096, 'mvtgeometry'), '') as mvtl FROM (SELECT ST_Expand(ST_TileEnvelope($1, $2, $3), 78271.51696402051/2^$1) as ST_AsMVTGeom(geometry, ST_TileEnvelope($1, $2, $3), 4096, 8, true) AS mvtgeometry, $1 AS housenumber, NULLIF(tags->'name:en', '') AS "name:en", NULLIF(tags->'name:de', '') AS "name:de", NULLIF(tags->'name:cs', '') AS "name:cs", NULLIF(tags->'name_int', '') AS "name_int", NULLIF(tags->'name:latin', '') AS "name:latin", NULLIF(tags->'name:nonlatin', '') AS "name:nonlatin" FROM (SELECT 'name:en=>"enname"'::hstore as tags) AS tt) AS t
SELECT COALESCE(ST_AsMVT(t, 'housenumber', 4096, 'mvtgeometry'), '') as mvtl FROM (SELECT ST_Expand(ST_TileEnvelope($1, $2, $3), 1252344.2714243282/2^$1) as ST_AsMVTGeom(geometry, ST_TileEnvelope($1, $2, $3), 4096, 8, true) AS mvtgeometry, $1 AS housenumber, NULLIF(tags->'name:en', '') AS "name:en", NULLIF(tags->'name:de', '') AS "name:de", NULLIF(tags->'name:cs', '') AS "name:cs", NULLIF(tags->'name_int', '') AS "name_int", NULLIF(tags->'name:latin', '') AS "name:latin", NULLIF(tags->'name:nonlatin', '') AS "name:nonlatin" FROM (SELECT 'name:en=>"enname"'::hstore as tags) AS tt) AS t
UNION ALL
SELECT COALESCE(ST_AsMVT(t, 'enumfield', 4096, 'mvtgeometry', 'osm_id'), '') as mvtl FROM (SELECT ST_TileEnvelope($1, $2, $3) as ST_AsMVTGeom(geometry, ST_TileEnvelope($1, $2, $3), 4096, 0, true) AS mvtgeometry, $1 AS osm_id, 'foo' AS class) AS t
) AS all_layers
Expand Down
2 changes: 1 addition & 1 deletion tests/expected/mvttile_query_gzip.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SELECT GZIP(STRING_AGG(mvtl, '')) AS mvt FROM (
SELECT COALESCE(ST_AsMVT(t, 'housenumber', 4096, 'mvtgeometry'), '') as mvtl FROM (SELECT ST_Expand(ST_TileEnvelope($1, $2, $3), 78271.51696402051/2^$1) as ST_AsMVTGeom(geometry, ST_TileEnvelope($1, $2, $3), 4096, 8, true) AS mvtgeometry, $1 AS housenumber, NULLIF(tags->'name:en', '') AS "name:en", NULLIF(tags->'name:de', '') AS "name:de", NULLIF(tags->'name:cs', '') AS "name:cs", NULLIF(tags->'name_int', '') AS "name_int", NULLIF(tags->'name:latin', '') AS "name:latin", NULLIF(tags->'name:nonlatin', '') AS "name:nonlatin" FROM (SELECT 'name:en=>"enname"'::hstore as tags) AS tt) AS t
SELECT COALESCE(ST_AsMVT(t, 'housenumber', 4096, 'mvtgeometry'), '') as mvtl FROM (SELECT ST_Expand(ST_TileEnvelope($1, $2, $3), 1252344.2714243282/2^$1) as ST_AsMVTGeom(geometry, ST_TileEnvelope($1, $2, $3), 4096, 8, true) AS mvtgeometry, $1 AS housenumber, NULLIF(tags->'name:en', '') AS "name:en", NULLIF(tags->'name:de', '') AS "name:de", NULLIF(tags->'name:cs', '') AS "name:cs", NULLIF(tags->'name_int', '') AS "name_int", NULLIF(tags->'name:latin', '') AS "name:latin", NULLIF(tags->'name:nonlatin', '') AS "name:nonlatin" FROM (SELECT 'name:en=>"enname"'::hstore as tags) AS tt) AS t
UNION ALL
SELECT COALESCE(ST_AsMVT(t, 'enumfield', 4096, 'mvtgeometry', 'osm_id'), '') as mvtl FROM (SELECT ST_TileEnvelope($1, $2, $3) as ST_AsMVTGeom(geometry, ST_TileEnvelope($1, $2, $3), 4096, 0, true) AS mvtgeometry, $1 AS osm_id, 'foo' AS class) AS t
) AS all_layers
Expand Down
2 changes: 1 addition & 1 deletion tests/expected/mvttile_query_gzip9.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SELECT GZIP(STRING_AGG(mvtl, ''), 9) AS mvt FROM (
SELECT COALESCE(ST_AsMVT(t, 'housenumber', 4096, 'mvtgeometry'), '') as mvtl FROM (SELECT ST_Expand(ST_TileEnvelope($1, $2, $3), 78271.51696402051/2^$1) as ST_AsMVTGeom(geometry, ST_TileEnvelope($1, $2, $3), 4096, 8, true) AS mvtgeometry, $1 AS housenumber, NULLIF(tags->'name:en', '') AS "name:en", NULLIF(tags->'name:de', '') AS "name:de", NULLIF(tags->'name:cs', '') AS "name:cs", NULLIF(tags->'name_int', '') AS "name_int", NULLIF(tags->'name:latin', '') AS "name:latin", NULLIF(tags->'name:nonlatin', '') AS "name:nonlatin" FROM (SELECT 'name:en=>"enname"'::hstore as tags) AS tt) AS t
SELECT COALESCE(ST_AsMVT(t, 'housenumber', 4096, 'mvtgeometry'), '') as mvtl FROM (SELECT ST_Expand(ST_TileEnvelope($1, $2, $3), 1252344.2714243282/2^$1) as ST_AsMVTGeom(geometry, ST_TileEnvelope($1, $2, $3), 4096, 8, true) AS mvtgeometry, $1 AS housenumber, NULLIF(tags->'name:en', '') AS "name:en", NULLIF(tags->'name:de', '') AS "name:de", NULLIF(tags->'name:cs', '') AS "name:cs", NULLIF(tags->'name_int', '') AS "name_int", NULLIF(tags->'name:latin', '') AS "name:latin", NULLIF(tags->'name:nonlatin', '') AS "name:nonlatin" FROM (SELECT 'name:en=>"enname"'::hstore as tags) AS tt) AS t
UNION ALL
SELECT COALESCE(ST_AsMVT(t, 'enumfield', 4096, 'mvtgeometry', 'osm_id'), '') as mvtl FROM (SELECT ST_TileEnvelope($1, $2, $3) as ST_AsMVTGeom(geometry, ST_TileEnvelope($1, $2, $3), 4096, 0, true) AS mvtgeometry, $1 AS osm_id, 'foo' AS class) AS t
) AS all_layers
Expand Down
2 changes: 1 addition & 1 deletion tests/expected/mvttile_query_no_feat_ids.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SELECT STRING_AGG(mvtl, '') AS mvt FROM (
SELECT COALESCE(ST_AsMVT(t, 'housenumber', 4096, 'mvtgeometry'), '') as mvtl FROM (SELECT ST_Expand(ST_TileEnvelope($1, $2, $3), 78271.51696402051/2^$1) as ST_AsMVTGeom(geometry, ST_TileEnvelope($1, $2, $3), 4096, 8, true) AS mvtgeometry, $1 AS housenumber, NULLIF(tags->'name:en', '') AS "name:en", NULLIF(tags->'name:de', '') AS "name:de", NULLIF(tags->'name:cs', '') AS "name:cs", NULLIF(tags->'name_int', '') AS "name_int", NULLIF(tags->'name:latin', '') AS "name:latin", NULLIF(tags->'name:nonlatin', '') AS "name:nonlatin" FROM (SELECT 'name:en=>"enname"'::hstore as tags) AS tt) AS t
SELECT COALESCE(ST_AsMVT(t, 'housenumber', 4096, 'mvtgeometry'), '') as mvtl FROM (SELECT ST_Expand(ST_TileEnvelope($1, $2, $3), 1252344.2714243282/2^$1) as ST_AsMVTGeom(geometry, ST_TileEnvelope($1, $2, $3), 4096, 8, true) AS mvtgeometry, $1 AS housenumber, NULLIF(tags->'name:en', '') AS "name:en", NULLIF(tags->'name:de', '') AS "name:de", NULLIF(tags->'name:cs', '') AS "name:cs", NULLIF(tags->'name_int', '') AS "name_int", NULLIF(tags->'name:latin', '') AS "name:latin", NULLIF(tags->'name:nonlatin', '') AS "name:nonlatin" FROM (SELECT 'name:en=>"enname"'::hstore as tags) AS tt) AS t
UNION ALL
SELECT COALESCE(ST_AsMVT(t, 'enumfield', 4096, 'mvtgeometry'), '') as mvtl FROM (SELECT ST_TileEnvelope($1, $2, $3) as ST_AsMVTGeom(geometry, ST_TileEnvelope($1, $2, $3), 4096, 0, true) AS mvtgeometry, $1 AS osm_id, 'foo' AS class) AS t
) AS all_layers
Expand Down
2 changes: 1 addition & 1 deletion tests/expected/mvttile_query_test_geom.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SELECT STRING_AGG(mvtl, '') AS mvt, SUM(COALESCE(_bad_geos_, 0)) as _bad_geos_ FROM (
SELECT COALESCE(ST_AsMVT(t, 'housenumber', 4096, 'mvtgeometry'), '') as mvtl, SUM((1-COALESCE(ST_IsValid(mvtgeometry)::int, 1))+COALESCE(_bad_geos_, 0)) as _bad_geos_ FROM (SELECT ST_Expand(ST_TileEnvelope($1, $2, $3), 78271.51696402051/2^$1) as ST_AsMVTGeom(geometry, ST_TileEnvelope($1, $2, $3), 4096, 8, true) AS mvtgeometry, (1-ST_IsValid(geometry)::int) as _bad_geos_, $1 AS housenumber, NULLIF(tags->'name:en', '') AS "name:en", NULLIF(tags->'name:de', '') AS "name:de", NULLIF(tags->'name:cs', '') AS "name:cs", NULLIF(tags->'name_int', '') AS "name_int", NULLIF(tags->'name:latin', '') AS "name:latin", NULLIF(tags->'name:nonlatin', '') AS "name:nonlatin" FROM (SELECT 'name:en=>"enname"'::hstore as tags) AS tt) AS t
SELECT COALESCE(ST_AsMVT(t, 'housenumber', 4096, 'mvtgeometry'), '') as mvtl, SUM((1-COALESCE(ST_IsValid(mvtgeometry)::int, 1))+COALESCE(_bad_geos_, 0)) as _bad_geos_ FROM (SELECT ST_Expand(ST_TileEnvelope($1, $2, $3), 1252344.2714243282/2^$1) as ST_AsMVTGeom(geometry, ST_TileEnvelope($1, $2, $3), 4096, 8, true) AS mvtgeometry, (1-ST_IsValid(geometry)::int) as _bad_geos_, $1 AS housenumber, NULLIF(tags->'name:en', '') AS "name:en", NULLIF(tags->'name:de', '') AS "name:de", NULLIF(tags->'name:cs', '') AS "name:cs", NULLIF(tags->'name_int', '') AS "name_int", NULLIF(tags->'name:latin', '') AS "name:latin", NULLIF(tags->'name:nonlatin', '') AS "name:nonlatin" FROM (SELECT 'name:en=>"enname"'::hstore as tags) AS tt) AS t
UNION ALL
SELECT COALESCE(ST_AsMVT(t, 'enumfield', 4096, 'mvtgeometry', 'osm_id'), '') as mvtl, SUM((1-COALESCE(ST_IsValid(mvtgeometry)::int, 1))+COALESCE(_bad_geos_, 0)) as _bad_geos_ FROM (SELECT ST_TileEnvelope($1, $2, $3) as ST_AsMVTGeom(geometry, ST_TileEnvelope($1, $2, $3), 4096, 0, true) AS mvtgeometry, (1-ST_IsValid(geometry)::int) as _bad_geos_, $1 AS osm_id, 'foo' AS class) AS t
) AS all_layers
Expand Down
2 changes: 1 addition & 1 deletion tests/expected/mvttile_query_test_geom_key.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SELECT mvt, md5(mvt) AS key, _bad_geos_ FROM (SELECT STRING_AGG(mvtl, '') AS mvt, SUM(COALESCE(_bad_geos_, 0)) as _bad_geos_ FROM (
SELECT COALESCE(ST_AsMVT(t, 'housenumber', 4096, 'mvtgeometry'), '') as mvtl, SUM((1-COALESCE(ST_IsValid(mvtgeometry)::int, 1))+COALESCE(_bad_geos_, 0)) as _bad_geos_ FROM (SELECT ST_Expand(ST_TileEnvelope($1, $2, $3), 78271.51696402051/2^$1) as ST_AsMVTGeom(geometry, ST_TileEnvelope($1, $2, $3), 4096, 8, true) AS mvtgeometry, (1-ST_IsValid(geometry)::int) as _bad_geos_, $1 AS housenumber, NULLIF(tags->'name:en', '') AS "name:en", NULLIF(tags->'name:de', '') AS "name:de", NULLIF(tags->'name:cs', '') AS "name:cs", NULLIF(tags->'name_int', '') AS "name_int", NULLIF(tags->'name:latin', '') AS "name:latin", NULLIF(tags->'name:nonlatin', '') AS "name:nonlatin" FROM (SELECT 'name:en=>"enname"'::hstore as tags) AS tt) AS t
SELECT COALESCE(ST_AsMVT(t, 'housenumber', 4096, 'mvtgeometry'), '') as mvtl, SUM((1-COALESCE(ST_IsValid(mvtgeometry)::int, 1))+COALESCE(_bad_geos_, 0)) as _bad_geos_ FROM (SELECT ST_Expand(ST_TileEnvelope($1, $2, $3), 1252344.2714243282/2^$1) as ST_AsMVTGeom(geometry, ST_TileEnvelope($1, $2, $3), 4096, 8, true) AS mvtgeometry, (1-ST_IsValid(geometry)::int) as _bad_geos_, $1 AS housenumber, NULLIF(tags->'name:en', '') AS "name:en", NULLIF(tags->'name:de', '') AS "name:de", NULLIF(tags->'name:cs', '') AS "name:cs", NULLIF(tags->'name_int', '') AS "name_int", NULLIF(tags->'name:latin', '') AS "name:latin", NULLIF(tags->'name:nonlatin', '') AS "name:nonlatin" FROM (SELECT 'name:en=>"enname"'::hstore as tags) AS tt) AS t
UNION ALL
SELECT COALESCE(ST_AsMVT(t, 'enumfield', 4096, 'mvtgeometry', 'osm_id'), '') as mvtl, SUM((1-COALESCE(ST_IsValid(mvtgeometry)::int, 1))+COALESCE(_bad_geos_, 0)) as _bad_geos_ FROM (SELECT ST_TileEnvelope($1, $2, $3) as ST_AsMVTGeom(geometry, ST_TileEnvelope($1, $2, $3), 4096, 0, true) AS mvtgeometry, (1-ST_IsValid(geometry)::int) as _bad_geos_, $1 AS osm_id, 'foo' AS class) AS t
) AS all_layers) AS mvt_data
Expand Down
2 changes: 1 addition & 1 deletion tests/expected/mvttile_query_v2.4.0dev-a.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SELECT STRING_AGG(mvtl, '') AS mvt FROM (
SELECT COALESCE(ST_AsMVT('housenumber', 4096, 'mvtgeometry', t), '') as mvtl FROM (SELECT ST_Expand(TileBBox($1, $2, $3), 78271.51696402051/2^$1) as ST_AsMVTGeom(geometry, TileBBox($1, $2, $3), 4096, 8, true) AS mvtgeometry, $1 AS housenumber, NULLIF(tags->'name:en', '') AS "name:en", NULLIF(tags->'name:de', '') AS "name:de", NULLIF(tags->'name:cs', '') AS "name:cs", NULLIF(tags->'name_int', '') AS "name_int", NULLIF(tags->'name:latin', '') AS "name:latin", NULLIF(tags->'name:nonlatin', '') AS "name:nonlatin" FROM (SELECT 'name:en=>"enname"'::hstore as tags) AS tt) AS t WHERE mvtgeometry IS NOT NULL
SELECT COALESCE(ST_AsMVT('housenumber', 4096, 'mvtgeometry', t), '') as mvtl FROM (SELECT ST_Expand(TileBBox($1, $2, $3), 1252344.2714243282/2^$1) as ST_AsMVTGeom(geometry, TileBBox($1, $2, $3), 4096, 8, true) AS mvtgeometry, $1 AS housenumber, NULLIF(tags->'name:en', '') AS "name:en", NULLIF(tags->'name:de', '') AS "name:de", NULLIF(tags->'name:cs', '') AS "name:cs", NULLIF(tags->'name_int', '') AS "name_int", NULLIF(tags->'name:latin', '') AS "name:latin", NULLIF(tags->'name:nonlatin', '') AS "name:nonlatin" FROM (SELECT 'name:en=>"enname"'::hstore as tags) AS tt) AS t WHERE mvtgeometry IS NOT NULL
UNION ALL
SELECT COALESCE(ST_AsMVT('enumfield', 4096, 'mvtgeometry', t), '') as mvtl FROM (SELECT TileBBox($1, $2, $3) as ST_AsMVTGeom(geometry, TileBBox($1, $2, $3), 4096, 0, true) AS mvtgeometry, $1 AS osm_id, 'foo' AS class) AS t WHERE mvtgeometry IS NOT NULL
) AS all_layers
Expand Down
Loading

0 comments on commit c0cb6df

Please sign in to comment.