Merge pull request #120 from CartoDB/add-contour

Let the user set the resolution [19]
This commit is contained in:
Carla
2016-09-21 17:14:05 +02:00
committed by GitHub
3 changed files with 17 additions and 14 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 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

View File

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

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;