使用转换函数设置样式

符号编码1.1规范定义了以下内容 转换函数

  • Recode 将一组离散属性值转换为另一组值

  • Categorize 将连续值属性转换为一组离散值

  • Interpolate 将连续值属性转换为另一个连续值范围

这些函数提供了一种从特征属性值计算样式参数的简洁方法。geoserver将它们实现为 过滤器功能 用同样的名字。

备注

geoserver函数语法与se 1.1定义稍有不同,因为规范定义了geoserver函数中不可用的额外语法元素。

这些函数可以使样式文档更简洁,因为它们表达的逻辑可能需要许多单独的规则或复杂的筛选表达式,因此它们甚至允许不可能以任何其他方式表达的逻辑。另一个好处是,它们通常提供优于显式规则的性能。

使用这些函数进行样式设置的一个缺点是它们不显示在WMS图例图形中。

重新编码

这个 Recode 过滤函数将属性的一组离散值转换为另一组值。该函数可在SLD样式参数中使用,以将特征属性的值转换为参数的特定值,如颜色、大小、宽度、不透明度等。

重新编码由一组 (输入、输出) 值对。

例子

考虑使用填充颜色表示州的地形区域的美国州数据集的叶绿体地图。数据集有一个属性 SUB_REGION 包含每个州的区号。这个 Recode 函数用于将每个区域代码映射到不同的颜色。

这种样式的符号是:

<PolygonSymbolizer>
   <Fill>
     <CssParameter name="fill">
       <ogc:Function name="Recode">
         <!-- Value to transform -->
         <ogc:Function name="strTrim">
           <ogc:PropertyName>SUB_REGION</ogc:PropertyName>
         </ogc:Function>

         <!-- Map of input to output values -->
         <ogc:Literal>N Eng</ogc:Literal>
         <ogc:Literal>#6495ED</ogc:Literal>

         <ogc:Literal>Mid Atl</ogc:Literal>
         <ogc:Literal>#B0C4DE</ogc:Literal>

         <ogc:Literal>S Atl</ogc:Literal>
         <ogc:Literal>#00FFFF</ogc:Literal>

         <ogc:Literal>E N Cen</ogc:Literal>
         <ogc:Literal>#9ACD32</ogc:Literal>

         <ogc:Literal>E S Cen</ogc:Literal>
         <ogc:Literal>#00FA9A</ogc:Literal>

         <ogc:Literal>W N Cen</ogc:Literal>
         <ogc:Literal>#FFF8DC</ogc:Literal>

         <ogc:Literal>W S Cen</ogc:Literal>
         <ogc:Literal>#F5DEB3</ogc:Literal>

         <ogc:Literal>Mtn</ogc:Literal>
         <ogc:Literal>#F4A460</ogc:Literal>

         <ogc:Literal>Pacific</ogc:Literal>
         <ogc:Literal>#87CEEB</ogc:Literal>
       </ogc:Function>
     </CssParameter>
   </Fill>
</PolygonSymbolizer>

此样式生成以下输出:

../../../_images/recode_usa_region.png

分类

这个 Categorize 过滤函数将连续值属性转换为一组离散值。该函数可在SLD样式参数中使用,以将特征属性的值转换为参数的特定值,如颜色、大小、宽度、不透明度等。

分类是由交替输出值和数据阈值列表定义的。阈值定义输入范围之间的分隔。根据输入值所处的范围,输入值被转换为输出值。

例子

考虑使用填充颜色的美国州数据集的叶绿体地图,以表示按人口分类的州。数据集具有属性 PERSONSLAND_KM 从中计算人口密度,使用 Div 操作员。此值输入到 Categorize 函数,用于为密度范围指定不同的颜色 [ <= 20] , [20 - 100] 和 [ > 100] .

这种样式的符号是:

<PolygonSymbolizer>
   <Fill>
     <CssParameter name="fill">
       <ogc:Function name="Categorize">
         <!-- Value to transform -->
         <ogc:Div>
           <ogc:PropertyName>PERSONS</ogc:PropertyName>
           <ogc:PropertyName>LAND_KM</ogc:PropertyName>
         </ogc:Div>

         <!-- Output values and thresholds -->
         <ogc:Literal>#87CEEB</ogc:Literal>
         <ogc:Literal>20</ogc:Literal>
         <ogc:Literal>#FFFACD</ogc:Literal>
         <ogc:Literal>100</ogc:Literal>
         <ogc:Literal>#F08080</ogc:Literal>

       </ogc:Function>
     </CssParameter>
   </Fill>
</PolygonSymbolizer>

此样式生成以下输出:

../../../_images/categorize_usa_popdensity.png

插入

这个 Interpolate 过滤函数将一个连续值属性转换为另一个连续值范围。该函数可在SLD样式参数中使用,将特征属性的值转换为连续值参数,如颜色、大小、宽度、不透明度等。

转换由一组 (输入、输出) 沿着所需的映射曲线选择的控制点。沿曲线分段插值用于计算任何输入值的输出值。

函数可以计算作为输出的数值或颜色值。这被称为 插值法 ,由值为的可选参数指定。 numeric (违约)或 color .

这个 形状 控制点之间的映射曲线由 插值模式 ,这是一个可选参数,值为 linear (违约), cubiccosine .

例子

通过对颜色范围的插值,可以为叶绿体(主题)地图简洁地定义连续变化的颜色。例如,考虑使用填充颜色指示状态总体的美国状态数据集的地图。数据集有一个属性 PERSONS 包含每个州的人口。人口值在0到30000000之间。插值曲线由三个控制点定义,这些控制点为0、9000000和23000000的总体级别指定颜色。填充值的颜色通过沿此曲线分段线性插值计算。例如,人口为16000000的状态显示为中间控制点和上控制点之间的中间颜色。人口超过23000000的州以最后一种颜色显示。

因为插值是对颜色值执行的,所以会提供方法参数,其值为 color .由于使用了默认的线性插值,因此不提供插值模式,

这种样式的符号是:

<PolygonSymbolizer>
   <Fill>
     <CssParameter name="fill">
       <ogc:Function name="Interpolate">
         <!-- Property to transform -->
         <ogc:PropertyName>PERSONS</ogc:PropertyName>

         <!-- Mapping curve definition pairs (input, output) -->
         <ogc:Literal>0</ogc:Literal>
         <ogc:Literal>#fefeee</ogc:Literal>

         <ogc:Literal>9000000</ogc:Literal>
         <ogc:Literal>#00ff00</ogc:Literal>

         <ogc:Literal>23000000</ogc:Literal>
         <ogc:Literal>#ff0000</ogc:Literal>

         <!-- Interpolation method -->
         <ogc:Literal>color</ogc:Literal>

         <!-- Interpolation mode - defaults to linear -->
       </ogc:Function>
     </CssParameter>
   </Fill>
</PolygonSymbolizer>

此符号产生以下输出:

../../../_images/interpolate_usa_pop.png