https://docs.geoserver.org/latest/en/user/styling/sld/cookbook/points.html#example-points-layer

给图层的样式添加文字标签

该标签在设定<TextSymbolizer>上 ,确定要在标签中显示的文本,在这种情况下,<ogc:PropertyName>num</ogc:PropertyName>是shp文件中的属性列的值。

<Fill> <CssParameter name=”fill”>#000000</CssParameter> </Fill>设置文本颜色。有关标签的所有其他详细信息均设置为渲染器默认值,这里是Times New Roman字体,黑色字体和10像素的字体大小。标签的左下方与该点的中心对齐。

  1.  
    <?xml version=”1.0″ encoding=”ISO-8859-1″?>
  2.  
    <StyledLayerDescriptor version=“1.0.0”
  3.  
    xsi:schemaLocation=“http://www.opengis.net/sld StyledLayerDescriptor.xsd”
  4.  
    xmlns=“http://www.opengis.net/sld”
  5.  
    xmlns:ogc=“http://www.opengis.net/ogc”
  6.  
    xmlns:xlink=“http://www.w3.org/1999/xlink”
  7.  
    xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”>
  8.  
    <NamedLayer>
  9.  
    <Name>Simple point</Name>
  10.  
    <UserStyle>
  11.  
    <Title>GeoServer SLD Cook Book: Simple point</Title>
  12.  
    <FeatureTypeStyle>
  13.  
    <Rule>
  14.  
    <PointSymbolizer>
  15.  
    <Graphic>
  16.  
    <Mark>
  17.  
    <WellKnownName>circle</WellKnownName>
  18.  
    <Fill>
  19.  
    <CssParameter name=“fill”>#FF0000</CssParameter>
  20.  
    </Fill>
  21.  
    </Mark>
  22.  
    <Size>6</Size>
  23.  
    </Graphic>
  24.  
    </PointSymbolizer>
  25.  
    <TextSymbolizer>
  26.  
    <Label>
  27.  
    <ogc:PropertyName>num</ogc:PropertyName>
  28.  
    </Label>
  29.  
    <Fill>
  30.  
    <CssParameter name=“fill”>#000000</CssParameter>
  31.  
    </Fill>
  32.  
    </TextSymbolizer>
  33.  
    </Rule>
  34.  
    </FeatureTypeStyle>
  35.  
    </UserStyle>
  36.  
    </NamedLayer>
  37.  
    </StyledLayerDescriptor>

将标签label放到点的上方

  1.  
    <?xml version=”1.0″ encoding=”ISO-8859-1″?>
  2.  
    <StyledLayerDescriptor version=“1.0.0”
  3.  
    xsi:schemaLocation=“http://www.opengis.net/sld StyledLayerDescriptor.xsd”
  4.  
    xmlns=“http://www.opengis.net/sld”
  5.  
    xmlns:ogc=“http://www.opengis.net/ogc”
  6.  
    xmlns:xlink=“http://www.w3.org/1999/xlink”
  7.  
    xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”>
  8.  
    <NamedLayer>
  9.  
    <Name>Simple point</Name>
  10.  
    <UserStyle>
  11.  
    <Title>GeoServer SLD Cook Book: Simple point</Title>
  12.  
    <FeatureTypeStyle>
  13.  
    <Rule>
  14.  
    <PointSymbolizer>
  15.  
    <Graphic>
  16.  
    <Mark>
  17.  
    <WellKnownName>circle</WellKnownName>
  18.  
    <Fill>
  19.  
    <CssParameter name=“fill”>#FF0000</CssParameter>
  20.  
    </Fill>
  21.  
    </Mark>
  22.  
    <Size>6</Size>
  23.  
    </Graphic>
  24.  
    </PointSymbolizer>
  25.  
    <TextSymbolizer>
  26.  
    <Label>
  27.  
    <ogc:PropertyName>name</ogc:PropertyName>
  28.  
    </Label>
  29.  
    <Font>
  30.  
    <CssParameter name=“font-family”>Arial</CssParameter>
  31.  
    <CssParameter name=“font-size”>12</CssParameter>
  32.  
    <CssParameter name=“font-style”>normal</CssParameter>
  33.  
    <CssParameter name=“font-weight”>bold</CssParameter>
  34.  
    </Font>
  35.  
    <LabelPlacement>
  36.  
    <PointPlacement>
  37.  
    <AnchorPoint>
  38.  
    <AnchorPointX>0.5</AnchorPointX>
  39.  
    <AnchorPointY>0.0</AnchorPointY>
  40.  
    </AnchorPoint>
  41.  
    <Displacement>
  42.  
    <DisplacementX>0</DisplacementX>
  43.  
    <DisplacementY>5</DisplacementY>
  44.  
    </Displacement>
  45.  
    </PointPlacement>
  46.  
    </LabelPlacement>
  47.  
    <Fill>
  48.  
    <CssParameter name=“fill”>#000000</CssParameter>
  49.  
    </Fill>
  50.  
    </TextSymbolizer>
  51.  
    </Rule>
  52.  
    </FeatureTypeStyle>
  53.  
    </UserStyle>
  54.  
    </NamedLayer>
  55.  
    </StyledLayerDescriptor>
  56.  

  57. 转自:https://blog.csdn.net/u014572215/article/details/108752687