Hi GeoTools members, I am writing to you in a state of confusion. In the last weeks I have been building another page of my styling widget for GISWidgets, one that is supposed to use expressions for attributes like color, line width etc. (Work is progressing, but slowly. I had an accident last week and was away for some days.)
Anyway, I thought it a good idea to look at OGC/GeoAPI/Geotools for their style and expression API ... and was hit by a lot of things that I simply don't understand: 1. What is an expression? My idea of an expression is more or less equal to what is defined on Wikipedia: http://en.wikipedia.org/wiki/Expression_%28programming%29 and http://en.wikipedia.org/wiki/Expression_%28mathematics%29 That is, it is a generic object returning a result. (Can be a constant(literal), a mathematical function, or the result might be depending on another object or on its attributes. Note that there's nothing geospatial about this definition at all! Reading the OGC Symbology Encoding v1.1 (05-077r4) document I find this mostly confirmed (e.g. page 17 for line stroke parameters). They use the "ParameterValueType" which in turn uses "ogc:expression"s. On the other hand OGC Filter Encoding v1.1 (04-095) defines on page 15: "An expression is a combination of one or more symbols that evaluate to single boolean value of true or false." I plainly don't understand this definition! :-( Still, from the text below, compared to the subinterfaces of org.opengis.filter.expression.Expression, I gather that they are ment to represent the same thing. Now I looked at the GeoAPI and GeoTools interfaces I found in my workspace: - geoapi-2.1-M2.jar: org.opengis.filter.expression.Expression - geoapi-2.0-tiger.jar: org.opengis.filter.expression.Expression - gt2-api-2.3.0.jar: org.geotools.filter.Expression (Deprecated) The GeoTools Expression interface was obviously geared too much towards Features: Object getValue(Feature feature); The very same applies to the old(?!) geoapi-2.0 interface. This basically leaves me with the pending geoapi-2.1-M2, whose Expression interface has following signature: Object evaluate(Object object); <T> T evaluate(Object object, Class<T> context) Object accept(ExpressionVisitor visitor, Object extraData) I admit the visitor design patter is the only one I have never understood - and I never understood why I would ever need something like that. And again, why does an expression need visitors? If I imagine a typical expression that takes a Feature as input and calculates a number from, lets say, the feature attribute "population", then I wouln't need to visit anything for this. 2. What is a function? There's also Function, extending this Expression interface with: String getName() void setName(String name) List<Expression> getParameters() void setParameters(List<Expression> parameters) Anyway, here my personal understanding is different from yours obviously. I would't care in the interface about parameter setting/getting and leave this to the implementations. But for me functions have something to do with math, hence I would expect a signature like this one: Number evaluate(Object object); Obviously, I should apply the programming definition of a "function" ... yes this fits better than the mathematical definition. It even explains why a function could have a name (but not why an expression doesn't need one). This leaves the question of the difference between an expression and a function. Can someone explain this in an understandable way? To me it looks like the only difference is that the expression just requires one object to get the result, the function needs an object and one or several parameters. Hmm ... beat me, but is the difference between the "input object" and "parameters"??? I don't see one, except if you require that the input object is to be a featue always. Couldn't we just define expression like this: Object evaluate(Object[] parameters); int getNumParameters(); Oh, and I'd prefer it type save (Java5), so what about: interface Expression<O extends Object>{ Class<? extends O> getOutputClass(); O evaluate(Object[] parameters); int getNumParameters(); } Beside this I do not see any relationship in interface signature between the GeoAPI "Function" and the definition of "Symbology Encoding Functions" in OGC Symbology Encoding v1.1 (05-077r4) pp. 37ff. Somehow this OGC spec makes sense to me, but the (in my opinion corresponding) GeoAPI interfaces don't. Guess I am mistaken in their meaning. 3. Binary expressions? Also confusing are the binary expressions: Obviously they combine two expression's results to return a combined one. Things like "Add" or "Multiply" just make sense with numbers, but I cannot see any type safety preventing you from trying to multiply a String with a color. ;-) 4. Status of GeoTools When I look at Classes such as f.e. "org.geotools.filter.function.math.FilterFunction_cos" I find that they theoretically implement the new GeoAPI interface, but more or less can only cope with features. (Otherwise they always return a new empty object. See class DefaultExpression.) I doubt such implementations are suitable for building generic expressions like I would like to do. So my lask question is: Are the geotools expression implementations by definition limited to taking a feature as input object for "evaluate" or is this just a historical thing, and they will be updated later? Sigh. I will have a look at uDig tomorrow. They manage to build SLD styles in the color brewer style page, so I hope to find some answers about expressions there. I guess I should go to bed now and sleep things over. P.S. If you got confused by reading my mail, feel free to ignore it. :-) -- Matthias Basler [EMAIL PROTECTED] ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier. Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Geotools-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/geotools-devel
