2

I am having a hard time putting labels on both ends of a line Here is SLD that I have so far. It puts a label on one side only but I need it on both ends of a line.


<?xml version="1.0" encoding="ISO-8859-1"?> <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"> <NamedLayer> <Name>line_name_ends_red</Name> <UserStyle> <Title>line_name_ends_red</Title> <FeatureTypeStyle> <Rule> <Name>line_name_ends_red</Name> <LineSymbolizer> <Stroke> <CssParameter name="stroke">#ff0000</CssParameter> <CssParameter name="stroke-width">2</CssParameter> </Stroke> </LineSymbolizer>
<TextSymbolizer> <Geometry> <ogc:Function name="endPoint"> <ogc:PropertyName>the_geom</ogc:PropertyName> </ogc:Function> </Geometry> <LabelPlacement> <PointPlacement> <Rotation> <ogc:Function name="endAngle"> <ogc:PropertyName>the_geom</ogc:PropertyName> </ogc:Function> </Rotation> </PointPlacement> </LabelPlacement>
<Label>
<ogc:PropertyName>LINE_NAME</ogc:PropertyName>
</Label> </TextSymbolizer> </Rule> </FeatureTypeStyle> </UserStyle> </NamedLayer> </StyledLayerDescriptor>


this is what my SLD produces But I need it to look like this But I need it to look like this

2

To get two labels you will need two textSymbolizers one for the start point and one for the end point. So it becomes:

<TextSymbolizer>
    <Geometry>
        <ogc:Function name="endPoint">
            <ogc:PropertyName>the_geom</ogc:PropertyName>
        </ogc:Function>
    </Geometry>
    <LabelPlacement>
        <PointPlacement>
            <Rotation>
                <ogc:Function name="endAngle">
                    <ogc:PropertyName>the_geom</ogc:PropertyName>
                </ogc:Function>
            </Rotation>
        </PointPlacement>
    </LabelPlacement>

    <Label>

        <ogc:PropertyName>LINE_NAME</ogc:PropertyName>

    </Label>
</TextSymbolizer>
<TextSymbolizer>
  <Geometry>
    <ogc:Function name="startPoint">
      <ogc:PropertyName>the_geom</ogc:PropertyName>
    </ogc:Function>
  </Geometry>
  <LabelPlacement>
    <PointPlacement>
      <Rotation>
        <ogc:Function name="startAngle">
          <ogc:PropertyName>the_geom</ogc:PropertyName>
        </ogc:Function>
      </Rotation>
    </PointPlacement>
  </LabelPlacement>

  <Label>

    <ogc:PropertyName>LINE_NAME</ogc:PropertyName>

  </Label>
</TextSymbolizer>
  • and I suspect if you take out the rotation your labels will end up the right way – Ian Turton Jul 3 '15 at 8:55
  • Hi and thank for the response. Yes that did place labels on both ends. But I need them to be always placed away of the line (before and after the line) not along the line. I'd upload how it look like now but I done see how. – Srdjan Jul 6 '15 at 14:36
  • Pointplacement takes an offset parameter which might help – Ian Turton Jul 6 '15 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.