[udig-devel] SLD: How to combine different feature attributes for a TextSymbolizer

Jody Garnett jgarnett at refractions.net
Wed Jun 6 12:55:42 PDT 2007


You got it figured ...

If we did a better job at implementing things on our end it would of 
been easier for you :-)

Jody

> I used FilterFunction_strConcat. Which Function do you mean? Where can 
> I find it?
> Somehow I didn't understand what you want to tell me but I guessed the 
> following and it works:
>  
> instead of creating an expression[] array with a size depending of the 
> number of attributes the user wants shown in the map I defined a 
> recursive function in which a FilterFunction_strConcat gets an 
> expression[] with size=2 containing an attributeexpression (an 
> attribute) or a literalexpression (the seperator ";") and as 
> second  element another FilterFunction_strConcat or (if it's the last 
> element) an attributeexpression.
> The recursive function finally generates an expression which is used 
> to create the TextSymbolizer. And it works perfectly.
>  
> Which means that the FilterFunction_strConcat.setArgs(Expression[]) 
> only works for arrays with two elements.
>  
> tony roth
>
>
>     Looks like there is a String concatenate function you could call
>     as well
>     in order to get what you want ... because of the annoying way the SLD
>     specification is written we need to have each function be unique
>     in name
>     and number of parameters.
>
>     So we have the "strConcat" function ... you will need to nest it
>     to get
>     what you want ....
>
>     Cheers.
>     Jody
>
>
>     > Hi list,
>     > I want to show a set of feature attributes (all Strings) as one
>     > label in the map next to the point/graphic. Like "1; London; 12"
>     > (number of item, name and a status). Since the user can toggle
>     check
>     > boxes to switch on/off single values I can not store all
>     information
>     > in one feature attribute. Instead of this I have n (currently 5)
>     > feature attributes for this. This is the way I thought it's the
>     > correct one:
>     >  
>     > ---- code ----
>     > // after each attribute except the last one a seperator like ";"
>     > // textAttributes is a List of attributes the user wants to be shown
>     > // Attributes is a enum with all attributes
>     > Expression[] expressions = new
>     Expression[textAttributes.size()*2-1];
>     >       int i = 0;
>     >       for (Attributes a : Attributes.values()){
>     >        if (textAttributes.contains(a)){
>     > // attribute expression for the attribute
>     >         Expression attributeExpression =
>     >
>     FilterFactoryFinder.createFilterFactory().createAttributeExpression(a.name());
>     > // literal expression for the seperator
>     >         LiteralExpression seperator =
>     >
>     FilterFactoryFinder.createFilterFactory().createLiteralExpression(";");
>     >         expressions[i++]=attributeExpression;
>     >         if (i>          expressions[i++]=seperator;
>     >         }
>     >        }
>     >       }
>     > // Filter to concatenate strings
>     >       FilterFunction_strConcat concatFunction = new
>     > FilterFunction_strConcat();
>     >       concatFunction.setArgs(expressions);
>     > // create TextSymbolizer (fill and font are handled above... not
>     > interesting here)
>     >       myStyleBuilder.createTextSymbolizer(fill, new Font[]
>     > {gtFont},null, concatFunction, placement, null));
>     > ---- code ----
>     > My first problem was to find a possibility to concatenate strings.
>     > Since
>     >
>     http://udig.refractions.net/docs/api-geotools/org/geotools/filter/function/FilterFunction_strConcat.htmlhas
>
>     > a very poor javadoc explanation I just guessed that this
>     function is
>     > the correct one.
>     >  
>     > What happend?
>     > Independet of the number of attributes I want to show (2,3,4,5)
>     only
>     > the first attribute combined with the first seperator (";") is
>     drawn.
>     > So I got "London;" instead of "London;1;3". If I flip the order of
>     > attributes I get "1;" instead of "1;London;3". As I said only the
>     > first two expressions (one attribute, one literal) are included.
>     Since
>     > these two are included I guess that the FilterFunction_strConcat is
>     > the correct way. Can someone help me with this?
>     > I debuged it and the expressions array is build correct, has no
>     null
>     > elements and all seems ok.
>     >  
>     > Thank you,
>     > tony roth
>     >
>     ------------------------------------------------------------------------
>     >
>     > _______________________________________________
>     > User-friendly Desktop Internet GIS (uDig)
>     > http://udig.refractions.net <http://udig.refractions.net/>
>     > http://lists.refractions.net/mailman/listinfo/udig-devel
>     >  
>
>     _______________________________________________
>     User-friendly Desktop Internet GIS (uDig)
>     http://udig.refractions.net <http://udig.refractions.net/>
>     http://lists.refractions.net/mailman/listinfo/udig-devel
>
>
> INVALID HTML
> ------------------------------------------------------------------------
>
> _______________________________________________
> User-friendly Desktop Internet GIS (uDig)
> http://udig.refractions.net
> http://lists.refractions.net/mailman/listinfo/udig-devel
>   



More information about the udig-devel mailing list