-DROP FUNCTION IF EXISTS cdb_contour(geometry[],numeric[],numeric,integer,integer,integer,integer);
-
 CREATE OR REPLACE FUNCTION CDB_Contour(
     IN geomin geometry[],
     IN colin numeric[],

    IN intmethod integer,
    IN classmethod integer,
    IN steps integer,
    IN resolution integer DEFAULT -90
    )
RETURNS TABLE(
    the_geom geometry,

DECLARE
    cell_count integer;
    tin geometry[];
    resolution integer;
BEGIN

    -- nasty trick to override issue #121
    resolution := max_time;
    max_time := -1 * resolution;

    -- calc the optimal number of cells for the current dataset
    SELECT
    CASE intmethod
        WHEN 0 THEN round(3.7745903782 * max_time - 9.4399210051 * array_length(geomin,1) - 1350.8778213073)
