Files
cartodb-postgresql/scripts-available/CDB_ZoomFromScale.sql
T
Paul Norman aa302c237d Use standard formula for CDB_ZoomFromScale
postgis-vt-util comes with a standard formula for zoom from
scaleDenominator, and this is well tested. This also fixes the
function throwing an error on NULL input.
2016-05-27 12:29:43 +02:00

13 lines
350 B
PL/PgSQL

CREATE OR REPLACE FUNCTION cartodb.CDB_ZoomFromScale(scaleDenominator numeric)
RETURNS int
LANGUAGE SQL
IMMUTABLE
AS $$
SELECT
CASE
-- Don't bother if the scale is larger than ~zoom level 0
WHEN scaleDenominator > 600000000 OR scaleDenominator = 0 THEN NULL
ELSE CAST (ROUND(LOG(2, 559082264.028/scaleDenominator)) AS INTEGER)
END;
$$;