1

How can I filter the label in SLD, I want to have a label for all the contour-lines where the elevation is between 200-400. I tried with this SLD, but it doesn't apply anything.

<Rule>
  <Name>rule 6</Name>
  <Title>Label (200-400)</Title>

  <ogc:Filter>
    <ogc:PropertyIsBetween>
        <ogc:Function name="IEEERemainder">
            <ogc:Function name="int2ddouble">
                <ogc:PropertyName>value</ogc:PropertyName>
            </ogc:Function>
            <ogc:Function name="parseDouble">
                <ogc:Literal>50.0</ogc:Literal>
            </ogc:Function>
        </ogc:Function>
        <ogc:LowerBoundary>
            <ogc:Literal>200</ogc:Literal>
        </ogc:LowerBoundary>
        <ogc:UpperBoundary>
            <ogc:Literal>400</ogc:Literal>
        </ogc:UpperBoundary>
    </ogc:PropertyIsBetween>
</ogc:Filter>

  <MaxScaleDenominator>120000</MaxScaleDenominator>
  <TextSymbolizer>
    <Label>
      <ogc:Function name="round">
        <ogc:PropertyName>value</ogc:PropertyName>
      </ogc:Function>
    </Label>
    <Font>
      <CssParameter name="font-family">Arial</CssParameter>
      <CssParameter name="font-weight">Normal</CssParameter>
      <CssParameter name="font-size">12</CssParameter>
    </Font>
    <LabelPlacement>
      <LinePlacement/>
    </LabelPlacement>
    <Halo>
      <Radius>
        <ogc:Literal>2</ogc:Literal>
      </Radius>
      <Fill>
        <CssParameter name="fill">#FFFFFF</CssParameter>
        <CssParameter name="fill-opacity">0.9</CssParameter>        
      </Fill>
    </Halo>
    <Fill>
      <CssParameter name="fill">#ff0000</CssParameter>
    </Fill>
    <Priority>2000</Priority>
    <VendorOption name="followLine">true</VendorOption>
    <VendorOption name="repeat">300</VendorOption>
    <VendorOption name="maxDisplacement">50</VendorOption>
    <VendorOption name="maxAngleDelta">30</VendorOption>
    <VendorOption name="spaceAround">30</VendorOption>
  </TextSymbolizer>
</Rule>
  • why are you calculating the remainder of the value? – Ian Turton Nov 13 '17 at 15:14
  • @IanTurton, because I don't want to show all the contour-lines between this range, just some of them(each 5 band) regarding to better performance. and also this is also my whole SLD in this question. gis.stackexchange.com/questions/261593/… – GeoCom Nov 13 '17 at 15:21
1

Your filter is wrong, currently, it compares the remainder of (value/50) to 200 and 400. So if you have contours between 10000 and 20000 they will be drawn and labelled.

I think you want something like:

<Rule>
  <Name>Draw Contours</Name>
  <Title>Height (200-400)</Title>

  <ogc:Filter>
    <ogc:PropertyIsBetween>
       <ogc:PropertyName>value</ogc:PropertyName>      
       <ogc:LowerBoundary>
            <ogc:Literal>200</ogc:Literal>
        </ogc:LowerBoundary>
        <ogc:UpperBoundary>
            <ogc:Literal>400</ogc:Literal>
        </ogc:UpperBoundary>
    </ogc:PropertyIsBetween>
  </ogc:Filter>
  <LineSymbolizer>
    [....]
  </LineSymbolizer>
</Rule>
<Rule>
<ogc:Filter>
    <ogc:And>
    <ogc:PropertyIsEqualTo>
      <ogc:Function name="IEEERemainder">
        <ogc:Function name="int2ddouble">
            <ogc:PropertyName>value</ogc:PropertyName>
        </ogc:Function>
        <ogc:Function name="parseDouble">
            <ogc:Literal>50.0</ogc:Literal>
        </ogc:Function>
    </ogc:Function>
    <ogc:Literal>0</ogc:Literal>
    </ogc:PropertyIsEqualTo>
    <ogc:PropertyIsBetween>
       <ogc:PropertyName>value</ogc:PropertyName>      
       <ogc:LowerBoundary>
            <ogc:Literal>200</ogc:Literal>
        </ogc:LowerBoundary>
        <ogc:UpperBoundary>
            <ogc:Literal>400</ogc:Literal>
        </ogc:UpperBoundary>
    </ogc:PropertyIsBetween>
    </ogc:And>
  </ogc:Filter>
  <MaxScaleDenominator>120000</MaxScaleDenominator>
  <TextSymbolizer>
    <Label>
      <ogc:Function name="round">
        <ogc:PropertyName>value</ogc:PropertyName>
      </ogc:Function>
    </Label>
    <Font>
      <CssParameter name="font-family">Arial</CssParameter>
      <CssParameter name="font-weight">Normal</CssParameter>
      <CssParameter name="font-size">12</CssParameter>
    </Font>
    <LabelPlacement>
      <LinePlacement/>
    </LabelPlacement>
    <Halo>
      <Radius>
        <ogc:Literal>2</ogc:Literal>
      </Radius>
      <Fill>
        <CssParameter name="fill">#FFFFFF</CssParameter>
        <CssParameter name="fill-opacity">0.9</CssParameter>        
      </Fill>
    </Halo>
    <Fill>
      <CssParameter name="fill">#ff0000</CssParameter>
    </Fill>
    <Priority>2000</Priority>
    <VendorOption name="followLine">true</VendorOption>
    <VendorOption name="repeat">300</VendorOption>
    <VendorOption name="maxDisplacement">50</VendorOption>
    <VendorOption name="maxAngleDelta">30</VendorOption>
    <VendorOption name="spaceAround">30</VendorOption>
  </TextSymbolizer>
</Rule>
  • shouldn't be the <ogc:And> closed, before filter? – GeoCom Nov 13 '17 at 16:14
  • almost certainly – Ian Turton Nov 13 '17 at 16:20
  • fixed now...... – Ian Turton Nov 13 '17 at 16:21

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.