3

I'm trying to style a torque heatmap in Cartodb based on a weighting value(pntcnt) rather than sum of points in an area. I think i've generated the appropriate value with the -torque-aggregation-function:"sum(pntcnt)";

However I can't seem to get the styling right.

I am new to CartoDB.

Full CSS code.

Map {
-torque-aggregation-function:"sum(pntcnt)";
-torque-resolution:2;
-torque-data-aggregation:linear; 
}

#heatmap{
  image-filters: colorize-alpha(blue, cyan, #008000, yellow , orange, red);
  marker-file: url(http://s3.amazonaws.com/com.cartodb.assets.static/alphamarker.png);
[value > 500] { marker-fill: blue; }
[value > 1000] { marker-fill: cyan; }
[value > 1500 an] { marker-fill: yellow; }
[value > 2500 { marker-fill: red; }
}

Data look something like this

Cartodb_ID        the_Geom                  pntcnt
7384             -107.6227, 24.4173         3391
7476             -107.6140, 24.4219         2514
6481             -107.7091, 24.4809         2352
6572             -107.7004, 24.4764         2258

2 Answers 2

4

You could use a query like:

WITH aux AS (
  SELECT max(pntcnt) AS m
  FROM table_name
  )
SELECT 
  t.*,
  (100.0*pntcnt)/aux.m AS norm_pntcnt
FROM 
  table_name t,
  aux

to have a norm_pntcnt column with 0-100 values. Then in the CartoCSS, you could use something like:

/** torque_heat visualization */

Map {
-torque-frame-count:1;
-torque-animation-duration:10;
-torque-time-attribute:"cartodb_id";
-torque-aggregation-function:"sum(norm_pntcnt)";
-torque-resolution:8;
-torque-data-aggregation:linear;
}

#populated_places{
  image-filters: colorize-alpha(blue, cyan, lightgreen, yellow , orange, red);
  marker-file: url(http://s3.amazonaws.com/com.cartodb.assets.static/alphamarker.png);
  marker-fill-opacity: 0.4*[value];
  marker-width: 36;
}
#populated_places[frame-offset=1] {
 marker-width:37;
 marker-fill-opacity:0.2; 
}
#populated_places[frame-offset=2] {
 marker-width:39;
 marker-fill-opacity:0.1; 
}

You could also play with -torque-resolution and marker-width to adjust the map to your preferences.

2

The Torque value variable range is limited from 0 to 255 at the moment, and your data seem to contain values much higher than this threshold.

You might want to normalize the data in the aggregation function or divide it by some quantity so that this value gets smaller (sum(pntcnt)/100). Depending on the nature of your data, just play with it and make sure that your aggregation function does not return values bigger than 255.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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