---
title: "GeoServer中多边形内多个标签问题"
author: "cjx186"
date: "2012-08-29T01:25:51Z"
tags: []
categories: ["开源软件"]
slug: "geoserver"
draft: false
lastmod: "2012-08-29T01:26:17Z"
id: 1666207
url: "https://xml.iteye.com/blog/1666207"
---

<span style="color:green">GeoServer在生成多边形切片时会产生重复标签</span>
![](http://dl.iteye.com/upload/attachment/0073/0078/c49f8aff-b5db-3129-bda7-f75903517bfb.png)
<span style="color:green">这个问题可以使用过滤器的质心功能，中心位置。</span>

|Name|Arguments|Description|
|centroid|geometry:Geometry|Returns the centroid of the geometry. Can be often used as a label point for polygons, though there is no guarantee it will actually lie inside the geometry|


```xml

<Rule>
  <TextSymbolizer>
    <Label><ogc:PropertyName>NAME</ogc:PropertyName></Label>
    <Fill><CssParameter name="fill">#666666</CssParameter></Fill>
    <Geometry>
      <ogc:Function name="centroid">
        <ogc:PropertyName>geom</ogc:PropertyName>
      </ogc:Function>
    </Geometry>
    <VendorOption name="spaceAround">10</VendorOption>
    <VendorOption name="autoWrap">85</VendorOption>
    <VendorOption name="group">yes</VendorOption>
  </TextSymbolizer>
</Rule>

```
<span style="color:green">使用后如下效果</span>
![](http://dl.iteye.com/upload/attachment/0073/0080/c0b51015-6370-33e8-965b-109fe909bd84.png)
<span style="color:green">但声明时没有保证一定在多边形内部有可能出现如下效果(需要注意)：</span>![](http://dl.iteye.com/upload/attachment/0073/0082/532e6075-a460-3486-aafb-bea3e8e9ba9b.png)