Limit the maximum overview level to 23

Fixes #257

23 = 32 bits per integer - 1 sign bit - 8 bits px/tile
This commit is contained in:
Javier Goizueta
2016-05-24 18:18:58 +02:00
parent f5f59be5b0
commit 86e5f6d317
+10 -2
View File
@@ -1,3 +1,11 @@
CREATE OR REPLACE FUNCTION _CDB_MaxOverviewLevel()
RETURNS INTEGER
AS $$
BEGIN
RETURN 23;
END;
$$ LANGUAGE PLPGSQL IMMUTABLE;
-- Information about tables in a schema. -- Information about tables in a schema.
-- If the schema name parameter is NULL, then tables from all schemas -- If the schema name parameter is NULL, then tables from all schemas
-- that may contain user tables are returned. -- that may contain user tables are returned.
@@ -322,7 +330,7 @@ AS $$
WHERE the_geom_webmercator && CDB_XYZ_Extent(x*2 + xx, y*2 + yy, t.z+1) WHERE the_geom_webmercator && CDB_XYZ_Extent(x*2 + xx, y*2 + yy, t.z+1)
) )
FROM t, base, (VALUES (0, 0), (0, 1), (1, 1), (1, 0)) AS c(xx, yy) FROM t, base, (VALUES (0, 0), (0, 1), (1, 1), (1, 0)) AS c(xx, yy)
WHERE t.e > %2$s AND t.z < (base.z + %3$s) WHERE t.e > %2$s AND t.z < (base.z + %3$s) AND t.z <= _CDB_MaxOverviewLevel()
) )
SELECT MAX(e/ST_Area(CDB_XYZ_Extent(x,y,z))) FROM t where e > 0; SELECT MAX(e/ST_Area(CDB_XYZ_Extent(x,y,z))) FROM t where e > 0;
', reloid::text, min_features, nz, n, c, reloid::oid) ', reloid::text, min_features, nz, n, c, reloid::oid)
@@ -363,7 +371,7 @@ AS $$
-- find minimum z so that fd*ta(z) <= lim -- find minimum z so that fd*ta(z) <= lim
-- compute a rough 'feature density' value -- compute a rough 'feature density' value
SELECT CDB_XYZ_Resolution(-8) INTO c; SELECT CDB_XYZ_Resolution(-8) INTO c;
RETURN ceil(log(2.0, (c*c*fd/lim)::numeric)/2); RETURN least(_CDB_MaxOverviewLevel(), ceil(log(2.0, (c*c*fd/lim)::numeric)/2));
END; END;
$$ LANGUAGE PLPGSQL STABLE; $$ LANGUAGE PLPGSQL STABLE;