GeoServer:How 仅在图层属性的外部边界上创建标签位置(水平和垂直)

GeoServer:How to create label Postion(Horizontal and Vertical) only on for outside boundary from layer Properties

我将包含多边形 Grid.I 属性的网格 shapefile 导入 GeoServer 并为图层样式创建了网格 layer.And,我创建了带有 LabelPlacement 的 SLD 文件,其中包含 Anchor X 和标签的 Y 位置显示在 polygon.It 工作正常的中间。 以下为SLD样式:

<?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_polygon</Name>
    <UserStyle>
    <!-- Styles can have names, titles and abstracts -->
      <Title>Default Polygon</Title>
      <Abstract>A sample style that draws a polygon</Abstract>
      <!-- FeatureTypeStyles describe how to render different features -->
      <!-- A FeatureTypeStyle for rendering polygons -->
      <FeatureTypeStyle>
        <Rule>
          <Name>rule1</Name>
          <Title>Gray Polygon with Black Outline</Title>
          <Abstract>A polygon with a gray fill and a 1 pixel black outline</Abstract>

          <PolygonSymbolizer>
            <Stroke>
              <CssParameter name="stroke">#0000FF</CssParameter>
              <CssParameter name="stroke-width">1.5</CssParameter>
            </Stroke>
          </PolygonSymbolizer>
          <TextSymbolizer>
            <Label>
              0<ogc:PropertyName>TWP</ogc:PropertyName>-0<ogc:PropertyName>RGE</ogc:PropertyName>W<ogc:PropertyName>M</ogc:PropertyName>
            </Label>
            <Font>
              <CssParameter name="font-family">Times New Roman</CssParameter>
              <CssParameter name="font-style">Normal</CssParameter>
              <CssParameter name="font-size">14</CssParameter>
            </Font>

            <LabelPlacement>
              <PointPlacement>
                <AnchorPoint>
                  <AnchorPointX>0.5</AnchorPointX>
                  <AnchorPointY>0.5</AnchorPointY>
                </AnchorPoint>
              </PointPlacement>
            </LabelPlacement>
           <!-- 
            <Displacement>
                <DisplacementX>25</DisplacementX>
                <DisplacementY>0</DisplacementY>
            </Displacement>
            -->

            <Fill>
               <CssParameter name="fill">#0000FF</CssParameter>
            </Fill>

          </TextSymbolizer>
        </Rule>
      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

得到的输出是:

但是如何只为层 properties.I 的网格的外边界分配标签水平和垂直需要如下图的标签:

我试过标签位移但AnchorPoint.Don不知道如何创建(水平和垂直标签)。

请帮忙。

这很难(而且可能是不可能的),GeoServer 将尝试(默认情况下)在每个要素的中心(或您指定的几何形状)标记每个要素,因此您首先需要设计一个过滤器,强制它只标记地图边缘的要素。您可能想要使用 predefined variable wms_bbox 来为您提供地图外部的位置。

接下来您将需要计算标签的位置,这将是您要标记的要素与 wms 边界框之间的某种交集。在这里您需要确定您是在顶部、底部、左侧还是右侧边缘,并相应地调整标签位置。为此,您有 functions available. I suspect you will need if_then_else and the env function to get the bounding box variable from above combined with the spatial functions to determine where you are, and finally the geometric functions 的范围来创建新的几何图形。

有一个 discussion on the geoserver-user's mailing list a while ago and this question on gis.stackexchange.com 是相关的,但我认为他们都没有得出好的结论。