10

I'm using the standalone GeoWebCache to serve tiles from a remote GeoServer. My problem is that the polygon label is added to each one of the tiles served, instead of only once in the polygon centroid.

I found a post which discusses the issue:
http://osgeo-org.1560.n6.nabble.com/polygon-label-repeated-for-each-tile-td4995203.html

The first reply mentioned a possible solution:

"All in all, I suggest to use a tile rendering engine (GeoWebCache, MapProxy, TileCache) anyway, instead of requesting small image from GeoServer and have the tile rendering engine do the tile slicing afterwards. You will have send fewer requests to GeoServer (1 large image instead of multiple small images), so this speeds up the overall tile cache creation time."

Problem is that I couldn't find how to do that by referring to the GeoWebCache documentation, and the above mentioned post doesn't explain the way to implement that.

I also found a post with an answer that links to the GeoWebCache "Tiled" documentation, but my code allready uses all the necessary attributes and still the label shows up multiple times:

var Layer_1874 = new OpenLayers.Layer.WMS(
    'Grundkort',
    '/wms10.ashx'
    , {
        format: 'image/png',
        srs: 'EPSG:25832',
        layers: 'ballerupkommune_grundkort_bk',
        tiled: true,
        tilesOrigin: '698804,6173460'
    }
    , {
        displayInLayerSwitcher: true,
        isBaseLayer: true,
        transitionEffect: 'resize',
        displayOutsideMaxExtent: true,
        visibility: false
    }
);

Anyone has an idea?

  • Can you show us the SLD file that you are using? That controls how labels are displayed on a WMS layer. – katahdin Oct 20 '12 at 20:28
15

Below is an example of an SLD rule that places a label at the center of a feature's geometry. This uses the ogc:Function called "centroid" to place the label. You can read more about SLD functions in the GeoServer docs, and some examples are given here.

<sld:Rule>
      <MaxScaleDenominator>5000</MaxScaleDenominator>
      <sld:TextSymbolizer>
        <sld:Geometry>
          <ogc:Function name="centroid">
            <ogc:PropertyName>the_geom</ogc:PropertyName>
          </ogc:Function>
        </sld:Geometry>
        <sld:Label>
          <ogc:PropertyName>LOT_NAME</ogc:PropertyName>
        </sld:Label>
        <sld:Font>
          <sld:CssParameter name="font-family">Arial</sld:CssParameter>
          <sld:CssParameter name="font-size">11</sld:CssParameter>
          <sld:CssParameter name="font-style">normal</sld:CssParameter>
          <sld:CssParameter name="font-weight">bold</sld:CssParameter>
        </sld:Font>
        <sld:LabelPlacement>
          <sld:PointPlacement>
            <sld:AnchorPoint>
              <sld:AnchorPointX>
                <ogc:Literal>0.0</ogc:Literal>
              </sld:AnchorPointX>
              <sld:AnchorPointY>
                <ogc:Literal>0.5</ogc:Literal>
              </sld:AnchorPointY>
            </sld:AnchorPoint>
            <sld:Rotation>
              <ogc:Literal>0</ogc:Literal>
            </sld:Rotation>
          </sld:PointPlacement>
        </sld:LabelPlacement>
        <sld:Halo>
          <sld:Radius>
            <ogc:Literal>1.0</ogc:Literal>
          </sld:Radius>
          <sld:Fill>
            <sld:CssParameter name="fill">#FFFFFF</sld:CssParameter>
          </sld:Fill>
        </sld:Halo>
        <sld:VendorOption name="conflictResolution">true</sld:VendorOption>
        <sld:VendorOption name="goodnessOfFit">0</sld:VendorOption>
        <sld:VendorOption name="autoWrap">60</sld:VendorOption>
      </sld:TextSymbolizer>
    </sld:Rule>

Also, the SLD Cookbook is a great reference. One thing that can trip you up is the ordering of tags in the SLD. For the TextSymbolizer rule above you can see required order by looking in the schema definition. Don't worry, it's not too scary! Just search for "textsymbolizer" in that .xsd file, an you should easily find the "sequence" tag. There you'll find that the element references match up with the order in my example. (Note: I didn't use the text symbolizer's "fill" attribute, my fill just applies to the halo.)

1

Computing labels with collision resolution (moving labels out of the way or removing lower priority ones so they don't overlap) requires knowing about every label that might collide with the label you are drawing, every label that might collide with them, and so on. So, in general, you either need to compute all the labels at once by looking at every feature, or break the map into blocks with labels computed within each block.

By default, GeoWebCache uses a 4x4 block of tiles called a "metatile". When you request a tile that isn't in the cache, GWC will request the entire metatile as one big image from the backend and then slice the metatile into tiles which it caches. You can adjust the metatile factor when setting up a layer. Larger metatiles give better looking labels, but increase the latency of a cache miss. If you aren't using label collision resolution on the back end, you can set the metatiling to 1x1.

You can also tell GWC to add a gutter around the metatile which is extra space that will be cut off. It's risky to do this if you have label collision resolution on as a label may be positioned differently or even be removed entirely on the other side of a metatile boundary. If you have labels that are totally fixed in position and never get supressed to avoid collision though, you can use a wide gutter to allow the labels to cross tile boundaries. This will have a performance cost as GeoServer will have to render a larger tile.

You can set metatiling and gutter on the Tile Layer tab of the layer configuration, or the default that will be used for new layers can be set on the Caching Defaults page.

To disable conflict resolution, you can use the conflictResolution vendor option in your styles.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.