0

This question is stemming from my other question on data defined attributes: How to create a gradient point on top of a shapefile?

Anyway, can anyone help me create an expression within the data defined properties -> fill color -> expression string builder. See following screenshot

enter image description here

My field is an integer value and I'd prefer light blue to dark blue gradient fill. Can anyone help with the input into the expression builder that would result in gradient filled centroid markers?

1

Well, I updated my original answer, but here it is again:

enter image description here

5

If you're wanting to do this via expressions, here's a possible approach:

  1. Under Settings -> Style Manager -> Color Ramp tab, create a new gradient ramp for your desired colors. (Hit the plus button down the bottom to add a new gradient). Give this gradient a descriptive name, eg 'blue ramp'.

  2. You can take advantage of the "ramp_color" function in an expression. This function returns a color interpolated from a color ramp. So, if you wanted the color 3/4 of the way along the 'blue ramp' gradient, the expression would be

    ramp_color('blue ramp', 0.75)

  3. You'll also want to use the "scale_linear" function, which makes it easy to scale values from a specified input max/min value to a max/min output range. Let's say your input values are stored in the "population" column and range from 100 to 300, then the expression:

    scale_linear( population, 100, 300, 0, 1 )

    will return values between 0 and 1, where a population of 100 returns 0 and a population of 300 returns 1, and values between 100 and 300 will return values somewhere between 0 and 1.

  4. Combining these two functions, the expression:

    ramp_color('blue ramp', scale_linear(population, 100, 300, 0, 1))

    will return a color from the ramp, with its position along the ramp scaling smoothly from population values of 100 to 300.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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