0

I tried to add external graphic element in TextSymbolizer of point layer as Geoserver 2.19, I got the following result

<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:se="http://www.opengis.net/se" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.1.0">
 <NamedLayer>
   <se:Name>pois_test</se:Name>
   <UserStyle>
     <se:Name>pois_test</se:Name>
     <se:FeatureTypeStyle>
       <se:Rule>
         <se:TextSymbolizer>
           <se:Geometry>
   <ogc:Function name="centroid">
     <ogc:PropertyName>the_geom</ogc:PropertyName>
   </ogc:Function>
 </se:Geometry>
           <se:Label>
             <ogc:PropertyName>name_en</ogc:PropertyName>
           </se:Label>
           <se:Font>
             <se:SvgParameter name="font-family">Calibri</se:SvgParameter>
             <se:SvgParameter name="font-size">13</se:SvgParameter>
           </se:Font>
           <se:LabelPlacement>
             <se:PointPlacement>
               <se:AnchorPoint>
        <se:AnchorPointX>
          <ogc:Literal>0.5</ogc:Literal>
        </se:AnchorPointX>
        <se:AnchorPointY>
          <ogc:Literal>1.0</ogc:Literal>
        </se:AnchorPointY>
      </se:AnchorPoint>
      <se:Displacement>
        <se:DisplacementX>
          <ogc:Literal>100</ogc:Literal>
        </se:DisplacementX>
        <se:DisplacementY>
          <ogc:Literal>100</ogc:Literal>
        </se:DisplacementY>
      </se:Displacement>   
             </se:PointPlacement>
           </se:LabelPlacement>
           <se:Fill>
             <se:SvgParameter name="fill">#000000</se:SvgParameter>
           </se:Fill>
           <se:Graphic>
             <se:ExternalGraphic>
<se:OnlineResource xlink:type="simple" xlink:href="http://localhost:8090/geoserver/styles/arabic/15.png"/>
<se:Format>image/png</se:Format>
               </se:ExternalGraphic>
             </se:Graphic>
           <se:Priority>
           <ogc:PropertyName>priority</ogc:PropertyName>
               </se:Priority>
           <se:VendorOption name="spaceAround">10</se:VendorOption>
           <se:VendorOption name="group">yes</se:VendorOption>
           <se:VendorOption name="autoWrap">100</se:VendorOption>
           <se:VendorOption name="conflictResolution">true</se:VendorOption>
           <se:VendorOption name="maxDisplacement">10</se:VendorOption>
            <se:VendorOption name="labelObstacle">true</se:VendorOption>                    
         </se:TextSymbolizer>
       </se:Rule>
     </se:FeatureTypeStyle>
   </UserStyle>
 </NamedLayer>
</StyledLayerDescriptor>

Is there any workaround to fix offset label from the graphic symbol?

4
  • This seems like an XY problem - could you describe what you are trying to do as well as what you have tried so far. It appears that GeoServer is doing exactly what you are asking. You have specified an offset and then said it can move by 10 pixels in any direction to improve the fit.
    – Ian Turton
    Commented Sep 21, 2021 at 15:29
  • I'm trying to prevent label from overlapping graphic icon
    – GIS Man
    Commented Sep 21, 2021 at 17:06
  • I changed displacement element value to reflect fix that, but unfortunately it's still exist
    – GIS Man
    Commented Sep 21, 2021 at 17:08
  • Then make the graphic a point and set label obstacle on the points
    – Ian Turton
    Commented Sep 21, 2021 at 18:18

1 Answer 1

0

What you are trying to do is usually solved using the label-obstacle vendorOption which is applied to a vector symbolizer to tell the label drawing code to avoid those features.

There is a detailed example in the GeoServer manual.

However, you could probably make your way work if you set displacement to be a simple negative Y (so you place the label below the graphic) with the anchor at the top middle of the label (X=0.5, Y=1) and remove the <se:VendorOption name="maxDisplacement">10</se:VendorOption> line as that allows the labelling code to move the label about (undoing the control you had). But you will have to move the graphic to a PointSymbolizer other wise it will always be drawn under your label (as that is the purpose of the graphic in a TextSymbolizer).

5
  • I used PointSymbolizer before and i found there is overlapping between each graphic, but when i used graphic in TextSymbolized, i found it fix overlapping between each graphic. that is why i am trying to use graphic inside TextSymbolizer,
    – GIS Man
    Commented Sep 22, 2021 at 9:15
  • BTW, I am using POIS layer that has millions of points and the space between each point about 1 to 5 meters.
    – GIS Man
    Commented Sep 22, 2021 at 9:20
  • that is why I found draw graphic inside TextSymbolyzer is the best solution for this case.
    – GIS Man
    Commented Sep 22, 2021 at 9:20
  • TextSymbolizer graphics will always be under the text, if you correctly use LabelObstacle it will never cover your symbol. Those are your two options - if you have too many points then set a scale dependency so as not to draw low priority points until you have zoomed in enough
    – Ian Turton
    Commented Sep 22, 2021 at 9:28
  • Ok thank you very much
    – GIS Man
    Commented Sep 22, 2021 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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