[GIS] How to use the SLD Filter “Difference”

filtersld

I have a postgis table with polygon geometries.

I would like to create an sld which first does an inside buffer, and then a difference between the buffer and the original geometry.

This is basically like cutting a hole out of the polygon….ie first buffer (say…50 meters) and then cut this buffered polygon out of the original polygon.

I can´t seem to get my head around the syntax of using the sld filter explained here

http://docs.geoserver.org/stable/en/user/filter/function_reference.html

<Intersects>
<PropertyName>GEOMETRY</PropertyName>
<Literal>
<gml:Point>
<gml:coordinates>1 1</gml:coordinates>
</gml:Point>
</Literal>
</Intersects>

This is an intersect function which only displays the points which intersect 1,1. I guess a DIFFERENCE function with a buffer would have to be somehow nested…but I don´t know if this is possible.

If anyone can help. i´d be really grateful,

yours,
Rob

Best Answer

Try this,

<PolygonSymbolizer>
          <Geometry>
        <ogc:Function name="difference">    
          <ogc:PropertyName>geom</ogc:PropertyName>
          <ogc:Function name="buffer">
            <ogc:PropertyName>geom</ogc:PropertyName>
            <ogc:Literal>-50</ogc:Literal>
          </ogc:Function>
          </ogc:Function>
          </Geometry>
          <Fill>
          <CssParameter name="fill">#894465</CssParameter>
          <CssParameter name="fill-opacity">0.5</CssParameter>  
        </Fill>
      </PolygonSymbolizer>

It works in geoserver 2.7-SNAPSHOT (rev 38562)

Related Question