[Geoserver-users] WMS labels

Greetings,

I’m trying to apply multiple fields to a label in my WMS. Let’s say I have a “mountain” feature. When I put it on my WMS layer, I want a label that contains both its name and its height. I also want to display this text on two lines: one line for the first field, another line for the second.

Example label:
Mount Everest
(8,848m)

I know that if I wanted the text on one line, I could use the “strConcat” function inside my label. But I really want the text put over two lines. Can this be accomplished using SLD and WMS?

Thanks,
Paul


More new features than ever. Check out the new AIM(R) Mail!

walrapaul@anonymised.com ha scritto:

Greetings,

I'm trying to apply multiple fields to a label in my WMS. Let's say I have a "mountain" feature. When I put it on my WMS layer, I want a label that contains both its name and its height. I also want to display this text on two lines: one line for the first field, another line for the second.

   Example label:
      Mount Everest
      (8,848m)

I know that if I wanted the text on one line, I could use the "strConcat" function inside my label. But I really want the text put over two lines. Can this be accomplished using SLD and WMS?

It is. To put text over two lines I think you have to use two separate
text symbolizers thought, one for the name and one for the height.
For the second, if you are using GeoServer 1.6.0rc2, you can
specify the label with the mixed syntax, for example:
<Label>(<ogc:propertyName>height</ogc:propertyName>m)</Label>

Unfortunately we have no filter function able to format a number
with the thousands separator you're looking for. To add this one
would have to code something in java, build geoserver and so on.

Cheers
Andrea

I've tried specifying multi-line WMS labels by using two
TextSymbolizer sections, and have tested it on GeoServer-1.5.4 and
GeoServer-1.6-RC2. But I can't get it to produce two labels. In both
versions, the WMS label only displays what was in the second
TextSymbolizer area. The first field is not displayed at all.

Here's a sample snippet from my SLD:

          ...
          <TextSymbolizer>
            <Label>
              <ogc:PropertyName>mountain_name</ogc:PropertyName>
            </Label>
            < Font>
              <CssParameter name="font-family">Courier</CssParameter>
              <CssParameter name="font-style">Normal</CssParameter>
              <CssParameter name="font-size">8</CssParameter>
            </ Font>
            <Fill>
              <CssParameter name="fill">#000000</CssParameter>
            </Fill>
          </TextSymbolizer>
          <TextSymbolizer>
            <Label><ogc:PropertyName>height</ogc:PropertyName></Label>
            < Font>
              <CssParameter name="font-family">Courier</CssParameter>
              <CssParameter name="font-style">Normal</CssParameter>
              <CssParameter name="font-size">8</CssParameter>
            </ Font>
            <Fill>
              <CssParameter name="fill">#000000</CssParameter>
            </Fill>
          </TextSymbolizer>
          ...

The resulting WMS label will only show the height field (the second
TextSymbolizer). Is there anything else I need to do in the SLD to
display both field labels?

Paul

aaime wrote:

walrapaul@anonymised.com ha scritto:

Greetings,

I'm trying to apply multiple fields to a label in my WMS. Let's say I
have a "mountain" feature. When I put it on my WMS layer, I want a label
that contains both its name and its height. I also want to display this
text on two lines: one line for the first field, another line for the
second.

   Example label:
      Mount Everest
      (8,848m)

I know that if I wanted the text on one line, I could use the
"strConcat" function inside my label. But I really want the text put
over two lines. Can this be accomplished using SLD and WMS?

It is. To put text over two lines I think you have to use two separate
text symbolizers thought, one for the name and one for the height.
For the second, if you are using GeoServer 1.6.0rc2, you can
specify the label with the mixed syntax, for example:
<Label>(<ogc:propertyName>height</ogc:propertyName>m)</Label>

Unfortunately we have no filter function able to format a number
with the thousands separator you're looking for. To add this one
would have to code something in java, build geoserver and so on.

Cheers
Andrea

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

