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 ? For now, my filter function takes two arguments: the feature attribute name and the format pattern (##.## for instance). I don't know however how the function interacts with the style... which leads to my second question
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), "");
NumberFormatFunction.java
Description: Binary data
Thanks for your help Le 24 févr. 09 à 14:03, Andrea Aime a écrit :
Jody Garnett wrote:Okay cool; so have you tried the text symbolizer offset yet? Setting an offset should allow you to draw above or below the line. There is also a rendering hint that can be used to make the text follow the line; I am not sure if that only changes orientation or if it also would calculate an offset?Follow line hint only helps if you need your text to follow the shape of a curved line, no help here.Benoit, are you sure you set your AnchorX to 0.5? That's all you should need to get you centering. If not, please create a bug report on jira.codehaus.org with a reproducable program that I can run to replicate and fix the bug.For formatting text to 2 decimals we'd need a formatting filter function, something that you could call like this: <Function name="numberFormat"> <PropertyName>myAtt</PropertyName> <Literal>###.##</Literal> </Function>to specify which attribute to use, and which pattern to use, respectively. As far as I remember there is no such a function,but it's not hard to make one, just have a look at the filterfunctions contained in the main module (e.g, FilterFunction_strLength),and their SPI registration in META-INF/services (to have GeoTools recognize them as plugins and thus don't throw and exception when you try to create an instance of your function using the filter factory). Oh, if you make that one, it's kind of general use, so consider contributing it back. 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
