1

I have a dataset containing the cost of damage caused by individual floods over the past 100 years. I'd like to use TORQUE to display these events on a map over time, with their severity shown by the size of the marker. ie lesser cost has a smaller marker size, greater cost has larger size.

Is there a torque aggregation function which will allow me to do this?

Here is the style I have so far, but the events still show up as one size...

/** torque visualization */

Map {
-torque-frame-count:1024;
-torque-animation-duration:30;
-torque-time-attribute:"date";
-torque-aggregation-function:"count(cartodb_id)";
-torque-resolution:4;
-torque-data-aggregation:cumulative;
}

#cdd_cost_1{
marker-fill-opacity: 0.9;
marker-line-color: #FFF;
marker-line-width: 1.5;
marker-line-opacity: 1;
marker-placement: point;
marker-multi-policy: largest;
marker-type: ellipse;
marker-fill: #FF5C00;
marker-allow-overlap: true;
marker-clip: false;
}
#cdd_cost_1 [ value <= 956350000] {
marker-width: 25.0;
}
#cdd_cost_1 [ value <= 47368494] {
marker-width: 23.3;
}
#cdd_cost_1 [ value <= 21000000] {
marker-width: 21.7;
}
#cdd_cost_1 [ value <= 14523061] {
marker-width: 20.0;
}
#cdd_cost_1 [ value <= 8300000] {
marker-width: 18.3;
}
#cdd_cost_1 [ value <= 5738341] {
marker-width: 16.7;
}
#cdd_cost_1 [ value <= 4029790] {
marker-width: 15.0;
}
#cdd_cost_1 [ value <= 2828222] {
marker-width: 13.3;
}
#cdd_cost_1 [ value <= 1668590] {
marker-width: 11.7;
}
#cdd_cost_1 [ value <= 572824] {
marker-width: 10.0;
}

1 Answer 1

2

You can build your own torque-aggregation-function by playing a bit with maths. Let's say that your column is named floods. Then you could do:

-torque-aggregation-function:"round(avg(floods))";

Please, take into account that the valuevariable of Torque is bounded by 255, so if your maximum values exceed this value (which seems that it does according to your filters) you'd need to customize a little bit more your function.

-torque-aggregation-function:"round(avg((floods-min)/(max-min))*255)";

Substituting min by the minimum value of floods and max by its maximum you'll get your data normalized within the range 0-255.

Then, the maximum filter of your CartoCSS should be:

#cdd_cost_1 [ value <= 255] {
marker-width: 25.0;
}

...

If this is not good enough for your use case, just let me know. I also recommend you to take a look at this blogpost about Torque by Andrew Hill.

3
  • Will this take a while to generate tiles? Trying this and it seems to be hanging...
    – GIS Danny
    Commented Sep 27, 2016 at 0:38
  • If you're doing the normalization to 255 in CartoCSS, I'd strongly recommend taking it out to SQL: just generate select/generate a new column in the table which is normalized with SQL. This might help, but without knowing the details it's hard to say... I'd recommend to take a look at the developer tools in your browser (specially network requests, to see if you find any error)
    – iriberri
    Commented Sep 27, 2016 at 8:12
  • 1
    Thanks - I just posted a gist to do it w/ pandas before bringing into carto - gist.github.com/nygeog/03e806283c1923fb39ff538477155060
    – GIS Danny
    Commented Sep 28, 2016 at 14:10

Your Answer

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

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