Use cell centers, not cluster centroids when grouping points

Fixes #225
This commit is contained in:
Javier Goizueta 2016-04-07 15:34:31 +02:00
parent e68d5eca45
commit 1c67214b09

View File

@ -596,6 +596,7 @@ AS $$
gtypes TEXT[]; gtypes TEXT[];
schema_name TEXT; schema_name TEXT;
table_name TEXT; table_name TEXT;
point_geom TEXT;
BEGIN BEGIN
SELECT _CDB_GeometryTypes(reloid) INTO gtypes; SELECT _CDB_GeometryTypes(reloid) INTO gtypes;
IF array_upper(gtypes, 1) <> 1 OR gtypes[1] <> 'ST_Point' THEN IF array_upper(gtypes, 1) <> 1 OR gtypes[1] <> 'ST_Point' THEN
@ -627,19 +628,17 @@ AS $$
aggr_attributes := aggr_attributes || ', '; aggr_attributes := aggr_attributes || ', ';
END IF; END IF;
point_geom = Format('ST_SetSRID(ST_MakePoint(gx*%1$s + %2$s, gy*%1$s + %2$s), 3857)', grid_m, grid_m/2);
-- compute the resulting columns in the same order as in the base table -- compute the resulting columns in the same order as in the base table
-- cartodb_id,
-- ST_Transform(ST_SetSRID(ST_MakePoint(sx/n, sy/n), 3857), 4326) AS the_geom,
-- ST_SetSRID(ST_MakePoint(sx/n, sy/n), 3857) AS the_geom_webmercator
-- %4$s
WITH cols AS ( WITH cols AS (
SELECT SELECT
CASE c CASE c
WHEN 'cartodb_id' THEN 'cartodb_id' WHEN 'cartodb_id' THEN 'cartodb_id'
WHEN 'the_geom' THEN WHEN 'the_geom' THEN
'ST_Transform(ST_SetSRID(ST_MakePoint(sx/n, sy/n), 3857), 4326) AS the_geom' Format('ST_Transform(%s, 4326) AS the_geom', point_geom)
WHEN 'the_geom_webmercator' THEN WHEN 'the_geom_webmercator' THEN
'ST_SetSRID(ST_MakePoint(sx/n, sy/n), 3857) AS the_geom_webmercator' Format('%s AS the_geom_webmercator', point_geom)
ELSE c ELSE c
END AS column END AS column
FROM CDB_ColumnNames(reloid) c FROM CDB_ColumnNames(reloid) c
@ -660,8 +659,6 @@ AS $$
SELECT SELECT
%5$s %5$s
count(*) AS n, count(*) AS n,
SUM(ST_X(f.the_geom_webmercator)) AS sx,
SUM(ST_Y(f.the_geom_webmercator)) AS sy,
Floor(ST_X(f.the_geom_webmercator)/%2$s)::int AS gx, Floor(ST_X(f.the_geom_webmercator)/%2$s)::int AS gx,
Floor(ST_Y(f.the_geom_webmercator)/%2$s)::int AS gy, Floor(ST_Y(f.the_geom_webmercator)/%2$s)::int AS gy,
MIN(cartodb_id) AS cartodb_id MIN(cartodb_id) AS cartodb_id