SLD 官方实例

基于xml标准的sld格式:

<?xml version="1.0" encoding="UTF-8"?>
<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>country_bounds</Name>
    <UserStyle>
      <Title>xxx</Title>
      <FeatureTypeStyle>
        <Rule>
          <LineSymbolizer>
            <Geometry>
              <ogc:PropertyName>center-line</ogc:PropertyName>
            </Geometry>
            <Stroke>
              <CssParameter name="stroke">#0000ff</CssParameter>
            </Stroke>
          </LineSymbolizer>
        </Rule>
      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

注:encoding="UTF-8"改成encoding="GB2312"支持中文

 

1.PointSymbolizer

Example:

<PointSymbolizer>
   <Graphic>
     <Mark>
       <WellKnownName>circle</WellKnownName>
       <Fill>
         <CssParameter name="fill">#FF0000</CssParameter>
       </Fill>
     </Mark>
     <Size>6</Size>
   </Graphic>
 </PointSymbolizer>
<PointSymbolizer>
   <Graphic>
     <ExternalGraphic>
       <OnlineResource xlink:type="simple"
                       xlink:href="file:///var/www/htdocs/sun.png" />
       <Format>image.png</Format>
     </ExternalGraphic>
   </Graphic>
 </PointSymbolizer>

2.LineSymbolizer

Basic Example:

<LineSymbolizer>
    <Stroke>
      <CssParameter name="stroke">#0000FF</CssParameter>
      <CssParameter name="stroke-width">3</CssParameter>
      <CssParameter name="stroke-dasharray">5 2</CssParameter>
    </Stroke>
 </LineSymbolizer>

Offsetting lines:

<LineSymbolizer>
    <Stroke>
         <CssParameter name="stroke">#000000</CssParameter>
         <CssParameter name="stroke-width">2</CssParameter>
    </Stroke>
</LineSymbolizer>
<LineSymbolizer>
    <Stroke>
         <CssParameter name="stroke">#0000FF</CssParameter>
         <CssParameter name="stroke-width">3</CssParameter>
         <CssParameter name="stroke-dasharray">5 2</CssParameter>
     </Stroke>
     <PerpendicularOffset>3</PerpendicularOffset>
</LineSymbolizer>

Offsetting polygons:

<PolygonSymbolizer>
    <Stroke>
       <CssParameter name="stroke">#000000</CssParameter>
       <CssParameter name="stroke-width">2</CssParameter>
    </Stroke>
</PolygonSymbolizer>
<LineSymbolizer>
    <Stroke>
       <CssParameter name="stroke">#AAAAAA</CssParameter>
       <CssParameter name="stroke-width">3</CssParameter>
    </Stroke>
    <PerpendicularOffset>-2</PerpendicularOffset>
</LineSymbolizer>

3.PolygonSymbolizer

Example:

<PolygonSymbolizer>
    <Fill>
         <CssParameter name="fill">#000080</CssParameter>
     </Fill>
</PolygonSymbolizer>

4.TextSymbolizer

Example:

<TextSymbolizer>
         <Label>
           <ogc:PropertyName>name</ogc:PropertyName>
         </Label>
         <Font>
           <CssParameter name="font-family">Arial</CssParameter>
           <CssParameter name="font-size">12</CssParameter>
           <CssParameter name="font-style">normal</CssParameter>
           <CssParameter name="font-weight">bold</CssParameter>
         </Font>
         <LabelPlacement>
           <PointPlacement>
             <AnchorPoint>
               <AnchorPointX>0.5</AnchorPointX>
               <AnchorPointY>0.0</AnchorPointY>
             </AnchorPoint>
             <Displacement>
               <DisplacementX>0</DisplacementX>
               <DisplacementY>25</DisplacementY>
             </Displacement>
             <Rotation>-45</Rotation>
           </PointPlacement>
         </LabelPlacement>
         <Fill>
           <CssParameter name="fill">#990099</CssParameter>
         </Fill>
</TextSymbolizer>

Scalable Font Size:

<CssParameter name="font-size">
         <ogc:Function name="Categorize">
           <!-- Value to transform -->
           <ogc:Function name="env">
             <ogc:Literal>wms_scale_denominator</ogc:Literal>
           </ogc:Function>
           <!-- Output values and thresholds -->
           <!-- Ranges: -->
           <!-- [scale <= 300, font 12] -->
           <!-- [scale 300 - 2500, font 10] -->
           <!-- [scale > 2500, font 8] -->
           <ogc:Literal>12</ogc:Literal>
           <ogc:Literal>300</ogc:Literal>
           <ogc:Literal>10</ogc:Literal>
           <ogc:Literal>2500</ogc:Literal>
           <ogc:Literal>8</ogc:Literal>
         </ogc:Function>
</CssParameter>

6.Geometry

Extracting vertices:

<PointSymbolizer>
     <Geometry>
       <ogc:Function name="vertices">
          <ogc:PropertyName>the_geom</ogc:PropertyName>
       </ogc:Function>
     </Geometry>
     <Graphic>
       <Mark>
         <WellKnownName>square</WellKnownName>
         <Fill>
           <CssParameter name="fill">#FF0000</CssParameter>
         </Fill>
       </Mark>
       <Size>6</Size>
     </Graphic>
</PointSymbolizer>

Start and end point:

<PointSymbolizer>
  <Geometry>
    <ogc:Function name="startPoint">
      <ogc:PropertyName>the_geom</ogc:PropertyName>
    </ogc:Function>
  </Geometry>
  <Graphic>
    <Mark>
      <WellKnownName>square</WellKnownName>
      <Stroke>
        <CssParameter name="stroke">0x00FF00</CssParameter>
        <CssParameter name="stroke-width">1.5</CssParameter>
      </Stroke>
    </Mark>
    <Size>8</Size>
  </Graphic>
 </PointSymbolizer>
 <PointSymbolizer>
   <Geometry>
     <ogc:Function name="endPoint">
       <ogc:PropertyName>the_geom</ogc:PropertyName>
     </ogc:Function>
   </Geometry>
   <Graphic>
     <Mark>
       <WellKnownName>circle</WellKnownName>
       <Fill>
          <CssParameter name="fill">0xFF0000</CssParameter>
       </Fill>
     </Mark>
     <Size>4</Size>
   </Graphic>
 </PointSymbolizer>

Drop shadow:

<PolygonSymbolizer>
    <Geometry>
       <ogc:Function name="offset">
          <ogc:PropertyName>the_geom</ogc:PropertyName>
          <ogc:Literal>0.00004</ogc:Literal>
          <ogc:Literal>-0.00004</ogc:Literal>
       </ogc:Function>
    </Geometry>
    <Fill>
      <CssParameter name="fill">#555555</CssParameter>
    </Fill>
</PolygonSymbolizer>

 

posted @ 2017-05-11 00:27  贝尔格里尔斯  阅读(1026)  评论(0编辑  收藏  举报