稍微整理一下geoserver配置style的几种样式
首先,配置geoserver图层样式,可以手写sld文件,或者通过一些工具辅助(QGIS或者udig都可以)。
第二,能够稍微阅读一下http://docs.geoserver.org/2.5.x/en/user/styling/index.html这里面的api。
未完待续,明天提供事例
事例1
图层介绍:
事例1图层是完整的一个shp图层,其中根据name属性可以划分四种类别。具体style可以用以下代码实现。
<?xml version=”1.0″ encoding=”GB2312″?>
<StyledLayerDescriptor version=”1.0.0″ 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”
xsi:schemaLocation=”http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd”>
<NamedLayer>
<Name>Attribute-based line</Name>
<UserStyle>
<Title>SLD Cook Book: Attribute-based line</Title>
<FeatureTypeStyle>
<Rule>
<Name>遗产区</Name>
<ogc:Filter>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>Layer</ogc:PropertyName>
<ogc:Literal>遗产区</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<LineSymbolizer>
<Stroke>
<CssParameter name=”stroke”>#ff00ff</CssParameter>
<CssParameter name=”stroke-width”>1</CssParameter>
</Stroke>
</LineSymbolizer>
</Rule>
</FeatureTypeStyle>
<FeatureTypeStyle>
<Rule>
<Name>保护区</Name>
<ogc:Filter>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>Layer</ogc:PropertyName>
<ogc:Literal>保护区</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<LineSymbolizer>
<Stroke>
<CssParameter name=”stroke”>#ff0000</CssParameter>
<CssParameter name=”stroke-width”>1</CssParameter>
</Stroke>
</LineSymbolizer>
</Rule>
</FeatureTypeStyle>
<FeatureTypeStyle>
<Rule>
<Name>缓冲区</Name>
<ogc:Filter>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>Layer</ogc:PropertyName>
<ogc:Literal>缓冲区</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<LineSymbolizer>
<Stroke>
<CssParameter name=”stroke”>#0000ff</CssParameter>
<CssParameter name=”stroke-width”>1</CssParameter>
</Stroke>
</LineSymbolizer>
</Rule>
</FeatureTypeStyle>
<FeatureTypeStyle>
<Rule>
<Name>建设控制地带</Name>
<ogc:Filter>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>Layer</ogc:PropertyName>
<ogc:Literal>建设控制地带</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<LineSymbolizer>
<Stroke>
<CssParameter name=”stroke”>#007f00</CssParameter>
<CssParameter name=”stroke-width”>1</CssParameter>
</Stroke>
</LineSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
事例2
事例2:色带主要特点与1差不多,都是要进行过滤特定字段,然后赋予不同颜色。此图层是在“字段”下有1、2这两条属性,所以只需要把这个字段过滤出来,然后分别赋予不同颜色就ok了(以下xml中的蓝色颜色的代码就是上面两句话的解释)
<?xml version=”1.0″ encoding=”UTF-8″?>
<StyledLayerDescriptor xmlns=”http://www.opengis.net/sld” xmlns:ogc=”http://www.opengis.net/ogc” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” version=”1.1.0″ 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:se=”http://www.opengis.net/se”>
<NamedLayer>
<se:Name>国界色带</se:Name>
<UserStyle>
<se:Name>国界色带</se:Name>
<se:FeatureTypeStyle>
<se:Rule>
<se:Name>1</se:Name>
<se:Description>
<se:Title>1</se:Title>
</se:Description>
<ogc:Filter xmlns:ogc=”http://www.opengis.net/ogc”>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>名称</ogc:PropertyName>
<ogc:Literal>1</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<se:PolygonSymbolizer>
<se:Fill>
<se:SvgParameter name=”fill”>#E4B3FF</se:SvgParameter>
</se:Fill>
</se:PolygonSymbolizer>
</se:Rule>
<se:Rule>
<se:Name>2</se:Name>
<se:Description>
<se:Title>2</se:Title>
</se:Description>
<ogc:Filter xmlns:ogc=”http://www.opengis.net/ogc”>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>名称</ogc:PropertyName>
<ogc:Literal>2</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<se:PolygonSymbolizer>
<se:Fill>
<se:SvgParameter name=”fill”>#F2D9FF</se:SvgParameter>
</se:Fill>
</se:PolygonSymbolizer>
</se:Rule>
</se:FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
转载自:https://mtr-1.oss-cn-beijing.aliyuncs.com/qyblog/2019/04/40401243.jpg