Sunday, 15 March 2015

carto - Setting a polygon-fill ramp to have minimum and maximum values


Using the Carto web-tool I've set up a map to fill polygons based on the value of one of its attributes. However, due to outliers in the data the attributes range in values from 0 to >600, where as I want to set the colour bar to range from 6-48, with the values outside this range being the same colour as the min/max limits.


I believe this can be done by using a list of conditional statementes


#layer_name[ value <= 6] {

polygon-fill: #FF2BE3;}
#layer_name[ value <= 12] {
polygon-fill: #FF41CF;}
#layer_name[ value <= 18] {
polygon-fill: #FF58BC;}
...
#layer_name[ value > 48] {
polygon-fill: #00FFFF;}

But when using the updated carto web-tool the default formatting for polygon-fill is now:



#layer {
polygon-fill: ramp([value], (#ffffb2, #fed976, #feb24c, #fd8d3c, #fc4e2a, #e31a1c, #b10026), quantiles);
polygon-opacity: 0.4;
line-width: 1;
line-color: #ffffff;
line-opacity: 0.1;
}

Is there a way to adjust the ramp function to provide lower and upper limits?



Answer




ramp is a Turbo Carto function. Turbo Carto was developed as a CartoCSS preprocessor in order to adapt to dynamic queries, so the color palette or range of dot/line size/opacity/... will adapt to these new values.


So, if you know your data (and how it is classified), you can still apply the first CartoCSS code you have shared on your post. But remember to change your legend to a custom one.


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...