Hi Michael, hi everyone,
Good news, I found a way to get rid of almost all deprecated methods.
Almost, because there is still one method I don't know how to avoid...
The idea is to use a StyleBuilder object instead of the StyleFactory
used in the example.
The API is a bit different, but you can achieve the same result.
The only deprecated method I still use is
style.addFeatureTypeStyle(fts). Maybe someone knows a way to avoid it ?
Here is the code I used. I do a color gradient (composed of colorsNb
different color), depending on the "depth" attribute value of my
FeatureType.
private Style createLineStyle(final String typeName, final double
maxDepth,
final int colorsNb) {
// Temporary style
Style style = null;
// Creates rules and symbolizers arrays
Rule[] rules = new Rule[colorsNb];
LineSymbolizer[] symbolizers = new LineSymbolizer[colorsNb];
// Depth range
double min = 0.0;
double max = 0.0;
// Color range
Color c1 = Color.decode("#000000");
Color c2 = Color.decode("#CCCCC");
StyleBuilder sb = new StyleBuilder();
FilterFactory ff = CommonFactoryFinder.getFilterFactory(GeoTools
.getDefaultHints());
for (int i = 0; i < colorsNb; i++) {
// Computes the color
float ratio = (float) i / (float) colorsNb;
int red = (int) (c2.getRed() * ratio + c1.getRed() * (1
- ratio));
int green = (int) (c2.getGreen() * ratio + c1.getGreen()
* (1 - ratio));
int blue = (int) (c2.getBlue() * ratio + c1.getBlue() *
(1 - ratio));
// Computes the depth range
min = i * maxDepth / colorsNb;
max = (i + 1) * maxDepth / (colorsNb);
// Set the symbolizer
symbolizers[i] = sb
.createLineSymbolizer(new Color(red,
green, blue));
Filter filter =
ff.between(sb.attributeExpression("depth"), sb
.literalExpression(min),
sb.literalExpression(max));
rules[i] = sb.createRule(symbolizers[i]);
rules[i].setFilter(filter);
}
// Creates a feature style
FeatureTypeStyle fts = sb.createFeatureTypeStyle(typeName,
rules);
// Creates the style
style = sb.createStyle();
// Adds the feature style to the style
style.addFeatureTypeStyle(fts);
return style;
}
Le 18 févr. 09 à 00:33, Michael Bedward a écrit :
> 2009/2/17 Benoît Thiébault wrote:
>> From what I see in the code you wrote, you don't use rules. How
>> would you do
>> to process a FeatureType differently depending on a feature
>> attribute ?
>
> I haven't worked out to use rules programmatically without using
> deprecated methods. Actually, if you look at the source for
> StyleBuilder and StyleFactory they have the same problem ! I believe
> styling is in a state of flux but I'm afraid that I don't follow all
> the details...
>
> I have been looking at the source for DynamicPolygonStyle2D class that
> is used in the geotools rendering system. It uses Expressions to get
> colour codes (in notation like #808080) for fill, outline... It
> passes each feature in turn to the Expression object to be evaluated.
> This seems ideal and is so simple that even I can understand it :-)
> But what I need to work out (or be told by some kind soul... hint...)
> is how to link to this at the client code level.
>
> Michael
>
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
------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users