We may be able to let the style / filter duplicating code reuse a function 
instance if it cannot actually create a copy when asked?

-- 
Jody Garnett


On Thursday, 30 June 2011 at 12:16 AM, LSA wrote:

>  Jody, thank you for answer,
> 
>  I am not really sure this tutorial is exactly what I need. 
> 
>  To illustrate my problem, I cooked a small example based on 
> SelectionLab.java (it has nothing to do with selection tool, I just used 
> SelectionLab.java as a starting point).
> 
>  Here it is:
> http://files.rsdn.ru/81424/SelectionLab.java
> 
>  Please pay attention to createDefaultStyle() method, where otherRule is 
> being created. 
>  static method createGeotoolsFilter is what I need. It takes interface 
> implementing filtering logic (ISimpleFeatureFilter) and with it constructs 
> dynamic filter (using function) which is passed to MapLayer using Rule.
>  And this is what I need - to construct filter, whose filtering logic is 
> implemented outside. 
>  In other words - I need to construct some sort of filter, which would be 
> indistinguishable from ordinary geotools filter, but with custom logic inside.
> 
>  For the supplied example geotools throws java.lang.RuntimeException: Unable 
> to find function Fooo.
> 
>  I would be really gratefull for reference implementation inside my 
> SelectionLab.java...
> 
>  Thanks,
>  Sergey
> 
>  On 29.06.2011 19:44, Jody Garnett wrote: 
> > Oh I think I can help.
> > 
> > We ended up copying the styles internally (to keep a copy that won't 
> > change). As such the code needs to be able to call FunctionFinder with 
> > "foo" and for that to work you need to register your function with the 
> > system as shown here: 
> > - http://docs.geotools.org/latest/userguide/tutorial/advanced/function.html
> > 
> > The above is an "advanced" tutorial as it involves hooking your code into 
> > geotools; all the basic tutorials just involve using geotools. 
> > 
> >  -- 
> >  Jody Garnett
> > 
> > 
> > On Wednesday, 29 June 2011 at 10:36 PM, LSA wrote:
> > 
> > > 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...
> > > > 
> > > >  FFilterFactory2 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 
> > > (mailto:Geotools-gt2-users@lists.sourceforge.net)
> > > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
> > 
> 

------------------------------------------------------------------------------
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

Reply via email to