diff --git a/doc/19_contour.md b/doc/19_contour.md index d6629e4..1463918 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 millisecons for processing time +| resolution | 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..2dd9f62 100644 --- a/src/pg/sql/19_contour.sql +++ b/src/pg/sql/19_contour.sql @@ -5,7 +5,7 @@ CREATE OR REPLACE FUNCTION CDB_Contour( IN intmethod integer, IN classmethod integer, IN steps integer, - IN max_time integer DEFAULT 60000 + IN resolution integer DEFAULT -90 ) RETURNS TABLE( the_geom geometry, @@ -17,18 +17,11 @@ RETURNS TABLE( DECLARE cell_count integer; tin geometry[]; + max_time 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; -- calc the optimal number of cells for the current dataset + max_time := -1 * resolution; SELECT CASE intmethod WHEN 0 THEN round(3.7745903782 * max_time - 9.4399210051 * array_length(geomin,1) - 1350.8778213073) @@ -70,9 +63,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;