Geoserver setting style

1 Background

We in ArcMap layers can be customized directly by symbol with map function. However, if we will shp layer with a good map published in GeoServer, you will find a layer style is completely lost. In fact, the reason is very simple, with a good layer using ArcMap, its style is not saved in shp file, but is stored in mxd or msd in.

So how can we make GeoServer release layer can also be customized with maps to reach the effect?

2 SLD Introduction

SLD is a stylized Layer Descriptor (Styled Layer Descriptor) for short, is a proposed standard in 2005 OGC, this standard allows WMS server under certain conditions, to map the visual manifestation of expansion. In the absence of SLD, you can only use some of the provisions have a good visual styles on a server on the map. And when used to achieve the SLD standard, which allows us to map to define your own style from the client, outline and other operations, which greatly expanded the map visualization flexibility.

The SLD- specification is defined using XML style map display, configured to render the map layer visualized by customizing the SLD style, a filter may be provided, custom legend like. rule is the most important element of the SLD, because she allows data sets are classified according to a given parameter (using filters), all the important parameters relating to the classification must be provided in the rule element.

For SLD to map custom style, you must use a combination of SE (Symbology Encoding) this standard. SE is another OGC standard, and this is also based on XML schema definition, the standard allows us to customize different styles to express different symbols on the map elements. SLD files using this language, so when the map is a map service rendered can be explained by a user-defined style.

SLD document architecture elements are as follows:

                       

A style SLD document contains a general part, but the most important are as follows:

FeatureTypeStyle: This part is the root of the whole style of the document and indicate what type it is characteristic of the style will be applied. FeatureTypeStyle contains one or more elements Rule, Rule element allows conditional mapping.

RULE (rule): scale rule is to group features rendering attribute conditions and according to the map, the general RULE only allows one type of render elements, in which a point, line, surface or the like, but may at the same time and annotation use.

Symbolizer (symbol): Symbolizer specified data should how to visualize, comprising five Zhong type Symbolizer 1.0 of the standard, respectively PointSymbolizer (dot notation), LineSymbolizer (line symbols), PloygonSymbolizer (face symbols), TextSymbolizer (annotation), RasterSymbolizer (grid).

More than just color and thickness can be provided by the SLD. Point may be provided common shape, such as round, square, star, or even a self-defined text or graphic image to specify; dashed lines may be rendered or dotted line and the like, may be filled polygon custom tile images, styles can be based on the attribute data of a given, so that the elements can

It is rendered into different styles.

Common parameters:

symbol

meaning

<Name>

Style Name

<FeatureTypeStyle>

Elements of style

<Rule>

rule

<Ogc: Filter>

filter

<ogc:PropertyIsBetween>

It used to define the filter between two attribute values

<ogc:PropertyIsLessThan>

Is used to define a property value is less than the filter

<ogc:PropertyIsGreaterThan>

Filters used to define an attribute value greater than

<ogc:PropertyName>

Property field name

<ogc:Literal>

Property Value

<PointSymbolizer>

Point marker

<LineSymbolizer>

Line markers

<PolygonSymbolizer>

Surface marker

<CssParameter   name="fill">

Fill Color

<CssParameter   name="font-family">

Fonts

<CssParameter   name="font-style">

Font style

<CssParameter   name="font-size">

font size

 

3 polygon layers, for example, explain in detail

3.1 Basic color fill

3.1.1 Structure

PolygonSymbolizer

 

……Fill

filling

………CssParameter  name="fill"

colour

………CssParameter  name="fill-opacity"

transparency

……Stroke

boundary

………CssParameter  name="stroke"

colour

………CssParameter  name="stroke-width"

width

3.1.2 Example

The boundary polygons with transparent

SLD:

<FeatureTypeStyle>
    <Rule>
        <PolygonSymbolizer>
        <Fill>
         <CssParameter   name="fill">#AAAAAA</CssParameter>
         <CssParameter   name="fill-opacity">0.5</CssParameter>
       </Fill>
       <Stroke>
        <CssParameter   name="stroke">#000000</CssParameter>
        <CssParameter   name="stroke-width">1</CssParameter>
      </Stroke>
     </PolygonSymbolizer>
    </Rule>
   </FeatureTypeStyle>

 

