New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
All values should become expressions #828
Comments
|
[kkaefer] Backwords compatiblity with current symbolizer values: first try to parse as constant/static value, if that fails, try to parse as expression |
|
[kkaefer] Duplicate: #359 |
|
[kkaefer] Implementation happens in https://github.com/kkaefer/mapnik2/compare/expressions I benchmarked On world_merc, the difference wasn't measurable. I also created a stylesheet that actually takes advantage of the fact that we can reference the data in values: |
|
This would be very cool, and could allow things like "change the colour of this object based on a column". |
|
Big fan of having this. Gradients, levels and in general functions would be cool, but expressions themselves are already a huge win. In CartoDB most of the functions can be precalculated via SQL and inject with the expression. |
|
Yes please! :) |
|
A syntax allowing a fallback value would be great, too. |
|
Hi, is there a list of attributes supporting expressions? |
|
Not as far as I know, but I just added information about support to the following wiki pages:
You can also use expressions with TextSymbolizer by using ExpressionFormat. I haven't found documentation in the Wiki about this feature, but see https://github.com/mapnik/mapnik/blob/master/tests/visual_tests/styles/text-expressionformat-color.xml as an example. As far as I know you can use ExpressionFormat from Mapnik 2.2 with the following attributes: I don't know about other symbolizers, but as far as I know they don't support expreesions yet. I hope I was right about all changes ... please correct me. |
|
This is now in place in master (upcoming 3.0.0 release). 95% of symbolizer properties are expressions with only a few holdouts/todos. If you find one that does not respond as an expression please file a new issue :) @plepe - ExpressionFormat was removed because now it is redundant because the normal |
To allow for less complex styles, every symbolizer attribute should become an expression. There are some properties that already have a notion of being an expression, e.g. the polygon-pattern-file and text-name has token replacement and the marker-width is an expression too.
How to implement
When rendering, create a pseudo-stylesheet for each layer that contains only the rules for that layer. This is already happening in [https://github.com/mapnik/mapnik2/blob/f3061554c97e80520da45870d86ae7ed6cc5c7ee/include/mapnik/feature_style_processor.hpp#L262-297 apply_to_layer()]. Instead of just creating a new set, we clone each rule and pre-evaluate it; i.e. evaluate all expressions as much as possible, leaving the parts that reference feature-specific values intact. In some cases, this might already yield a constant value, in other cases we still have an expression. This is an optional step and should be implemented last to improve performance should the following changes turn out to slow down rendering dramatically.
Every attribute of a symbolizer becomes an expression. The renderer passes the feature to the attribute getter of a symbolizer to obtain the actual value. In case the value is static, the expression object just returns that value, otherwise it evaluates the expression taking the current feature into account. In addition to the feature's attributes, the scale denominator is also an available attribute.
As a next step, we'd add ''value gradients'': a function that transforms a float in the range of 0.0 to 1.0 to an actual value, e.g. you could create a color gradient from #000 to #FFF and using an expression, calculate a value between 0 and 1 (e.g. by using statistics about the datasource) and resolve that value to a color. This could come in two flavors, a gradient() function that returns continuous values and a levels() that returns only discrete values.
Related tickets: #816, #827, #704, #810
The text was updated successfully, but these errors were encountered: