Hi Benoît,

Looking at the style builder classes, it does not seem to be possible, 
as it does not expose a method that creates a stroke from an Expression. 
  However you can get at the underlying style factory 
(getStyleFactory()), and should be able to manually build up the 
symbolizer, creating the stroke with a property expression. The downside 
being that it will take 3 or 4 lines of code to build up the symbolizer 
manually, instead of calling a single method on the builder.

-Justin

Benoît Thiébault wrote:
> Hi everyone,
> 
> I am trying to build a style programmatically, and I would like the  
> color of my line symbolizer to be retrieved from a feature attribute,  
> like in the SLD sample below.
> Do you know how to do this ?
> 
> <UserStyle>
>       <FeatureTypeStyle>
>                <Rule>
>                       <LineSymbolizer>
>                               <Stroke>
>                                       <CssParameter name=\"stroke\">
>                                               
> <PropertyName>color</PropertyName>
>                                       </CssParameter>
>                                       <CssParameter 
> name=\"width\">1.0</CssParameter>
>                               </Stroke>
>                       </LineSymbolizer>
>               </Rule>
>       </FeatureTypeStyle>
> </UserStyle>
> 
> Here is my code so far:
> 
> // Create the style
> Style style = null;
> 
> // Create the style builder and the filter factory
> StyleBuilder sb = new StyleBuilder();
> 
> // Creates the line symbolizer
> LineSymbolizer symbolizer = sb.createLineSymbolizer(Color.decode(???));
> 
> // Creates a rule
> Rule rule = sb.createRule(symbolizer);
> 
> // Creates a feature style
> FeatureTypeStyle fts = sb.createFeatureTypeStyle(typeName, rule);
> 
> // Creates the style
> style = sb.createStyle();
> 
> // Adds the feature style to the style
> style.addFeatureTypeStyle(fts);
> 
> ------------------------------------------------------------------------------
> Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
> -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
> -Strategies to boost innovation and cut costs with open source participation
> -Receive a $600 discount off the registration fee with the source code: SFAD
> http://p.sf.net/sfu/XcvMzF8H
> _______________________________________________
> Geotools-gt2-users mailing list
> Geotools-gt2-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users


-- 
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Geotools-gt2-users mailing list
Geotools-gt2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to