--
View this message in context: http://www.nabble.com/WMS-labels-tp14667977p14699676.html
Sent from the GeoServer - User mailing list archive at Nabble.com.

Another possibility is to use a spatial view, through Postgres or
Oracle for instance, to accomplish this.
I am not sure if you are using a spatial database, but if so, you
might not have to code any Java, since it seems what you want to do
would be fairly trivial with the use of a view, or for performance
reasons, a materialized view or a trigger that would populate your
database with the combination of the two fields. I have used this
approach in some cases, and it works fine.

Regards,
Jason

On Jan 8, 2008 10:54 PM, pdub <walrapaul@anonymised.com> wrote:

I've tried specifying multi-line WMS labels by using two
TextSymbolizer sections, and have tested it on GeoServer-1.5.4 and
GeoServer-1.6-RC2. But I can't get it to produce two labels. In both
versions, the WMS label only displays what was in the second
TextSymbolizer area. The first field is not displayed at all.

Here's a sample snippet from my SLD:

          ...
          <TextSymbolizer>
            <Label>
              <ogc:PropertyName>mountain_name</ogc:PropertyName>
            </Label>
            < Font>
              <CssParameter name="font-family">Courier</CssParameter>
              <CssParameter name="font-style">Normal</CssParameter>
              <CssParameter name="font-size">8</CssParameter>
            </ Font>
            <Fill>
              <CssParameter name="fill">#000000</CssParameter>
            </Fill>
          </TextSymbolizer>
          <TextSymbolizer>
            <Label><ogc:PropertyName>height</ogc:PropertyName></Label>
            < Font>
              <CssParameter name="font-family">Courier</CssParameter>
              <CssParameter name="font-style">Normal</CssParameter>
              <CssParameter name="font-size">8</CssParameter>
            </ Font>
            <Fill>
              <CssParameter name="fill">#000000</CssParameter>
            </Fill>
          </TextSymbolizer>
          ...

The resulting WMS label will only show the height field (the second
TextSymbolizer). Is there anything else I need to do in the SLD to
display both field labels?

Paul

aaime wrote:
>
> walrapaul@anonymised.com ha scritto:
>> Greetings,
>>
>> I'm trying to apply multiple fields to a label in my WMS. Let's say I
>> have a "mountain" feature. When I put it on my WMS layer, I want a label
>> that contains both its name and its height. I also want to display this
>> text on two lines: one line for the first field, another line for the
>> second.
>>
>> Example label:
>> Mount Everest
>> (8,848m)
>>
>> I know that if I wanted the text on one line, I could use the
>> "strConcat" function inside my label. But I really want the text put
>> over two lines. Can this be accomplished using SLD and WMS?
>
> It is. To put text over two lines I think you have to use two separate
> text symbolizers thought, one for the name and one for the height.
> For the second, if you are using GeoServer 1.6.0rc2, you can
> specify the label with the mixed syntax, for example:
> <Label>(<ogc:propertyName>height</ogc:propertyName>m)</Label>
>
> Unfortunately we have no filter function able to format a number
> with the thousands separator you're looking for. To add this one
> would have to code something in java, build geoserver and so on.
>
> Cheers
> Andrea
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Geoserver-users mailing list
> Geoserver-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/geoserver-users
>
>

--
View this message in context: http://www.nabble.com/WMS-labels-tp14667977p14699676.html
Sent from the GeoServer - User mailing list archive at Nabble.com.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

_______________________________________________
Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

pdub ha scritto:

I've tried specifying multi-line WMS labels by using two
TextSymbolizer sections, and have tested it on GeoServer-1.5.4 and
GeoServer-1.6-RC2. But I can't get it to produce two labels. In both
versions, the WMS label only displays what was in the second
TextSymbolizer area. The first field is not displayed at all.

