Michael Bedward ha scritto:
> Hi Nenad,
> 
> OK, here's where I try to sell you another filter function hack and
> see if Miles can trump it with a one liner again :-)
> 
> import java.util.HashMap;
> import java.util.Map;
> import org.geotools.filter.FunctionExpressionImpl;
> import org.opengis.feature.simple.SimpleFeature;
> 
> public class VarLookupFunction extends FunctionExpressionImpl {
> 
>     private static Map<String, Double> table
> 
>     public VarLookupFunction(String name) {
>         super("VarLookup");
>     }
> 
>     public static void setLookupValues(Map<String, Double> values) {
>         table = new HashMap<String, Double>();
>         table.putAll(values);
>     }
> 
>     @Override
>     public int getArgCount() {
>         return 1;
>     }
> 
>     @Override
>     public Object evaluate(SimpleFeature feature) {
>         String varName = getExpression(0).evaluate(feature, String.class);
>         return lookupValues.get(varName);
>     }
> 
> }

Hey hey! :-)
This looks a lot like the next SLD proposal I want to make (time 
allowing), "Enviroment variables" :-)

I imagined it almost the way you proposed it, the only twist would
be that the map would be stored in thread local to allow multiple
value and that the function would also allow a default value to
fall back to if the variable is not defined.

Cheers
Andrea

-- 
Andrea Aime
OpenGeo - http://opengeo.org
Expert service straight from the developers.

------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing. 
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to