Compare commits

..

4 Commits

Author SHA1 Message Date
abelvm
7c4849d62e fixed duplicities 2016-09-30 18:32:20 +02:00
abelvm
45e30973a0 v.0.0.4 2016-09-29 17:20:25 +02:00
abelvm
d51b02b61e Merge branch 'develop' of github.com:CartoDB/crankshaft into add-salesforce 2016-09-22 15:09:54 +02:00
abelvm
9b1a889133 first commit, just to save the work 2016-09-22 15:09:41 +02:00
2 changed files with 261 additions and 33 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1,33 +0,0 @@
CREATE OR REPLACE FUNCTION CDB_WeightedMedianCenter(geoms geometry[], vals numeric[])
RETURNS geometry(Point, 4326)
AS $$
DECLARE
i INT;
median_val numeric;
median_index INT;
BEGIN
-- find the median value
SELECT percentile_disc(0.5) WITHIN GROUP (ORDER BY v) INTO median_val
FROM unnest(vals) As x(v);
-- find the index of the median value
FOR i in 1..array_length(vals, 1)
LOOP
IF vals[i] < median_val
THEN
median_index := i;
EXIT;
END IF;
END LOOP;
-- return the geometry that has the median value of the dataset
IF ST_GeometryType(geoms[median_index]) <> 'ST_Point'
THEN
RETURN ST_Centroid(geoms[median_index]);
ELSE
RETURN geoms[median_index];
END IF;
END;
$$ LANGUAGE plpgsql;