Benoît Thiébault wrote:
> Hi everyone,
>
> As Andrea suggested, I'm trying to implement a formatting filter
> function that could be used in SLD files (or programmatically) to
> display text in a given format, like this :
>
> <Function name="numberFormat">
> <PropertyName>myAtt</PropertyName>
> <Literal>##.##</Literal>
> </Function>
>
> I have looked at existing functions and coded the function attached.
>
> However, I still have some questions to finish it.
>
> 1) I don't really know how to implement the evaluate(final Object
> object, final Class<T> context) method.
> What is the object parameter supposed to be ? A feature ? What should I
> return ?
You're not supposed to know. You have expressions as parameters,
evaluate the first against the object and ask for a String.class result
type, evaluate the second and do the same.
Then use the two results to perform the formatting, and return the
resulting value.
> 2) I dont' really know how to use the function in my programmatically
> built style. I have created a text symbolizer and successfully retrieved
> the function. But I don't know how to make the text symbolizer depend on
> my function result. Here is the code I have for now.
>
> StyleBuilder sb = new StyleBuilder();
> FilterFactory ff =
> CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints());
>
> Function format = null;
> try {
> format = ff.function("NumberFormat", ff
> .property("depth"), sb.literalExpression(".##"));
> } catch (Exception e) {
> logger.error(e);
> }
>
> org.geotools.styling.Font[] fontArray = { sb.createFont(new Font(
> "sansserif", Font.PLAIN, 12)) };
>
> TextSymbolizer text = sb.createTextSymbolizer(null, fontArray, null, sb
> .attributeExpression("depth"), sb.createPointPlacement(0.5,
> 0.0, 0.0), "");
The symbolizer must use the function as the source of the label, so you
should pass "format" instead of "sb.attributeExpression("depth")"
Cheers
Andrea
------------------------------------------------------------------------------
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