01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.filter.function;
17:
18: import org.geotools.feature.Feature;
19: import org.geotools.filter.Expression;
20: import org.geotools.filter.FunctionExpressionImpl;
21: import org.opengis.filter.expression.Literal;
22:
23: public class ClassifyFunction extends FunctionExpressionImpl {
24:
25: //parameters are expression, classifier
26:
27: public ClassifyFunction() {
28: super ("classify");
29: }
30:
31: public int getArgCount() {
32: return 2;
33: }
34:
35: public Classifier getClassifier(Object context) {
36: Expression expr = (Expression) getParameters().get(1);
37: if (expr instanceof Literal) {
38: // this is not good practice! (but the other method doesn't work)
39: Literal literal = (Literal) expr;
40: return (Classifier) literal.getValue();
41: }
42: return (Classifier) expr.evaluate(context, Classifier.class);
43: }
44:
45: public Expression getExpression() {
46: return (Expression) getParameters().get(0);
47: }
48:
49: public Object evaluate(Object feature) {
50: Classifier classifier = getClassifier(feature);
51: Expression expression = getExpression();
52: return new Integer(classifier.classify(expression, feature));
53: }
54:
55: }
|