diff --git a/doc/19_contour.md b/doc/19_contour.md index 2e5b440..fdee52e 100644 --- a/doc/19_contour.md +++ b/doc/19_contour.md @@ -18,7 +18,7 @@ Function to generate a contour map from an scatter dataset of points, using one | method | integer | 0:nearest neighbor, 1: barycentric, 2: IDW| | classmethod | integer | 0:equals, 1: heads&tails, 2:jenks, 3:quantiles | | steps | integer | Number of steps in the classification| -| max_time | integer | Max time in milliseconds for processing time +| max_time | integer | if <= 0: max processing time in seconds (smart resolution) , if >0: resolution in meters ### Returns Returns a table object diff --git a/src/pg/sql/19_contour.sql b/src/pg/sql/19_contour.sql index 759b151..78f0cfd 100644 --- a/src/pg/sql/19_contour.sql +++ b/src/pg/sql/19_contour.sql @@ -17,16 +17,15 @@ RETURNS TABLE( DECLARE cell_count integer; tin geometry[]; + resolution integer; BEGIN - -- calc the cell size in web mercator units - -- WITH center as ( - -- SELECT ST_centroid(ST_Collect(geomin)) as c - -- ) - -- SELECT - -- round(resolution / cos(ST_y(c) * pi()/180)) - -- INTO cell - -- FROM center; - -- raise notice 'Resol: %', cell; + + -- nasty trick to override issue #121 + IF max_time = 0 THEN + max_time = -90; + END IF; + resolution := max_time; + max_time := -1 * resolution; -- calc the optimal number of cells for the current dataset SELECT @@ -70,9 +69,13 @@ BEGIN ), resolution as( SELECT - round(|/ ( - ST_area(geom) / cell_count - )) as cell + CASE WHEN resolution <= 0 THEN + round(|/ ( + ST_area(geom) / abs(cell_count) + )) + ELSE + resolution + END AS cell FROM envelope3857 ), grid as( diff --git a/src/pg/test/sql/19_contour_test.sql b/src/pg/test/sql/19_contour_test.sql index 70e5cf9..9225612 100644 --- a/src/pg/test/sql/19_contour_test.sql +++ b/src/pg/test/sql/19_contour_test.sql @@ -12,6 +12,6 @@ SELECT foo.* FROM a, - cdb_crankshaft.CDB_contour(a.g, a.vals, 0.0, 1, 3, 5, 60) foo + cdb_crankshaft.CDB_contour(a.g, a.vals, 0.0, 1, 3, 5, -60) foo ) SELECT bin, avg_value from b order by bin;