0

In Carto (CartoDB), is it possible to change the category classifications in “Torque Cat” to be qualitative instead of categorical, as you would have in the “Choropleth” map? Both the values and the legend representation. Basically I want to animate the representation we get from the choropleth wizard.

I’m working on a simple animated map of points over time for drone locations and I want the animation to change the point and trail colors according to a field with values for the drone roll or pitch at each location. I've attempted to port over the CSS from the choropleth map to the torque cat map but not getting the results I want.

updated to add my modified code as applied from answer below:

/** torque visualization */

Map {
-torque-frame-count:512;
-torque-animation-duration:30;
-torque-time-attribute:"serialdate";
-torque-aggregation-function:"sum(pitch)";
-torque-resolution:2;
-torque-data-aggregation:linear;
}

#seacharger_ca_hi_10kmjoin{
  comp-op: source-over;
  marker-fill-opacity: 0.9;
  marker-line-color: #FFF;
  marker-line-width: 0;
  marker-line-opacity: 1;
  marker-type: ellipse;
  marker-width: 6;
  marker-fill: #0F3B82;
}
#seacharger_ca_hi_10kmjoin [ value <= 12] {
   marker-fill: #41b6c4;
}
#seacharger_ca_hi_10kmjoin [ value <= 6] {
   marker-fill: #7fcdbb;
}
#seacharger_ca_hi_10kmjoin [ value <= 0] {
   marker-fill: #ffffcc;
}
#seacharger_ca_hi_10kmjoin [ value <= -7] {
   marker-fill: #FFCC00;
}
#seacharger_ca_hi_10kmjoin [ value <= -14] {
   marker-fill: #FF9900;
}
#seacharger_ca_hi_10kmjoin [ value <= -21] {
   marker-fill: #FF6600;
}
5
  • Torque values should range from 0 to 250! Try this: "sum(pitch + max)" (or better "avg(pitch + max)"), where max is the maximum value from the pitch column (you can get this value applying the following query: SELECT max(pitch) FROM seacharger_ca_hi_10kmjoin. Commented Aug 27, 2016 at 8:43
  • Sorry to leave this hanging for so long. I tried the above changes with no effect, then realized that it must be the negative values that are causing the drop outs. I used an sql query to port the original values to a new column plus 100 points resulting in a positive value scale. I then ran the code on that column adjusting the values for classes to the new positive values. The animated point now changes symbology between both ends of the class range and I have almost no missing data points. Curiously I now see some time steps with two points showing simultaneously. Commented Sep 1, 2016 at 17:02
  • link to map Commented Sep 1, 2016 at 17:05
  • The two-points problem is known, and it is due you are using avg (or maybe sum) instead of count. But this is the only way to style it as a choropleth. So if you think your question has been solved, please mark it as answered. Commented Sep 1, 2016 at 17:17
  • I'll look up the multi point issue elsewhere as swapping to count doesn't eliminate them. But the switch to choropleth seems to have worked, thanks! Commented Sep 1, 2016 at 17:32

1 Answer 1

0

CARTO Torque maps works aggregating your dataset points into bins. So you have to set torque-aggregation-function to "sum(field)" or "avg(field)". Remember that Torque only works with values from 0 to 250, so if the sum or average is more than 250, your Torque visualization will fail. In order to avoid this, you should normalize your column like this: "avg(field/100)". Then at the end of your CartoCSS code, you have to add the choropleth conditional style. Your will end up with a CartoCSS code like this one:

/** torque visualization */

Map {
-torque-frame-count:256;
-torque-animation-duration:30;
-torque-time-attribute:"date";
-torque-aggregation-function:"avg(total_damage/100000)";
-torque-resolution:2;
-torque-data-aggregation:linear;
}
#railroad_data[frame-offset=1] {
 marker-width:8;
 marker-fill-opacity:0.45; 
}
#railroad_data[frame-offset=2] {
 marker-width:10;
 marker-fill-opacity:0.225; 
}
#railroad_data [ value <= 181] {
   marker-fill: #B10026;
}
#railroad_data [ value <= 16.2959] {
   marker-fill: #E31A1C;
}
#railroad_data [ value <= 2.55648] {
   marker-fill: #FC4E2A;
}
#railroad_data [ value <= 1.4796] {
   marker-fill: #FD8D3C;
}
#railroad_data [ value <= 0.62302] {
   marker-fill: #FEB24C;
}
#railroad_data [ value <= 0.24804] {
   marker-fill: #FED976;
}
#railroad_data [ value <= 0.2454] {
   marker-fill: #FFFFB2;
}

And here you can check a live map, with this code applied.

3
  • Ok, I think this is the right answer, but I'm having some issues implementing it. Here's the link to the map with new code: Here it is with just torque running. Commented Aug 26, 2016 at 16:33
  • Is there a trick to adding a code block? Mines too long for a comment apparently. Commented Aug 26, 2016 at 16:39
  • Update your questions with your code. Commented Aug 26, 2016 at 18:31

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.