2

I am trying to avoid drawing overlapping labels with vendor parameters. I tried below option in different versions of Geoservers (2.2.1 to 2.5.2), its not working.

http://docs.geoserver.org/2.5.x/en/user/styling/sld-extensions/label-obstacles.html

My style is given below.

I have added vendor parameter in Pointsymboliser after element.

Point_rule1

       <PointSymbolizer>
           <Graphic>
               <ExternalGraphic>
                   <OnlineResource  xlink:type="simple" xlink:href="city.svg" />
                 <Format>image/svg+xml</Format>
                </ExternalGraphic>
              <Size>8</Size>
             </Graphic>
              <VendorOption name="labelObstacle">true</VendorOption>
         </PointSymbolizer>


 <TextSymbolizer>
          <Label>
            <ogc:PropertyName>NAME</ogc:PropertyName>
          </Label>
          <Font>
            <CssParameter name="font-family">
             <ogc:Literal>Arial</ogc:Literal>
            </CssParameter>
              <CssParameter name="fill-opacity">0.2</CssParameter>
            <CssParameter name="font-style">bold</CssParameter>
            <CssParameter name="font-size">9</CssParameter>
            <CssParameter name="font-weight">Normal</CssParameter>
          </Font>
          <LabelPlacement>
            <PointPlacement> 
              <AnchorPoint>
                <AnchorPointX><ogc:Literal>0.0</ogc:Literal></AnchorPointX> 
                <AnchorPointY><ogc:Literal>0.0</ogc:Literal></AnchorPointY>
              </AnchorPoint>
             <Displacement>
                <DisplacementX><ogc:Literal>8</ogc:Literal></DisplacementX>  
                <DisplacementY><ogc:Literal>0</ogc:Literal></DisplacementY> 
              </Displacement>
              <Rotation><ogc:Literal>0</ogc:Literal></Rotation>
            </PointPlacement>
          </LabelPlacement>
          <Halo>
            <Radius><ogc:Literal>1</ogc:Literal></Radius>
            <Fill>
              <CssParameter name="fill">#FFFFFF</CssParameter>
              <CssParameter name="fill-opacity">1</CssParameter>
            </Fill>
          </Halo>
          <Fill><CssParameter name="fill">#333333</CssParameter></Fill>

         <VendorOption name="goodnessOfFit">1.2</VendorOption>
         <VendorOption name="removeOverlaps">true</VendorOption>
         <VendorOption name="labelObstacle">true</VendorOption>
        </TextSymbolizer>


      </Rule>
    </FeatureTypeStyle>
</UserStyle>

Anyone implemented this vendor option successfully?

2
1

I took the "tiger_roads.sld" from the default data_dir and modified it to add a symbol "burg02.svg" with the labelObstacle vendor option and it does seem to work for me with GeoServer 2.6

Without labelObstacle:

without labelOstacle

With labelObstacle:

with labelObstacle

<?xml version="1.0" encoding="UTF-8"?>
<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> area landmarks </Name>
    <UserStyle>

         <FeatureTypeStyle>
            <FeatureTypeName>Feature</FeatureTypeName>
            <Rule>  
                   <MinScaleDenominator>32000</MinScaleDenominator>
                   <LineSymbolizer>
                       <Stroke>
                        <CssParameter name="stroke">
                            <ogc:Literal>#666666</ogc:Literal>
                        </CssParameter>
                        <CssParameter name="stroke-width">
                            <ogc:Literal>2</ogc:Literal>
                        </CssParameter>
                    </Stroke>
                   </LineSymbolizer>
            </Rule>

            <Rule>  <!-- thick line drawn first-->
                <MaxScaleDenominator>32000</MaxScaleDenominator>
                <LineSymbolizer>
                    <Stroke>
                        <CssParameter name="stroke">
                            <ogc:Literal>#666666</ogc:Literal>
                        </CssParameter>
                        <CssParameter name="stroke-width">
                            <ogc:Literal>7</ogc:Literal>
                        </CssParameter>
                    </Stroke>
                </LineSymbolizer>
            </Rule>
        </FeatureTypeStyle>
        <FeatureTypeStyle>
           <FeatureTypeName>Feature</FeatureTypeName>
           <Rule>   <!-- thin line drawn second -->
                <MaxScaleDenominator>32000</MaxScaleDenominator>
                <LineSymbolizer>
                       <Stroke>
                        <CssParameter name="stroke">
                            <ogc:Literal>#FFFFFF</ogc:Literal>
                        </CssParameter>
                        <CssParameter name="stroke-width">
                            <ogc:Literal>4</ogc:Literal>
                        </CssParameter>
                    </Stroke>
                </LineSymbolizer>
            </Rule> 
           <Rule> <!-- test with labelObstacle here -->
      <PointSymbolizer>
        <Graphic>
          <ExternalGraphic>
            <OnlineResource
              xlink:type="simple"
              xlink:href="burg02.svg" />
            <Format>image/svg</Format>
          </ExternalGraphic>
          <Size>32</Size>
        </Graphic>
       <VendorOption name="labelObstacle">true</VendorOption>
      </PointSymbolizer>
    </Rule>
            <!-- label -->     
            <Rule>
                <MaxScaleDenominator>32000</MaxScaleDenominator>
                <TextSymbolizer>
                    <Label>
                        <ogc:PropertyName>NAME</ogc:PropertyName>
                    </Label>

                    <Font>
                        <CssParameter name="font-family">Times New Roman</CssParameter>
                        <CssParameter name="font-style">Normal</CssParameter>
                        <CssParameter name="font-size">14</CssParameter>
                        <CssParameter name="font-weight">bold</CssParameter>
                    </Font>

                    <LabelPlacement>
                      <LinePlacement>
                      </LinePlacement>
                    </LabelPlacement>
                    <Halo>
                        <Radius>
                            <ogc:Literal>2</ogc:Literal>
                        </Radius>
                        <Fill>
                            <CssParameter name="fill">#FFFFFF</CssParameter>
                            <CssParameter name="fill-opacity">0.85</CssParameter>               
                        </Fill>
                    </Halo>

                    <Fill>
                        <CssParameter name="fill">#000000</CssParameter>
                    </Fill>

                    <VendorOption name="group">true</VendorOption>

                </TextSymbolizer>
            </Rule>
        </FeatureTypeStyle>

    </UserStyle>
    </NamedLayer>
</StyledLayerDescriptor>
3
  • Hi, Thankyou verymuch for answer. I am getting the following error (but it seems some environment/library related issue in my system. It was worked fine in other systems). line 66: cvc-complex-type.2.4.d: Invalid content was found starting with element 'VendorOption'. No child element is expected at this point.
    – Hari
    Oct 22 '14 at 10:45
  • I get the same error from the validator but if I still save the style it works.
    – user30184
    Oct 22 '14 at 10:54
  • Thats good. Its not working in my system. I will investigate it later.
    – Hari
    Oct 22 '14 at 11:21

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.