geotools-gt2-users

Hi everyone,
I'm using geotools 2.5 and I try to set styles programmatically, from
examples provided on the geotools tutorials (like here http://docs.codehaus.org/display/GEOTDOC/05+Style
or there http://docs.codehaus.org/display/GEOTDOC/09+ShapeLab)
In both cases, a lot of methods seem to be deprecated and "will be
replaced by live lists in 2.6.x". As Geotools 2.6 is not stable yet,
what is the best solution to define styles without depending on these
deprecated methods ?
Any example of code would be greatly appreciated
Benoît

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

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

Hi Benoit,
There is a back door...
Instead of...
style.addFeatureTypeStyle(fts);
...which is deprecated, you can do this...
((List<FeatureTypeStyle>)style.featureTypeStyles()).add(fts);
...which is ugly, but not deprecated :-)
I've no idea whether that is 'bad practice' or not
Michael

2009/2/19 Benoît Thiébault <thiebault@...>:
> Hi Michael,
>
> I tryed this but it seems the featureTypeStyles() method doesn't exist...
> I'm using geotools 2.5.1
> Should I update geotools to a more recent version ?
> Is changing the pom.xml file all I have to do for this ?
>
Oops - my mistake Benoît. I was looking at the 2.6 code. I just
checked and that method isn't in 2.5.3 either so you'd have to swap to
2.6 to use it, which you probably don't want to do.
Sorry about that.
Michael

In general the methods marked as deprecated as "setters". In GeoTools 2.6 we
are experimenting with making the styles immutable (after you create them
you cannot change them). This makes things easier when we are writing a fast
renderer; if the style is not changing as we are drawing with it!
I am not sure there is a good solution here; the best way would be to define
all the parameters as you create the style; but I am not sure the geotools
StyleFactory create methods are complete in this respect.
Jody
On Tue, Feb 17, 2009 at 1:38 AM, Benoît Thiébault <thiebault@...>wrote:
> Hi everyone,
>
> I'm using geotools 2.5 and I try to set styles programmatically, from
> examples provided on the geotools tutorials (like here
> http://docs.codehaus.org/display/GEOTDOC/05+Style
> or there http://docs.codehaus.org/display/GEOTDOC/09+ShapeLab)
>
> In both cases, a lot of methods seem to be deprecated and "will be
> replaced by live lists in 2.6.x". As Geotools 2.6 is not stable yet,
> what is the best solution to define styles without depending on these
> deprecated methods ?
>
> Any example of code would be greatly appreciated
>
> Benoît
>
> ------------------------------------------------------------------------------
> 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@...
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>

2009/2/23 Jody Garnett <jody.garnett@...>:
> I am not sure there is a good solution here; the best way would be to define
> all the parameters as you create the style; but I am not sure the geotools
> StyleFactory create methods are complete in this respect.
> Jody
>
They're not :)
For a user who isn't a Style expert (I put myself firmly in this
category) the API seems to say: thou shalt use SLD files. I'm not
saying this is intentional, just that that's the impression I think a
user gets at the moment.
As Benoît pointed out, you often don't want to SLD files.
Michael

Hi,
when i started playing with geootools with same purpose (dynamic SLDs)
I also had same issues. Havent done much since then, I hope these tips
you guys wrote here will help :)
I bookmarked this page while ago, might be helpfull:
http://eskopinski.blogspot.com/2008/11/criando-um-arquivo-sld-com-geotools.html
Cheers!
On Mon, Feb 23, 2009 at 9:09 AM, Michael Bedward
<michael.bedward@...> wrote:
> 2009/2/23 Jody Garnett <jody.garnett@...>:
>> I am not sure there is a good solution here; the best way would be to define
>> all the parameters as you create the style; but I am not sure the geotools
>> StyleFactory create methods are complete in this respect.
>> Jody
>>
>
> They're not :)
>
> For a user who isn't a Style expert (I put myself firmly in this
> category) the API seems to say: thou shalt use SLD files. I'm not
> saying this is intentional, just that that's the impression I think a
> user gets at the moment.
>
> As Benoît pointed out, you often don't want to SLD files.
>
> Michael
>
> ------------------------------------------------------------------------------
> 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@...
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
--
Ivan Grcic