效果:

 

3.2图片填充

3.2.1结构

PolygonSymbolizer

 

……Fill

 

………GraphicFill

 

…………Graphic

 

……………ExternalGraphic

 

………………OnlineResource

图片来源

………………Format

图片格式

……………Size

大小

3.2.2示例

带有使用图片填充的多边形

SLD:

<FeatureTypeStyle>
    <Rule>
       <PolygonSymbolizer>

            <Fill>

              <GraphicFill>

                <Graphic>

                    <ExternalGraphic>

                     <OnlineResource xlink:type="simple"   xlink:href="20101.gif" />

                   <Format>image/gif</Format>

                    </ExternalGraphic>

                    <Size>20</Size>

                </Graphic>

              </GraphicFill>

            </Fill>

            <Stroke>

              <CssParameter   name="stroke">#000000</CssParameter>

              <CssParameter   name="stroke-width">1</CssParameter>

            </Stroke>

        </PolygonSymbolizer>

  </Rule>
   </FeatureTypeStyle>

效果:

 

3.3注记显示

3.2.1结构

TextSymbolizer

 

……Label

 

………ogc:PropertyName

注记的属性字段名称

……Font

字体

………CssParameter  name="font-family"

字体类型

………CssParameter  name="font-size"

字体大小

………CssParameter  name="font-style"

字体样式

………CssParameter  name="font-weight"

字体加粗

……LabelPlacement

注记的位置

………PointPlacement

注记点位置

…………AnchorPoint

 

……………AnchorPointX

 

……………AnchorPointY

 

…………Displacement

 

……………Displacement X

 

……………Displacement Y

 

…………Rotation

设置旋转角度

……Fill

填充

………CssParameter  name="fill"

填充颜色

3.2.2示例

带有注记的填充色透明的多边形

SLD:

 <TextSymbolizer>
         <Label>
             <ogc:PropertyName>COMNAME</ogc:PropertyName>
         </Label>
         <Font>
             <CssParameter name="font-family">
微软雅黑</CssParameter>
             <CssParameter name="font-size">15</CssParameter>
             <CssParameter name="font-style">normal</CssParameter>
             <CssParameter name="font-weight">bold</CssParameter>
         </Font>
         <LabelPlacement>
             <PointPlacement>
                  <AnchorPoint>
               <AnchorPointX>0.5</AnchorPointX>
               <AnchorPointY>0.5</AnchorPointY>
               </AnchorPoint>
             </PointPlacement>
         </LabelPlacement>
         <Fill>
             <CssParameter name="fill">#FF5226</CssParameter>
         </Fill>
         <VendorOption name="followLine">true</VendorOption>
    </TextSymbolizer> 

 

 

效果:

 

3.4 分属性渲染

3.4.1结构

PolygonSymbolizer

 

……Rule

 

………Filter

 

………PolygonSymbolizer

 

………TextSymbolizer

 

3.4.2示例

根据属性字段值范围用不同颜色渲染。

SLD:

<FeatureTypeStyle>

<Rule>

<Name>SmallCOMM</Name>

<Title>Less Than 510104024008</Title>

<ogc:Filter>

<ogc:PropertyIsLessThan>

<ogc:PropertyName>COMID</ogc:PropertyName>

<ogc:Literal>510104024008</ogc:Literal>

</ogc:PropertyIsLessThan>

</ogc:Filter>

<PolygonSymbolizer>

  <Fill>

 <CssParameter   name="fill">#66FF66</CssParameter>

 </Fill>

 </PolygonSymbolizer>

</Rule>

<Rule>

<Name>MediumCOMM</Name>

<Title>510104024008 to 510104024011</Title>

<ogc:Filter>

<ogc:And>

<ogc:PropertyIsGreaterThanOrEqualTo>

<ogc:PropertyName>COMID</ogc:PropertyName>

<ogc:Literal>510104024008</ogc:Literal>

</ogc:PropertyIsGreaterThanOrEqualTo>

