Hi Manfred; what version of GeoTools are you using? I spent a lot of
time fixing up these sorts of errors for 2.5-M2 ...
Manfred PAUL wrote:
>
> Hi,
>
> I want to draw a postgis layer (polygon) with a simple style (as well
> as an alpha color).
>
> But I always get a cast error. Here is the code, maybe somebody has an
> idea ?
>
> Manfred
>
> Error :
>
> java.lang.ClassCastException: java.awt.Color cannot be cast to
> java.lang.String
>
> at
> org.geotools.renderer.style.SLDStyleFactory.evalToColor(SLDStyleFactory.java:1447)
>
> at
> org.geotools.renderer.style.SLDStyleFactory.getStrokePaint(SLDStyleFactory.java:986)
>
> at
> org.geotools.renderer.style.SLDStyleFactory.createLineStyle(SLDStyleFactory.java:398)
>
> at
> org.geotools.renderer.style.SLDStyleFactory.createStyleInternal(SLDStyleFactory.java:332)
>
> at
> org.geotools.renderer.style.SLDStyleFactory.createStyle(SLDStyleFactory.java:295)
>
> at
> org.geotools.renderer.lite.StreamingRenderer.processSymbolizers(StreamingRenderer.java:1730)
>
> at
> org.geotools.renderer.lite.StreamingRenderer.process(StreamingRenderer.java:1657)
>
> at
> org.geotools.renderer.lite.StreamingRenderer.processStylers(StreamingRenderer.java:1601)
>
> at
> org.geotools.renderer.lite.StreamingRenderer.paint(StreamingRenderer.java:641)
>
> at
> org.geotools.renderer.lite.StreamingRenderer.paint(StreamingRenderer.java:473)
>
> at com.bg.union.pa.GeoToolsEngine.paint(GeoToolsEngine.java:116)
>
> at
> com.bg.union.pa.GeoToolsRenderService.execute(GeoToolsRenderService.java:23)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>
> at java.lang.reflect.Method.invoke(Method.java:597)…
>
> First problem based on this code: (no alpha)
>
> StyleBuilder builder = *new* StyleBuilder();
>
> PolygonSymbolizer symbolizer = /styleFactory/.createPolygonSymbolizer();
>
> Stroke stroke = symbolizer.getStroke();
>
> *if* (stroke == *null*) {
>
> stroke = builder.createStroke(Color./blue/);
>
> symbolizer.setStroke(stroke);
>
> }
>
> stroke.setColor(builder.colorExpression(Color./blue/));
>
> Fill fill = symbolizer.getFill();
>
> *if* (fill == *null*) {
>
> fill = builder.createFill(Color./blue/);
>
> symbolizer.setFill(fill);
>
> }
>
> Rule rule = /styleFactory/.createRule();
>
> rule.setSymbolizers(*new* Symbolizer[] { symbolizer });
>
> FeatureTypeStyle fts = /styleFactory/.createFeatureTypeStyle();
>
> fts.setRules(*new* Rule[] { rule });
>
> fts.setFeatureTypeName("polygonfeature");
>
> Style style = /styleFactory/._createStyle_();
>
> style.addFeatureTypeStyle(fts);
>
> Second problem (this time with alpha) but the same error message:
>
> PolygonSymbolizer polysym = styleFactory.createPolygonSymbolizer();
>
> Fill myFill = styleFactory.getDefaultFill();
>
> // --- HERE
>
> myFill.setOpacity(filterFactory.literal(0.5));
>
> myFill.setColor(filterFactory.literal("#FFAA00"));
>
> polysym.setFill(myFill);
>
> polysym.setStroke(styleFactory.getDefaultStroke());
>
> Rule rule0 = styleFactory.createRule();
>
> rule0.setSymbolizers(new Symbolizer[]{polysym});
>
> FeatureTypeStyle fts0 = styleFactory.createFeatureTypeStyle(new
> Rule[]{rule0});
>
> //fts0.setFeatureTypeName("polygonfeature");
>
> style0 = styleFactory.createStyle();
>
> style0.addFeatureTypeStyle(fts0);
>
> return style0;
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> ------------------------------------------------------------------------
>
> _______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users