[Geoserver-users] Number of labels on a single polygon

Hi,

was there any method of controlling how many labels are set in one polygon. I am labeling polygons with TextSymbolizer in SLD and hope there would be exactly one label per one geometry. I tried grouping VendorOption, but I guess it's for the case of multiple geometries but only one label wanted.

       <TextSymbolizer>
          <Label>
            <ogc:PropertyName>attrname</ogc:PropertyName>
          </Label>
            <Font>
           <CssParameter name="font-family">/usr/java/latest/lib/verdana.ttf</CssParameter>
              <CssParameter name="font-style">normal</CssParameter>
              <CssParameter name="font-weight">normal</CssParameter>
              <CssParameter name="font-size">12</CssParameter>
            </Font>
          <Fill>
            <CssParameter name="fill">#FF0000</CssParameter>
            <CssParameter name="fill-opacity">1</CssParameter>
          </Fill>
          <VendorOption name="group">yes</VendorOption>
        </TextSymbolizer>

- mika -

Lehtonen, Mika ha scritto:

Hi,

was there any method of controlling how many labels are set in one polygon. I am labeling polygons with TextSymbolizer in SLD and hope there would be exactly one label per one geometry. I tried grouping VendorOption, but I guess it's for the case of multiple geometries but only one label wanted.

There is no way to label any geometry more than once atm.
At the moment I'm working on labelling long lines multiple times,
it's not easy but still approachable, you can just partition
the long line in parts along its length.
Labelling a (supposedly big) polygon multiple times is quite a bit
harder, how do you split the initial polygon in interesting parts
without spending an eternity doing so? Doing an on the fly
triangulation may be an answer, but traingulating all polygons
is going to be extremely expensive. Do you have any suggestions
on what approach could be taken?

Cheers
Andrea

--
Andrea Aime
OpenGeo - http://opengeo.org
Expert service straight from the developers.

Actually I wanted to do the opposite. But it turned out that the problem was not a server related but OpenLayers, as Tim Schaub told me:

Regarding labels, your WMS layer probably uses multiple tiles (unless you set singleTile to true). With multiple tile requests, the server treats each as independent, so it will faithfully label as many polygons as the tile bounds intersect.

- mika -

Andrea Aime kirjoitti:

Lehtonen, Mika ha scritto:

Hi,

was there any method of controlling how many labels are set in one polygon. I am labeling polygons with TextSymbolizer in SLD and hope there would be exactly one label per one geometry. I tried grouping VendorOption, but I guess it's for the case of multiple geometries but only one label wanted.

There is no way to label any geometry more than once atm.
At the moment I'm working on labelling long lines multiple times,
it's not easy but still approachable, you can just partition
the long line in parts along its length.
Labelling a (supposedly big) polygon multiple times is quite a bit
harder, how do you split the initial polygon in interesting parts
without spending an eternity doing so? Doing an on the fly
triangulation may be an answer, but traingulating all polygons
is going to be extremely expensive. Do you have any suggestions
on what approach could be taken?

Cheers
Andrea

Lehtonen, Mika ha scritto:

Actually I wanted to do the opposite. But it turned out that the problem was not a server related but OpenLayers, as Tim Schaub told me:

Regarding labels, your WMS layer probably uses multiple tiles (unless you set singleTile to true). With multiple tile requests, the server treats each as independent, so it will faithfully label as many polygons as the tile bounds intersect.

Ah sorry. Yeah, you can minimize the problem by using tile caching and meta-tiling. Or you can eliminate it completely by creating a layer
that's not tiled, and that only contains the labels.
Each time you move around OL should force the layer to be recomputed
and thus give you optimal labelling for the current map position.
I have never actually tried that, but should be working?

Cheers
Andrea

--
Andrea Aime
OpenGeo - http://opengeo.org
Expert service straight from the developers.

Andrea Aime kirjoitti:

Lehtonen, Mika ha scritto:

Actually I wanted to do the opposite. But it turned out that the problem was not a server related but OpenLayers, as Tim Schaub told me:

Regarding labels, your WMS layer probably uses multiple tiles (unless you set singleTile to true). With multiple tile requests, the server treats each as independent, so it will faithfully label as many polygons as the tile bounds intersect.

Ah sorry. Yeah, you can minimize the problem by using tile caching and meta-tiling. Or you can eliminate it completely by creating a layer
that's not tiled, and that only contains the labels.
Each time you move around OL should force the layer to be recomputed
and thus give you optimal labelling for the current map position.
I have never actually tried that, but should be working?

Yes, it truly is working fine! Even if you try to hide the label by panning the map so that the label should stay hide, it still jumps back into view. Excellent. Now I just can't even understand why was I to go use tiles when there are only couple of hundreds polygons styled very simple. I guess I can leave the labels and the polygons in the same layer without tiling and still get a satisfactory performance. Still, I am interested in getting to know the GeoWebCache.

thanks,
mika

Cheers
Andrea