1

I've a PostGIS table published as a layer, I need to style this layer using SLD. I need to call a custom OWS function (which I wrote) from inside the SLD. It should look something like:

<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0"
  xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/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>test_fn_call</Name>
    <UserStyle>
      <Title>dark yellow square point style</Title>
      <FeatureTypeStyle>
        <Rule>
          <Title>dark yellow point</Title>
          <PointSymbolizer>
            <Graphic>
              <Mark>
                <WellKnownName>square</WellKnownName>
                <Fill>
                  <CssParameter name="fill">#99cc00</CssParameter>
                </Fill>
              </Mark>
              <Size>
              <ogc:Function name="gs:calcSize">
                <ogc:Function name="parameter">
                    <!-- **** What should I write here? **** -->
                </ogc:Function>
              </ogc:Function>
              </Size>
            </Graphic>
          </PointSymbolizer>
        </Rule>

      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

calcSize is a function to calculate point size depending on some calculations on the feature's fields.

My question is what should I write as a parameter of this function, actually I need to path the current feature as a parameter, so what should I write in the SLD as a parameter?

Also in the java side, what should the parameter type be?

2

In the SLD you need to name the properties being passed into the function as is shown in this example.

In the function itself you need to specify the parameter types you expect and then you receive a list of Parameters that it is up to your code to extract and check. See the function tutorial for more detail.

public class SnapFunction implements Function {

    static FunctionName NAME = new FunctionNameImpl("snap", Point.class,
            FunctionNameImpl.parameter("point",Point.class),
            FunctionNameImpl.parameter("line",Geometry.class));

    private final List<Expression> parameters;

    private final Literal fallback;

    public SnapFunction(List<Expression> parameters, Literal fallback) {
        if (parameters == null) {
            throw new NullPointerException("parameters required");
        }
| improve this answer | |

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.