I have a PostGIS table that contains the GDP of countries together with their polygon boundaries. I am using GeoServer to display this data via OpenLayers.

When styling the data, I want to avoid having to hardcode numeric range / colour pairs in my SLD file.

Is it possible to create an SLD style file that dynamically determines the minimum and maximum value of GDP that are present in a PostGIS column, for example through CQL, and then uses that information to colour the map?


2 Answers 2


Following Dynamic SLD styling - unique colours for linestrings I would suggest adding a "color value" column to your postGIS table is the easiest solution. The column should always be updated with respect to the current range of GDP values. Then, you might access it in your SLD with a PropertyValue in the CssParameter tag.

  • Thanks for your answer. My concern is that it just doesn't seem very clean to hardcode this, mixing raw data and formatting instructions in the same table. Also, it may be desirable to modify colour scale at runtime.
    – user18285
    Commented Jul 8, 2013 at 20:51

I don't know much about PostGIS, but would it be possible to make a view out of your table which generates a column that contains either a colour value or perhaps some sort of calculated percentile that you could then use to style. This would then technically keep your Raw data away from data used to style it. For example, I'm sure you could (don't ask me how, I'm an Oracle man) add a new column in your view called something like GDPPercentile, which would be 100 for whatever row had the highest value, 0 for whatever had the lowest value, and the values in between for everything else. From that you could use GeoServer SLDs Comparison Operators to assign colours to various percentile ranges, using <PropertyIsGreaterThanOrEqualTo> and <PropertyIsLessThan> ranges.

I hope that makes sense (it does in my head, but articulating it was a whole different story). Like I said, I don't know anything about the capabilities of PostGIS, so it might not be possible.

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.