前言
在地图上使用统计图表是项目开发中经常碰到的事情,在GeoServer中可以通过Chart Symbolizer扩展实现统计图表专题图。下面是GeoServer官网对插件的一段介绍:
An open source solution, completely embedded in GeoServer, would guarantee control over the service availability, over its features, and provide excellent performance. David Gilbert, of JFreeChart fame, must have thought the same when he developed Eastwood Charts, an open source implementation of the Google Charts API.
一、安装插件
在GeoServer下载页面找到Chart Symbolizer插件,下载解压并拷贝jar文件到GeoServer的lib目录下,重启GeoServer完成安装。
二、使用方法
在SLD中使用<ExternalGraphic> 标签进行配置图表信息,格式如下所示:
<ExternalGraphic>
<OnlineResource
xlink:href="https://chart?cht=<chart_type>&chd=<chart_data>&chs=<chart_size>&..." />
<Format>application/chart</Format>
</ExternalGraphic>
基本配置项说明:
参数 | 说明 |
---|---|
cht | 图表类型,如饼状图的值可选p(二维),p3(三维) |
chd | 图表数据,如 chd=t:10,20,30,40,50 |
chs | 图表大小,如 chs=220x100 |
chl | 图表标签,如 chl=May|Jun|Jul|Aug|Sep|Oct |
chco | 图表颜色,如 chco=FF0000|00FF00|0000FF |
chf | 图表背景填充,如 chf=bg,s,FFFFFF00 |
更多配置参数参考 Google Chart API 文档。
1、饼状图
设置chs参数使用固定大小的饼图。
<?xml version="1.0" encoding="gb2312"?>
<StyledLayerDescriptor version="1.0.0"
xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/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">
<NamedLayer>
<Name></Name>
<UserStyle>
<Name>Pie charts</Name>
<FeatureTypeStyle>
<Rule>
<PolygonSymbolizer>
<Fill