3

I would like to make the CartoDB heatmap use weighted values from a column in the dataset. I tried to find the option in the wizards and the docs but I couldn't find anything. Is there a way to do that?

  • 1
    Heatmaps are a variation of Torque maps, maybe you could change the torque-aggregation-function of the Heatmap in order to get the effect that you want. You can find more information about how the Torque spatial aggregation works here:github.com/CartoDB/torque/wiki/How-spatial-aggregation-works – oriolbx Feb 11 '16 at 9:49
  • @oriolbx that comment deserves to be in an answer, not in the comments! :-) – iriberri Feb 14 '16 at 10:53
0

As @oriolbx suggested in the comments it is possible through the torque-aggregation-function. You can change the standard heatmap CartoCSS like this:

/** torque_heat visualization */

Map {
-torque-frame-count:1;
-torque-animation-duration:10;
-torque-time-attribute:"cartodb_id";
-torque-aggregation-function:"round(avg(weight))";
-torque-resolution:2;
-torque-data-aggregation:linear;
}

#your-dataset{
  image-filters: colorize-alpha(blue, cyan, lightgreen, yellow , orange, red);
  marker-file: url(http://s3.amazonaws.com/com.cartodb.assets.static/alphamarker.png);
  [value < 1] {marker-fill-opacity: 0.05;}
  [value < 10] {marker-fill-opacity: 0.1;}
  [value < 100] {marker-fill-opacity: 0.2;}
  [value < 1000] {marker-fill-opacity: 0.4;}
  [value < 10000] {marker-fill-opacity: 0.6;}
  [value < 100000] {marker-fill-opacity: 0.8;}
  [value >= 100000] {marker-fill-opacity: 1.0;}
  marker-width: 7;
}

The only differences are the -torque-aggregation-function, for which I used my weight column, and the marker-fill-opacity, that has to be modified to take into account the output value of the torque aggregation function, stored in the value variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.