From: Jody G. <jga...@re...> - 2005-12-16 05:59:51
|
suneesh kumar wrote: > Hello, > > I am facing a small problem while migrating my application from > geotools 2.0 to geotools 2.1. > I am getting exception in the following code: > > TextSymbolizer tsArch = sb.createTextSymbolizer(Color.RED, font, "KIDE"); > ----- > Exception is as follows: > > org.geotools.filter.IllegalFilterException: Attribute: KIDE is not > in stated schema . > at > org.geotools.filter.AttributeExpressionImpl2.setAttributePath(AttributeExpressionImpl2.java:65) > at > org.geotools.styling.StyleBuilder.attributeExpression(StyleBuilder.java:1684) Always wondered what caused this bug - I have always just used a FilterFactory .... Here is the code: > public Expression attributeExpression(String attributeName) > throws org.geotools.filter.IllegalFilterException { > org.geotools.filter.AttributeExpression attribute = > ff.createAttributeExpression((AttributeType)null); > attribute.setAttributePath(attributeName); > return attribute; > } Here is what is going on ... their are two implementations of AttributeExpression, one that takes an AttributeType and one that takes a FeatureType and a string.... In both cases the implementations will try and throw exceptions when you step "out of bounds" to a attributeName that is not going to work out. The goal being to fail once on creation rather then 10,000 times during rendering ... So above code is ending up with the first one ...AttributeExpressionImpl2 ... > public void setAttributePath(String attPath) throws > IllegalFilterException { > throw new IllegalFilterException( > "Attribute: " +attPath+ " is not in stated schema > "+"."); > } So even on geoTools trunk there is *no way* the above code can work? I am going to fix the problem with the following patch ... > public Expression attributeExpression(String attributeName) > throws org.geotools.filter.IllegalFilterException { > org.geotools.filter.AttributeExpression attribute = > ff.createAttributeExpression( null, attributeName ); > return attribute; > } And I will ask Brent or Justin to apply this patch to 2.1.x (so it will make it into the 2.1.1 release) - go either of you have a GeoTools 2.1.x checkout? Here is the issue tag: http://jira.codehaus.org/browse/GEOT-788 As for GeoTools 2.2 (aka trunk) ff.createAttributeExpression( String ) is defined ... and the troublesome methods deprecated, part of a move to make Expression, (and thus Styles) be able to work with content other the Features. For more information check out the complex DataStore branch, or the recent experimental GeoServer release... Now to answer your problem, please use StyleBuilder.createTextSymbolizer() and fill in the blanks using your own FilterFactory ... TextSymbolizer tsArch = sb.createTextSymbolizer(); tsArch.setFill( sb.createFill( Color.RED ) ); tsArch.setFont( new Font[]{ font } ); tsArch.setLabel( ff.createAttribtueExpression( null, "KIDE" ); Later (and thanks for the bug find), Jody |