Sunday 22 March 2015

animation - Animating quantitative values in Carto Torque Cat?


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;
}


Answer



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.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...