I have the grid shapefile that contains properties of the Polygon Grid.I imported into GeoServer and created the grid layer.And for the style of the layer, I created SLD File with LabelPlacement contains Anchor X and Y position for the label to display in the middle of the polygon.It's working fine. The following is the SLD style:
<?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>
And getting output is:
But how to assign the Label Horizontal and Vertical only for Outer Boundary of the Grid from layer properties.I want Label like the following image:
I tried label Displacement and AnchorPoint.Don't know how to create(Horizontal and Vertical Label).
Please, any help.
This is hard (and possibly impossible), GeoServer will try (by default) to label each feature at it's centre (or at the geometry you specify) so you first need to design a filter that will force it to only label features at the edge of the map. You will probably want to make use of the predefined variable wms_bbox
which gives you the location of the outside of the map.
Next you will need to calculate the position of the label which will be some sort of intersection between the feature you are labelling and the wms bounding box. Here you will need to determine if you are at the top, bottom, left or right edge and adjust the label location accordingly. For this you have a range of 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 to create the new geometry.
There was a discussion on the geoserver-user's mailing list a while ago and this question on gis.stackexchange.com that are related but I don't think either of them reached a good conclusion.