GeoServer中地图可视化提升利器之SLD知识简介

目录

前言

 一、SLD简介

1、介绍

2、SLD的版本

3、SLD的Schema说明

二、SLD中相关知识解析

1、Scheme简要说明

2、一个SLD实例

总结


前言

        在互联网上有很多精美的地图,在地图从shp或者gdb等矢量文件,经过设计人员的加工,配色,标注,符号化等等修饰加工。原始的点线面数据,在经过数据处理人员的修饰后,就变得丰富多彩,引人入胜。

        在常见的Arcgis或者Qgis等桌面产品中,支持对地图产品的符号化,在符号化同时辅以标注等信息,实现对地图样式的定制。通常,在Arcgis中,使用ArcMap设置好地图后,同时会生成地图的mxd文件。在进行地图服务发布的时候,可以将对应的mxd文件导入到服务中,即可实现样式的发布。那么在免费的商业套件GeoServer中,是怎么进行样式定制的呢?

        本文将简单介绍Geoserver中,地图样式定制功能的相关知识。本文将首先介绍SLD的基础概念,相关约束标准,其次结合一个SLD的实例进行案例讲解,帮助读者对SLD有一个直观的认识。

 一、SLD简介

1、介绍

        地理空间数据(矢量和栅格)没有内在的视觉组件。为了查看数据,必须对其进行样式设置。样式指定用于在地图上渲染数据的颜色、厚度和其他可见属性。WMS为每个数据集提供一组样式选项;但是这些选项是由服务器预先配置的,用户不能创建、检查和修改样式。

        Styled Layer Descriptor(SLD)是一个标准,它使应用程序能够在XML文档中配置如何正确地描述WMS中的层和图例。它使用符号结尾(SE)来指定特性和覆盖范围的样式。WMS的SLD配置文件通过附加操作增强WMS,以支持WFS的功能样式和WCS的覆盖范围。

        SLD对于地图的作用,类似于CSS对于HTML的作用,如果没有Css,Html的世界将是暗淡无光的,没了SLD的地图,也将失去地图独特的美感。SLD是一种描述地图图层样式的标准,一般用于WMS。一个地图不仅包含数据源组成,还需要对数据进行符号化和渲染,SLD就是这个定义地图图层符号化和渲染信息的标准。

2、SLD的版本

        sld发展到现在,已经是1.1的版本,从最开始的1.0发展而来。其实现标准参考如下:

序号SLD标准参考内容
11.0.0OGC Styled Layer Descriptor Implementation Specification, Version 1.0.0
21.1.0

OGC Symbology Encoding Implementation Specification, Version 1.1.0

OGC Styled Layer Descriptor profile of the Web Map Service Implementation Specification, Version

        需要注意的是,在GeoServer当中,根据版本的不同,其支持SLD的程度不一样,GeoServer完全执行SLD1.0.0的标准,而对于1.1.0版本来说,只执行了部分标准。一般来说,1.0.0版本已经很好的满足日常生活需要。

3、SLD的Schema说明

        sld作为一种xml形式的图层样式控制文件,采用的基于xml的定义方式,为了满足其特殊的定义需求,对其xml的内容是有严格的Schema验证的。只要是支持标准OGC的服务标准都应该对生成的sld进行数据格式的校验,在生成sld时也必须进行规范格式的创建。

        有兴趣的朋友可以在sld的schema官方定义看到,其Schema的不同历史阶段说明。

OpenGIS(r) SLD schema - ReadMe.txt
==================================

OpenGIS Styled Layer Descriptor Profile of the Web Map Service Implementation Specification

More information on the OGC SensorML standard may be found at
 http://www.opengeospatial.org/standards/sld

The most current schema are available at http://schemas.opengis.net/ .

-----------------------------------------------------------------------