Here's a sample snippet from my SLD:

          ...
          <TextSymbolizer>
            <Label>
              <ogc:PropertyName>mountain_name</ogc:PropertyName>
            </Label>
            < Font>
              <CssParameter name="font-family">Courier</CssParameter>
              <CssParameter name="font-style">Normal</CssParameter>
              <CssParameter name="font-size">8</CssParameter>
            </ Font>
            <Fill>
              <CssParameter name="fill">#000000</CssParameter>
            </Fill>
          </TextSymbolizer>
          <TextSymbolizer>
            <Label><ogc:PropertyName>height</ogc:PropertyName></Label>
            < Font>
              <CssParameter name="font-family">Courier</CssParameter>
              <CssParameter name="font-style">Normal</CssParameter>
              <CssParameter name="font-size">8</CssParameter>
            </ Font>
            <Fill>
              <CssParameter name="fill">#000000</CssParameter>
            </Fill>
          </TextSymbolizer>
          ...

The resulting WMS label will only show the height field (the second
TextSymbolizer). Is there anything else I need to do in the SLD to
display both field labels?

Yes, given they are two labels you have to displace them so that they
don't cover each other, otherwise the label conflict resolution
algorithm will just pick one.

For example, adding the following two symbolizers to the "green"
style used by the tasmania states demo layer works for me (see the displacement in action):

<TextSymbolizer>
   <Label>
     <ogc:PropertyName>STATE</ogc:PropertyName>
   </Label>
   <Font>
     <CssParameter name="font-family">Arial</CssParameter>
     <CssParameter name="font-style">Normal</CssParameter>
     <CssParameter name="font-size">8</CssParameter>
   </Font>
   <Fill>
     <CssParameter name="fill">#000000</CssParameter>
   </Fill>
</TextSymbolizer>
<TextSymbolizer>
   <Label><ogc:PropertyName>COUNTRY</ogc:PropertyName></Label>
   <Font>
     <CssParameter name="font-family">Arial</CssParameter>
     <CssParameter name="font-style">Normal</CssParameter>
     <CssParameter name="font-size">8</CssParameter>
   </Font>
   <LabelPlacement>
     <PointPlacement>
       <Displacement>
         <DisplacementX>0</DisplacementX>
         <DisplacementY>-12</DisplacementY>
       </Displacement>
     </PointPlacement>
   </LabelPlacement>
   <Fill>
     <CssParameter name="fill">#000000</CssParameter>
   </Fill>
</TextSymbolizer>

I also tried out adding a newline inside the text using
the mixes syntax, but it's really our label renderer
that does not support newlines in a label (at least the
one in 1.6.x does not...)

Cheers
Andrea

Jason Pickering ha scritto:

Another possibility is to use a spatial view, through Postgres or
Oracle for instance, to accomplish this.
I am not sure if you are using a spatial database, but if so, you
might not have to code any Java, since it seems what you want to do
would be fairly trivial with the use of a view, or for performance
reasons, a materialized view or a trigger that would populate your
database with the combination of the two fields. I have used this
approach in some cases, and it works fine.

Hum Jason, did you try this out with newlines and it worked for you?

Using mixed syntax in 1.6.x works as well, for example:

<TextSymbolizer>
   <Label><ogc:PropertyName>STATE</ogc:PropertyName> - <ogc:PropertyName>COUNTRY</ogc:PropertyName></Label>
   <Font>
     <CssParameter name="font-family">Arial</CssParameter>
     <CssParameter name="font-style">Normal</CssParameter>
     <CssParameter name="font-size">8</CssParameter>
   </Font>
   <Fill>
     <CssParameter name="fill">#000000</CssParameter>
   </Fill>
</TextSymbolizer>

applied to Tasmania states actually displays a lable with a dash
in between the two properties, yet I've found no way to make it
work with a newline. In fact any attempt to specify a newline
(using an xml entity such as &#10:wink: fails.

I've created an issue to handle this:
http://jira.codehaus.org/browse/GEOS-1661

Cheers
Andrea