1

I am trying to pass my fill parameter for GeoServer SLD and I am using SVG, found some reference from here GeoServer filter , but getting below error, also sharing the working code where I tried to make rule with and filter

This sample svg can be use here, with any sample data which have two attributes here in my case act_id and structure_type

This one will create dynamic fill value depending upon property value

        <Rule>
          <Name>Cement Nala Bunds</Name>
          <Filter>
            <PropertyIsEqualTo>
              <PropertyName>act_id</PropertyName>
              <Literal>305</Literal>
            </PropertyIsEqualTo>
          </Filter>
          <PointSymbolizer>
            <Graphic>
              <ExternalGraphic>
                <OnlineResource
                   xlink:type="simple" 
                   xlink:href="nrm_styles/KTW.svg?fill=${if_then_else(structure_type == 'existing', '#cfcccc', '#84fa8d')}" />
                <Format>image/svg+xml</Format>
              </ExternalGraphic>
              <Size>
                <Literal>20</Literal>
              </Size>
            </Graphic>
          </PointSymbolizer>
        </Rule>

This one is working which will be forced to make seperate rule for each condintion which will be repeatable

       <Rule>
          <Name>Cement Nala Bunds</Name>
          <Filter>
            <And>
              <PropertyIsEqualTo>
                <PropertyName>act_id</PropertyName>
                <Literal>305</Literal>
              </PropertyIsEqualTo>
              <PropertyIsEqualTo>
                <PropertyName>structure_type</PropertyName>
                <Literal>existing</Literal>
              </PropertyIsEqualTo>
            </And>
          </Filter>
          <PointSymbolizer>
            <Graphic>
              <ExternalGraphic>
                <OnlineResource xlink:type="simple" xlink:href="nrm_styles/KTW.svg?fill=#84fa8d" />
                <Format>image/svg+xml</Format>
              </ExternalGraphic>
              <Size>
                <Literal>20</Literal>
              </Size>
            </Graphic>
          </PointSymbolizer>
        </Rule>

Error

java.lang.illegalArgumentException: Invalid cql expression 'if_then_else(structure_type == 'existing', '#cfcccc', '#84fa8d')'
Invalid cql expression 'if_then_else(structure_type == 'existing', '#cfcccc', '#84fa8d')'
Encountered "==" at line 1, column 29.
was expecting one of:
    ")"...
    "."...
    ":"...
    "*"...
    "+"...  
    <IDENTIFIER>...
    "("...
    Parsing : 'if_then_else(structure_type == 'existing', '#cfcccc', '#84fa8d')'

Also trying same thing in CSS module using recode and dynamic url as suggested by previous question

/* @title Cement Nala */
[act_id = 305] {
  mark: url('KTW.svg?fill=#cfcccc');
  mark-mime: "image/svg+xml";
  mark-size: 20;
}

/* @title Cement Nala Bund */
[act_id = 322] {
  mark: url('${if_then_else(structure_type=existing, KTW.svg?fill=#cfcccc, KTW.svg?fill=#ff0000)}');
  mark-mime: "image/svg+xml";
  mark-size: 20;
}


/* @title Cement Nala Bund  */
[act_id = 322] {
  mark-size: 20; 
  :mark {
    url: [
    recode(structure_type,
      'existing','KTW.svg?fill=#ff0000',
      'proposed','KTW.svg?fill=#ff9933'
    )]
  };
  mark-mime: "image/svg+xml";
}
5
  • 3
    please post the error from the log file as text not an unreadable image
    – Ian Turton
    Commented Oct 22 at 13:29
  • Please click one the image it will open in readable size
    – SpiderMan
    Commented Oct 22 at 13:32
  • 3
    Images are unreadable - please paste in the text!
    – Ian Turton
    Commented Oct 22 at 14:41
  • 1
    Images are not legible on all devices, and can't be searched by others with the same issue. Text logs should always be posted as text.
    – Vince
    Commented Oct 22 at 15:30
  • please check updated version of question.
    – SpiderMan
    Commented Oct 23 at 5:51

1 Answer 1

1

I haven't got anything handy to test this on, but I think you just need one '=' instead of '=='.

if_then_else(structure_type = 'existing', '#cfcccc', '#84fa8d')

ECQL Reference: https://docs.geoserver.org/stable/en/user/filter/ecql_reference.html

4
  • you can see the other example in the format of css style, where i tried this approach which is not working
    – SpiderMan
    Commented Oct 24 at 8:21
  • Did you try it in the SLD? You could also try equalTo(), e.g. if_then_else(equalTo(structure_type,'existing'), '#cfcccc', '#84fa8d')) Commented Oct 24 at 16:35
  • as suggested by @SirLostalot tried this approach <OnlineResource xlink:type="simple" xlink:href="KTW.svg?fill=${if_then_else(equalTo(structure_type,'existing'), '#cfcccc', '#84fa8d'))}" /> but error says line 23: cvc-datatype-valid.1.2.1: 'KTW.svg?fill=${if_then_else(equalTo(structure_type,'existing'), '#cfcccc', '#84fa8d'))}' is not a valid value for 'anyURI'. line 23: cvc-attribute.3: The value 'KTW.svg?fill=${if_then_else(equalTo(structure_type,'existing'), '#cfcccc', '#84fa8d'))}' of attribute 'xlink:href' on element 'OnlineResource' is not valid with respect to its type, 'anyURI'
    – SpiderMan
    Commented Oct 25 at 12:41
  • That one might be to do with the '#''s in the colour hex. And my knowledge of this issue is fading fast..... You could try replacing those with something like '&#35;' depending on the encoding, but I'd put that outside of the if_then_else. Perhaps KTW.svg?fill=&#35;${if_then_else(equalTo(structure_type,'existing'),'cfcccc', '84fa8d'))}. Commented Oct 25 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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