Hi All, Solution offered by Michael worked flawlessly for geotools.2.6.3.
However, for geotools 2.7.0, when such filter: org.opengis.filter.Filter filter = ff2.equals(foo, ff2.literal(true)); passed to MapLayer in Style in Rule (mixed with some other filters using filterFactory.and()) this gives the following error: java.lang.RuntimeException: Unable to find function foo at org.geotools.filter.FunctionFinder.findFunction(FunctionFinder.java:103) Any ideas? Thanks, Sergey On 21.05.2010 6:32, Michael Bedward wrote: > Hi again Sergey, > > If you are only going to be using your filter programmatically (rather > than in SLD files) you can cheat a bit and set the string that you are > looking for in the filter function constructor like this... > > public class Foo extends FunctionExpressionImpl { > private final String typeName; > > public Foo(String typeName) { > super("foo"); > this.typeName = typeName; > } > > @Override > public int getArgCount() { > return 0; > } > > @Override > public Object evaluate(Object feature) { > return > (((SimpleFeature)feature).getID().matches(String.format("%s\\.\\d+", > typeName))); > } > } > > Then you can use it to create a Filter like this... > > FilterFactory2 ff2 = CommonFactoryFinder.getFilterFactory2(null); > org.opengis.filter.expression.Function foo = new Foo("some_name"); > org.opengis.filter.Filter filter = ff2.equals(foo, > ff2.literal(true)); > > Michael > ------------------------------------------------------------------------------ All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-d2d-c2 _______________________________________________ Geotools-gt2-users mailing list Geotools-gt2-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users