SLD Rule Evaluation?

I’m curious about how others store/evaluate SLD rules/filters. At the moment, in OpenLayers SLD rendering, we have an ‘applies’, which is a string something like:

“feature[‘attributename’] == ‘foo’ || feature.fid == 1”

Which we eval. Yuck, I know.

But how else do you do it? What’s the internal storage look like?

I originally thought of something like a set of tuples:

(‘operation’, ‘value’, ‘type’, ‘extra’):

  • (‘equals’, ‘foo’, ‘attribute’, ‘attributename’)
  • (‘equals’, 1, ‘fid’)

But then Andreas pointed out that these are not just ‘and’ or ‘or’, but either of the two, and can also be nested… it seems like it quickly goes complex enough that we would need to implement a full boolean logic thingy of some kind, and it seems like the wrong way to go… but then again, so does eval.

Would love to have advice from someone else as to how they implement SLD filters and their application.

3 Responses to “SLD Rule Evaluation?”

  1. Sean Gillies Says:

    Why not DOM to store and compile into javascript for evaluation?

  2. crschmidt Says:

    1. eval is slow
    2. I hate calling eval on random stuff given to me by users.
    3. Expressions don’t feel like the right way to implement filtering. But maybe I’m wrong.

  3. Sean Gillies Says:

    I just wanted to make sure you ruled out the brain-dead solution before you wrote a rules engine.