0

I have a database: database

and I made with it a GeoServer getMap request which works great for one year (one column). enter image description here But I want to change the year programmatically with JavaScript (I am open for better ideas). For that I found the "env" function in SLD: https://docs.geoserver.org/stable/en/user/styling/sld/extensions/substitution.html But the following code does not work:

<Rule>
       ...
        <ogc:PropertyIsLessThan>
          <ogc:PropertyName>
            <ogc:Function name="env">
              <ogc:Literal>years</ogc:Literal>
              <ogc:Literal>yr1995</ogc:Literal>
            </ogc:Function>
          </ogc:PropertyName>
          <ogc:Literal>10</ogc:Literal>
         </ogc:PropertyIsLessThan>
       ...
     </Rule>

In the PropertyName-Tag I am writing the column name. If I only would write this:

<ogc:PropertyName>yr1995</ogc:PropertyName>

then all the data are properly displayed in the map. But I want, that in the URL I can pass a year with ...&env=years:yr2015... as in in the documentation written. So my goal is that I pass a year as parameter in the URL and in SLD I take the column which is passed with the URL. So what am I doing wrong in the above code?

2

A PropertyName can only contain a fixed string, it cannot work with an expression inside (by OGC filter specification).

What you are trying to do can be achieved using a dedicated filter function, called "property", which allows for dynamic property lookups. Something like this should work (but did not test it, mind):

         <ogc:PropertyIsLessThan>
          <ogc:Function name="property">
            <ogc:Function name="env">
              <ogc:Literal>years</ogc:Literal>
              <ogc:Literal>yr1995</ogc:Literal>
            </ogc:Function>
          </ogc:Function>
          <ogc:Literal>10</ogc:Literal>
         </ogc:PropertyIsLessThan>

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.