Class Expression

java.lang.Object
dev.avelar.mapnik.Expression
All Implemented Interfaces:
AutoCloseable

public final class Expression extends Object implements AutoCloseable
A parsed expression in Mapnik's expression language, the one used in rule filters and text labels: [population] > 1000 and [kind] = 'city', [name] + ' (' + [pop] + ')', [elevation] * 3.28084. Attribute names go in brackets, text in single quotes, and @name refers to a variable you pass when you evaluate.

Use it to check a filter before putting it in a style, or to filter features in Java the same way Mapnik will. Holds native memory: close it.

  • Method Details

    • parse

      public static Expression parse(String text)
      Parse an expression. Throws MapnikException with Mapnik's message if it is not valid, so this doubles as a syntax check.
    • isValid

      public static boolean isValid(String text)
      True if text parses.
    • text

      public String text()
      The text this expression was parsed from.
    • evaluate

      public Object evaluate(Feature feature)
      Evaluate against a feature. The result is null, Boolean, Long, Double or String. An attribute the feature does not have reads as null.
    • evaluate

      public Object evaluate(Feature feature, Map<String,?> variables)
      As evaluate(Feature), with values for the @name variables the expression uses.
    • matches

      public boolean matches(Feature feature)
      Whether a feature passes this expression used as a filter: true, non-zero or non-empty counts as a match.
    • matches

      public boolean matches(Feature feature, Map<String,?> variables)
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • toString

      public String toString()
      Overrides:
      toString in class Object