2012-07-21  Kevin Stegemoller
  * v1.0 - v1.1: WARNING XLink change is NOT BACKWARD COMPATIBLE.
  * changed OGC XLink (xlink:simpleLink) to W3C XLink (xlink:simpleAttrs)
    per an approved TC and PC motion during the Dec. 2011 Brussels meeting.
    see http://www.opengeospatial.org/blog/1597
  * implement 11-025: retroactively require/add all leaf documents of an
    XML namespace shall explicitly <include/> the all-components schema
  * v1.1.0: added sldAll.xsd as the all-components document (06-135r11 #14)
  * v1.1.0: updated xsd:schema/@version to 1.1.0.2 (06-135r11 s#13.4)
  * v1.0.0: updated xsd:schema/@version to 1.0.0.2 (06-135r11 s#13.4)
  * v1.1: removed 1.1 because it was posted in error. 
    The sld 1.1 URL is rewritten to 1.1.0 to preserve backward compatibility.
  * v0.7.x: schema were removed and archived
  * v1.0.20: schema were removed and archived

2010-11-17  Simon Cox
  * v1.1: Changes to 1.1.0 create SLD 1.1.1
    + added sldAll.xsd as the all-components document (06-135r9 s#14)
    + created sld/1.1 version from SLD 1.1.1

2010-02-01  Kevin Stegemoller
  * v1.1.0, v1.0.20, v1.0.0, v0.7.3, v0.7.2, v0.7.1
    + updated xsd:schema/@version attribute (06-135r7 s#13.4)
    + update relative schema imports to absolute URLs (06-135r7 s#15)
    + update/verify copyright (06-135r7 s#3.2)
    + add archives (.zip) files of previous versions
    + create/update ReadMe.txt (06-135r7 s#17)

2007-11-28  Kevin Stegemoller
  * v1.1.0 Published SLD 1.1.0 schemas from OGC 05-078r4 including
    Corrigendum 1 07-123r1 (Corrigendum 1 for 05-078r4)

2005-11-22  Arliss Whiteside
  * SLD versions 0.7.2 through 1.0.20: The sets of XML Schema Documents
    for OpenGIS Styled Layer Descriptor Versions 0.7.2 through 1.0.20
    have been edited to reflect the corrigenda to all those OGC
    documents that is based on the change requests:
    OGC 05-068r1 "Store xlinks.xsd file at a fixed location"
    OGC 05-081r2 "Change to use relative paths"

  * Note: check each OGC numbered document for detailed changes.

-- [ VERSION NOTES ] --------------------------------------------------

  OGC is incrementally changing how schemas will be hosted. A new
  revision of the Specification Best Practice policy document (06-135r11)
  clarifies this practices.

  OGC is moving to host the schemas using a 2 digit version number so
  that dependent documents (schemas) will not have to change each time a
  schema is corrected (by a corrigendum). The schemas actual version
  number will be kept in the version attribute on the schema element
  which will be used to signify that there has been a change to the
  schema. Each previous revision will be available online in a ZIP
  archive.
  
  The LATEST version is the M.N directory where 
   * M is the major version
   * N is the minor version
  The latest bugfix version now is always in the M.N directory and 
  documented in the version attribute on the schema element. The older
  versions are now archived in the -M_N_X.zip files.
  
  Previously the OGC used M.N.C where
   * M is the major version
   * N is the minor version
   * C is the corrigendum version
  These older M.N.C versions will be updated using M.N.C.X where 
  X may be a bugfix version. These schema will also be .zip archived.

-- 2010-01-21  Kevin Stegemoller  updated 2012-07-21

-----------------------------------------------------------------------

Policies, Procedures, Terms, and Conditions of OGC(r) are available
  http://www.opengeospatial.org/ogc/legal/ .

Copyright (c) 2010 Open Geospatial Consortium.

-----------------------------------------------------------------------

        上面也包含了SLD从1.0.0到1.1.0的不用版本的升级概况。

二、SLD中相关知识解析

1、Scheme简要说明

         上图以1.0.0版本的schema说明为例,在schema的要求中定义一些属性和具体的值范围。SLD-规范是采用XML定义地图显示样式,通过自定义SLD来配置地图图层渲染的可视化风格,可以设置过滤器,自定义图例等。rule是SLD最重要的一个元素,因为她允许根据给定的某个参数(使用过滤器)对数据集进行分类,所有的与分类有关的重要参数都必须在rule元素中设置。

        对于使用SLD来进行地图的自定义样式,则必须结合使用SE(Symbology Encoding)这个标准。SE是OGC的另一个标准,这个也是基于XML模式定义的,这个标准允许我们自定义不同的符号样式来表达地图上不同的要素。SLD文件使用这种语言,这样在地图渲染时地图服务可以解释由用户定义的样式。

         以上是对Schema文档的一些解析。涉及的内容比较多,感兴趣的朋友可以在官网上找到官方的定义。

2、一个SLD实例

这里分享一个SLD实例,实现对Point(点要素)的样式控制。

<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor version="1.0.0" 
 xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd" 
 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">
  <!-- a Named Layer is the basic building block of an SLD document -->
  <NamedLayer>
    <Name>default_point</Name>
    <UserStyle>
    <!-- Styles can have names, titles and abstracts -->
      <Title>Red Square Point</Title>
      <Abstract>A sample style that draws a red square point</Abstract>
      <!-- FeatureTypeStyles describe how to render different features -->
      <!-- A FeatureTypeStyle for rendering points -->
      <FeatureTypeStyle>
        <Rule>
          <Name>rule1</Name>
          <Title>Red Square Point</Title>
          <Abstract>A 6 pixel square with a red fill and no stroke</Abstract>
            <PointSymbolizer>
              <Graphic>
                <Mark>
                  <WellKnownName>square</WellKnownName>
                  <Fill>
                    <CssParameter name="fill">#FF0000</CssParameter>
                  </Fill>
                </Mark>
              <Size>6</Size>
            </Graphic>
          </PointSymbolizer>
        </Rule>
      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

         上面SLD文件中,演示了PointSymbolizer的具体使用,对点要素设置了颜色填充样式。在GeoServer中使用以上样式渲染数据效果如下:

总结

        以上就是本文的主要内容,本文将首先介绍SLD的基础概念,相关约束标准,其次结合一个SLD的实例进行案例讲解,帮助读者对SLD有一个直观的了解。关于SLD更多的专业知识,可以在相应的官方文档中查询,行文仓促,如有不当之处,欢迎评论交流,批评指正。

  • 49
    点赞
  • 45
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 73
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 73
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夜郎king

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值