1

I have set up GeoServer with PostgreSQL/PostGIS as database. Imported a country boundary shapefile into the database and published as WMS.
The data has got the Country name attribute in the "label" column.
I setup a map client using Openlayers, and it shows so many labels when zoomed in, one for each tile.

Can I publish the wms map as a Single Image, (without multiple image tiles) to avoid duplicate country name labels?

Or is there any other successful methods to do this in SLD?

I have read many answers and tried vendor options to correct this, nothing worked.
Some similar questions were seen as removed as duplicates, but sincerely, I got no solution for this duplicate label issue in GeoServer.

More Info: I am using GeoServer 2.7.0
Using openlayers javascript from :

http://openlayers.org/api/OpenLayers.js

And the Openlayers code is:

<script type="text/javascript">
    var map;
    function init() {
        map = new OpenLayers.Map({
            div: "map",
            projection: new OpenLayers.Projection("EPSG:900913"),
            controls: [],
            numZoomLevels: 8,
            maxZoomLevel: 16
        });
        var osm = new OpenLayers.Layer.OSM("Open Street");
        var gmap = new OpenLayers.Layer.Google("Google Streets");
        Layer1 = new OpenLayers.Layer.WMS("1648", "http://localhost:8080/geoserver/wms", 
        { layers: 'my_wor:Layer1', transparent: true },
        { isBaseLayer: false });

        Layer2 = new OpenLayers.Layer.WMS("2015", "http://localhost:8080/geoserver/wms", 
        { layers: 'my_wor:Layer2', transparent: true },
        { isBaseLayer: false });

        map.addLayers([gmap, osm, Layer1, Layer2]);

        map.addControl(new OpenLayers.Control.LayerSwitcher());
        map.addControl(new OpenLayers.Control.ScaleLine());
        map.addControl(new OpenLayers.Control.OverviewMap());
        map.addControl(new OpenLayers.Control.Navigation());
        map.addControl(new OpenLayers.Control.PanZoomBar());
</script>

See the SLD below, with the vendor options "group" is given true.

<?xml version="1.0" encoding="ISO-8859-1"?> <StyledLayerDescriptor version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <NamedLayer> <Name>Polygon with styled label</Name> <UserStyle> <Title>SLD Cook Book: Polygon with styled label</Title> <FeatureTypeStyle> <Rule> <PolygonSymbolizer> <Fill> <CssParameter name="fill">#FF0000</CssParameter> </Fill> <Stroke> <CssParameter name="stroke">#CCCCCC</CssParameter> <CssParameter name="stroke-width">1</CssParameter> </Stroke> </PolygonSymbolizer>
<TextSymbolizer> <Label> <ogc:PropertyName>label</ogc:PropertyName> </Label> <Font> <CssParameter name="font-family">Arial</CssParameter> <CssParameter name="font-size">12</CssParameter> <CssParameter name="font-style">normal</CssParameter> <CssParameter name="font-weight">bold</CssParameter> </Font> <LabelPlacement> <PointPlacement> <AnchorPoint> <AnchorPointX>0.5</AnchorPointX> <AnchorPointY>0.5</AnchorPointY> </AnchorPoint> </PointPlacement> </LabelPlacement> <Fill> <CssParameter name="fill">#000000</CssParameter> </Fill> <VendorOption name="autoWrap">160</VendorOption> <VendorOption name="repeat">0</VendorOption> <VendorOption name="group">true</VendorOption> <VendorOption name="labelAllGroup">false</VendorOption>
</TextSymbolizer> </Rule> </FeatureTypeStyle> </UserStyle> </NamedLayer> </StyledLayerDescriptor>

  • Well try with the Single Image, and see what happen.But it might be that you have multigeometries and that there is a label for each part of the multigeometries. Is this the case? – Djana Jul 14 '15 at 12:00
  • 1
    How to set up single image? I couldn't find a way in Geoserver admin. Yes,I am drawing a single multipolygon for the country. Does that make the problem? – OpenMapperz Jul 14 '15 at 14:45
  • Is this such a tough problem with label duplication or single image wms rendering in Geoserver? – OpenMapperz Jul 15 '15 at 11:57
4

I will try to be as clear as possible, but I am not sure I understood everything that your are asking. You might want to edit your post with additional information or a concrete example and the version of Geoserver you are using.


Problem 1: you have duplicate labels due to the tiling of your WMS request by OL

-> solution: in Open Layer, request a single WMS image (see example here http://openlayers.org/en/v3.1.1/examples/wms-image.html)


Problem 2: you have duplicate labels due to multi geometries

-> solution: use the vendor option group in Geoserver SLD

The group option allows displaying a single label for multiple features in a logical group.

(see here http://docs.geoserver.org/latest/en/user/styling/sld-reference/labeling.html)


These are not miracle solutions and you might still need to tweek your SLD to get exactly what you want.

EDIT – regarding Problem 2

A possible trick I used on a small dataset: manually delete the label value for the smaller entities of my multi-geometries. However, I would not consider this good practice.

Another trick would be to create a additional column in your database and to assign 1 (=need a label) and 0 (=does not need a label) and to use it in a conditional filter in SLD to tell Geoserver whether to draw a label or not


EDIT 2

(after the comment from @user30184 & @OpenMapperz)

This is the same example, but for OL3 here http://openlayers.org/en/master/examples/wms-image.html?q=wms

If you want to find the relevant syntax, look at the OL3 documentation. The relevant point here is to use the object ol.layer.Image with ol.layer.ImageWMS.

  • I have edited the question adding more details and code snippets. – OpenMapperz Jul 15 '15 at 17:39
  • 1
    The right term is "single tile" and here is on OpenLayers 2 example dev.openlayers.org/examples/single-tile.html. You can also compare tiled/single tile settings with the layer preview application (OL3) that comes with GeoServer. Open the advanced settings of the preview and you will see the menu. – user30184 Jul 16 '15 at 13:16
  • In Geoserver Layer preview(OL3), the code is like this: ` var untiled = new ol.layer.Image({ source: new ol.source.ImageWMS({ ratio: 1, url: 'localhost:8080/geoserver/myworkspace/wms', params: {'FORMAT': format, 'VERSION': '1.1.1', LAYERS: 'myworkspace:mylayername', STYLES: '', } }) }); ` What is the relevant syntax to take from this? – OpenMapperz Jul 20 '15 at 7:14
  • I had the problem of multiple labels on geoserver and openlayer set up changing to ol.layer.Image and ol.layer.ImageWMS solved the issue. – mapperx Jan 2 '18 at 19:37

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.