From: Justin D. <jde...@op...> - 2009-03-05 23:54:56
|
Aha, very nice, much better than my suggestion :). -Justin Benoît Thiébault wrote: > Hi Justin, > > In fact, I just found a way to do it : > > // Temporary style > Style style = null; > > // Style builder > StyleBuilder sb = new StyleBuilder(); > > // Line symbolizer stroke > Stroke stroke = sb.createStroke(sb.attributeExpression("color"), > sb.literalExpression(2.0)); > > // Line symbolizer > LineSymbolizer lineSymbolizer = sb.createLineSymbolizer(stroke); > > // Creates the style > style = sb.createStyle(lineSymbolizer); > > Le 5 mars 09 à 21:33, Justin Deoliveira a écrit : > >> 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 >>> Geo...@li... >>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >> >> >> -- >> Justin Deoliveira >> OpenGeo - http://opengeo.org >> Enterprise support for open source geospatial. >> > > Benoît Thiébault > > Société Artenum > 24 rue Louis Blanc, 75010 Paris > tel: +33 (0)1 46 94 67 54 > > Artenum - Science & Groupware - http://www.artenum.com > -- Justin Deoliveira OpenGeo - http://opengeo.org Enterprise support for open source geospatial. |