Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm using the standalone GeoWebCache to serv 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 repley mentuned 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 reffering to the GeoWebCache documentation, and the above mentuned 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?

Kind regards
Amit

share|improve this question
    
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

1 Answer 1

up vote 5 down vote accepted

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.)

share|improve this answer
    
Thanks @katahdin, that was great help. –  Ambran Oct 22 '12 at 8:08
    
Feel free to accept the answer if it helped. Cheers! –  katahdin Oct 22 '12 at 11:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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