<ogc:PropertyIsLessThan>

<ogc:PropertyName>COMID</ogc:PropertyName>

<ogc:Literal>510104024011</ogc:Literal>

</ogc:PropertyIsLessThan>

</ogc:And>

</ogc:Filter>

<PolygonSymbolizer>

<Fill>

<CssParameter name="fill">#33CC33</CssParameter>

</Fill>

</PolygonSymbolizer>

</Rule>

<Rule>

<Name>LargeCOMM</Name>

<Title>Greater Than 510104024011</Title>

<ogc:Filter>

<ogc:PropertyIsGreaterThan>

<ogc:PropertyName>COMID</ogc:PropertyName>

<ogc:Literal>510104024011</ogc:Literal>

</ogc:PropertyIsGreaterThan>

</ogc:Filter>

<PolygonSymbolizer>

<Fill>

<CssParameter name="fill">#009900</CssParameter>

</Fill>

</PolygonSymbolizer>

</Rule>

</FeatureTypeStyle>

 

效果:

                       

在SLD中还根据3.3的注记写法,增加了注记的显示。

3.5分级渲染

3.5.1结构

PolygonSymbolizer

 

……Rule

 

………MinScaleDenominator

 

………MaxScaleDenominator

 

………PolygonSymbolizer

 

………TextSymbolizer

 

 

3.5.2示例

通过设置不同比例尺时的显示颜色,展示不同的效果。

SLD:

<FeatureTypeStyle>

<Rule>

<Name>Large</Name>

<MaxScaleDenominator>5746</MaxScaleDenominator>

<PolygonSymbolizer>

<Fill>

<CssParameter name="fill">#CCCCCC</CssParameter>

</Fill>

<Stroke>

<CssParameter name="stroke">#000000</CssParameter>

<CssParameter name="stroke-width">7</CssParameter>

</Stroke>

</PolygonSymbolizer>

</Rule>

<Rule>

<Name>Medium</Name>

<MinScaleDenominator>5746</MinScaleDenominator>

<MaxScaleDenominator>12000</MaxScaleDenominator>

<PolygonSymbolizer>

<Fill>

<CssParameter name="fill">#0000CC</CssParameter>

</Fill>

<Stroke>

<CssParameter name="stroke">#000000</CssParameter>

<CssParameter name="stroke-width">4</CssParameter>

</Stroke>

</PolygonSymbolizer>

</Rule>

<Rule>

<Name>Small</Name>

<MinScaleDenominator>12000</MinScaleDenominator>

<PolygonSymbolizer>

<Fill>

<CssParameter name="fill">#0000CC</CssParameter>

</Fill>

<Stroke>

<CssParameter name="stroke">#000000</CssParameter>

<CssParameter name="stroke-width">1</CssParameter>

</Stroke>

</PolygonSymbolizer>

</Rule>

</FeatureTypeStyle>

效果图:

 

 

 

4 注意

4.1 注记渲染时某些注记未显示

初始时,某个要素的注记无法显示:

 

放大后其又可以出现:

 

出现这种情况,往往是因为注记显示的地方在另外一个要素下面。

解决方法比较简单,利用LabelPalcement元素调整注记显示的地方便可解决。例如:

 <LabelPlacement>
         <PointPlacement>
           <AnchorPoint>
               <AnchorPointX>0.5</AnchorPointX>
               <AnchorPointY>0.5</AnchorPointY>
           </AnchorPoint>
         </PointPlacement>
       </LabelPlacement>

4.2 中文出现乱码


出现这样的情况,一般是SLD中未进行正确的格式编码赋值。

首先将编码改成GB2312。例如:

<?xml version="1.0" encoding="GB2312"?>

如果发现还是乱码,则很有可能是目前字体不支持中文。

例如当字体是Arial时,不支持中文:

<CssParameter name="font-family">Arial</CssParameter>

将字体改成微软雅黑,则注记不再重现乱码:

<CssParameter name="font-family">微软雅黑</CssParameter>

Guess you like

Origin www.cnblogs.com/yangzhengier/p/11459181.html