From bbdd4de6ee305308d2d131d8bf5dc5e8f475a068 Mon Sep 17 00:00:00 2001 From: abelvm Date: Fri, 2 Sep 2016 12:23:47 +0200 Subject: [PATCH 1/6] smart guessing optional --- doc/19_contour.md | 2 +- src/pg/sql/19_contour.sql | 23 ++++++++++------------- src/pg/test/sql/19_contour_test.sql | 2 +- 3 files changed, 12 insertions(+), 15 deletions(-) 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; From 90f36b40585835c1b60ad4491c52a2af8a0a9af9 Mon Sep 17 00:00:00 2001 From: abelvm Date: Fri, 2 Sep 2016 12:35:54 +0200 Subject: [PATCH 2/6] drop --- src/pg/sql/19_contour.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pg/sql/19_contour.sql b/src/pg/sql/19_contour.sql index 2dd9f62..784779e 100644 --- a/src/pg/sql/19_contour.sql +++ b/src/pg/sql/19_contour.sql @@ -1,3 +1,5 @@ +DROP FUNCTION cdb_contour(geometry[],numeric[],numeric,integer,integer,integer,integer); + CREATE OR REPLACE FUNCTION CDB_Contour( IN geomin geometry[], IN colin numeric[], From 036a33aceddb3bfa041f1cb405d72b467653d3e1 Mon Sep 17 00:00:00 2001 From: abelvm Date: Fri, 2 Sep 2016 12:58:13 +0200 Subject: [PATCH 3/6] drop --- src/pg/sql/19_contour.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pg/sql/19_contour.sql b/src/pg/sql/19_contour.sql index 784779e..ae48eb5 100644 --- a/src/pg/sql/19_contour.sql +++ b/src/pg/sql/19_contour.sql @@ -1,4 +1,4 @@ -DROP FUNCTION cdb_contour(geometry[],numeric[],numeric,integer,integer,integer,integer); +DROP FUNCTION IF EXISTS cdb_contour(geometry[],numeric[],numeric,integer,integer,integer,integer); CREATE OR REPLACE FUNCTION CDB_Contour( IN geomin geometry[], From b8ce37eb60c5da80d966330982d2dd952562464d Mon Sep 17 00:00:00 2001 From: abelvm Date: Fri, 2 Sep 2016 14:37:52 +0200 Subject: [PATCH 4/6] back to the original signature --- src/pg/sql/19_contour.sql | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/pg/sql/19_contour.sql b/src/pg/sql/19_contour.sql index ae48eb5..5c2cfc2 100644 --- a/src/pg/sql/19_contour.sql +++ b/src/pg/sql/19_contour.sql @@ -1,5 +1,3 @@ -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[], @@ -7,7 +5,7 @@ CREATE OR REPLACE FUNCTION CDB_Contour( IN intmethod integer, IN classmethod integer, IN steps integer, - IN resolution integer DEFAULT -90 + IN max_time integer DEFAULT -90 ) RETURNS TABLE( the_geom geometry, @@ -19,11 +17,14 @@ RETURNS TABLE( DECLARE cell_count integer; tin geometry[]; - max_time integer; + resolution integer; BEGIN - -- calc the optimal number of cells for the current dataset + -- 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) From 139e86d414ce7b227ecb806862c0f45c1fd6b6bb Mon Sep 17 00:00:00 2001 From: abelvm Date: Fri, 2 Sep 2016 14:43:48 +0200 Subject: [PATCH 5/6] back to the original signature --- src/pg/sql/19_contour.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pg/sql/19_contour.sql b/src/pg/sql/19_contour.sql index 5c2cfc2..18430c0 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 -90 + IN max_time integer DEFAULT 60000 ) RETURNS TABLE( the_geom geometry, From a530de80f106ab1ff1eef56272c8c1005aec9530 Mon Sep 17 00:00:00 2001 From: abelvm Date: Fri, 2 Sep 2016 14:57:21 +0200 Subject: [PATCH 6/6] back to the original signature --- doc/19_contour.md | 2 +- src/pg/sql/19_contour.sql | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/19_contour.md b/doc/19_contour.md index b29ed89..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| -| resolution | integer | if <= 0: max processing time in seconds (smart resolution) , if >0: resolution in meters +| 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 18430c0..78f0cfd 100644 --- a/src/pg/sql/19_contour.sql +++ b/src/pg/sql/19_contour.sql @@ -21,6 +21,9 @@ DECLARE BEGIN -- nasty trick to override issue #121 + IF max_time = 0 THEN + max_time = -90; + END IF; resolution := max_time; max_time := -1 * resolution;