Geoserver如何让图层标注基于规则显示
一、模拟需求
让图层标注根据不同比例尺度显示不同的标注及样式。
二、示例演示
1.数据表准备
说明:我准备了三个字段来操作,你也可以一个字段,后面可以用过滤来区分字段内容
2.打开QGIS,打开图层属性
3.选择标注,基于规则标注
花点时间,每个tap都点开看看呗,按自己需求设置
操作如下图
4.QGIS效果
large
middle
small
上面示例,标注大小样式我没认真调,小伙伴们可以按自己需求DIY哦~
5.保存样式
6.加载至geoserver样式
7.图层预览
注意得是你设置样式的这个图层哦~
其它图层的话可能就得更改图层字段名或者sld文本里的标签名了
点击查看代码
<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" xmlns:ogc="http://www.opengis.net/ogc" version="1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:se="http://www.opengis.net/se" xmlns:xlink="http://www.w3.org/1999/xlink">
<NamedLayer>
<se:Name>zsc_label</se:Name>
<UserStyle>
<se:Name>zsc_label</se:Name>
<se:FeatureTypeStyle>
<se:Rule>
<se:Name>Single symbol</se:Name>
<se:PointSymbolizer>
<se:Graphic>
<se:Mark>
<se:WellKnownName>circle</se:WellKnownName>
<se:Fill>
<se:SvgParameter name="fill">#e77148</se:SvgParameter>
</se:Fill>
<se:Stroke>
<se:SvgParameter name="stroke">#232323</se:SvgParameter>
<se:SvgParameter name="stroke-width">0.5</se:SvgParameter>
</se:Stroke>
</se:Mark>
<se:Size>7</se:Size>
</se:Graphic>
</se:PointSymbolizer>
</se:Rule>
<se:Rule>
<se:MaxScaleDenominator>100000</se:MaxScaleDenominator>
<se:TextSymbolizer>
<se:Label>
<ogc:PropertyName>large</ogc:PropertyName>
</se:Label>
<se:Font>
<se:SvgParameter name="font-family">微软雅黑</se:SvgParameter>
<se:SvgParameter name="font-size">13</se:SvgParameter>
<se:SvgParameter name="font-weight">bold</se:SvgParameter>
</se:Font>
<se:LabelPlacement>
<se:PointPlacement>
<se:AnchorPoint>
<se:AnchorPointX>0</se:AnchorPointX>
<se:AnchorPointY>0.5</se:AnchorPointY>
</se:AnchorPoint>
</se:PointPlacement>
</se:LabelPlacement>
<se:Halo>
<se:Radius>2</se:Radius>
<se:Fill>
<se:SvgParameter name="fill">#000000</se:SvgParameter>
</se:Fill>
</se:Halo>
<se:Fill>
<se:SvgParameter name="fill">#ffffff</se:SvgParameter>
</se:Fill>
<se:VendorOption name="maxDisplacement">1</se:VendorOption>
</se:TextSymbolizer>
</se:Rule>
<se:Rule>
<se:MinScaleDenominator>1000000</se:MinScaleDenominator>
<se:TextSymbolizer>
<se:Label>
<ogc:PropertyName>small</ogc:PropertyName>
</se:Label>
<se:Font>
<se:SvgParameter name="font-family">微软雅黑</se:SvgParameter>
<se:SvgParameter name="font-size">13</se:SvgParameter>
</se:Font>
<se:LabelPlacement>
<se:PointPlacement>
<se:AnchorPoint>
<se:AnchorPointX>0</se:AnchorPointX>
<se:AnchorPointY>0.5</se:AnchorPointY>
</se:AnchorPoint>
</se:PointPlacement>
</se:LabelPlacement>
<se:Halo>
<se:Radius>2</se:Radius>
<se:Fill>
<se:SvgParameter name="fill">#000000</se:SvgParameter>
</se:Fill>
</se:Halo>
<se:Fill>
<se:SvgParameter name="fill">#fcf40b</se:SvgParameter>
</se:Fill>
<se:VendorOption name="maxDisplacement">1</se:VendorOption>
</se:TextSymbolizer>
</se:Rule>
<se:Rule>
<se:MinScaleDenominator>100000</se:MinScaleDenominator>
<se:MaxScaleDenominator>1000000</se:MaxScaleDenominator>
<se:TextSymbolizer>
<se:Label>
<ogc:PropertyName>middle</ogc:PropertyName>
</se:Label>
<se:Font>
<se:SvgParameter name="font-family">微软雅黑</se:SvgParameter>
<se:SvgParameter name="font-size">20</se:SvgParameter>
<se:SvgParameter name="font-weight">bold</se:SvgParameter>
</se:Font>
<se:LabelPlacement>
<se:PointPlacement>
<se:AnchorPoint>
<se:AnchorPointX>0</se:AnchorPointX>
<se:AnchorPointY>0.5</se:AnchorPointY>
</se:AnchorPoint>
</se:PointPlacement>
</se:LabelPlacement>
<se:Halo>
<se:Radius>2</se:Radius>
<se:Fill>
<se:SvgParameter name="fill">#000000</se:SvgParameter>
</se:Fill>
</se:Halo>
<se:Fill>
<se:SvgParameter name="fill">#160be7</se:SvgParameter>
</se:Fill>
<se:VendorOption name="maxDisplacement">1</se:VendorOption>
</se:TextSymbolizer>
</se:Rule>
</se:FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>