smart guessing optional

This commit is contained in:
abelvm
2016-09-02 12:23:47 +02:00
parent ef436546b4
commit bbdd4de6ee
3 changed files with 12 additions and 15 deletions

View File

@@ -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

View File

@@ -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(

View File

@@ -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;