Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [udig-devel] SLD: How to combine different feature attributes for a TextSymbolizer

What you describe is supposed to work in the Filter specification right now .. but it is beyond the abilities of our current implementation.

Basically the <label> is allowed to be mixed text ....

<label><propertyName>number</propertyName>; <propertyName>London</propertyName>;<propertyName>size</propertyName></label>

For now just use three different text symbolizers, and position them so they do not overlap.

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.length){
         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.html has 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://lists.refractions.net/mailman/listinfo/udig-devel



Back to the top