Extending GeoServer Styling with Geometry Transformations
December 22, 2010
While designing a map style, sometimes it is necessary to manipulate the geometries representation on-the-fly. For instance a straight line should be drawn as a sinuous line or plain building footprints should be decorated with a 3D effect. ESRI developers might be familiar with the various rendering extension interfaces in ArcObjects API.
With GeoTools/Geoserver there are similar extension points as well – although somewhat hidden. So here is a little sample for a custom geometry transformation function one can add to the GeoTools rendering module.
First create a java class that extends from org.geotools.filter.FunctionExpressionImpl and implement your geometry manipulation function inside the #evaluate method. If you need some examples, look at the existing classes that extend from FunctionExpressionImpl.
Second, to register that class to the GeoTools service provider interface: add a file named “org.opengis.filter.expression.Function” to the “META-INF/services” directory of your JAR file and add a line with the full class name of the java class (that one extending from FunctionExpressionImpl) to this file.
Third, create a JAR with your class and the META-INF and add it to the Geoserver’s classpath.
Fourth, create a SLD style where this new geometry function is used:
<FeatureTypeStyle>
<Rule>
<PolygonSymbolizer>
<Geometry>
<ogc:Function name="magic">
<ogc:PropertyName>the_geom</ogc:PropertyName>
<ogc:PropertyName>bld_height</ogc:PropertyName>
</ogc:Function>
</Geometry>
<Stroke>
<CssParameter name="stroke">#888888</CssParameter>
<CssParameter name="stroke-width">0.6</CssParameter>
</Stroke>
</PolygonSymbolizer>
</Rule>
</FeatureTypeStyle>
Voilá… oh I forgot to say, that of course you can pass other attributes from the feature to your function class – like with my example the attribute “building height” to control the height of the 3D wire frame.











January 31, 2011 at 9:45 pm
Thanks for the great example of user defined Styles and the comparison to the commercial Esri ArcGIS solutions. Have you seen the Geoserver example at http://tinyurl.com/6345bml ? There you can find a sample SLD file where the already defined “offset” function is used for geometry creation. You don’t need Java experience to solve 3D requirements.
Cheers, Frank
March 11, 2011 at 1:49 pm
Here is an other example to extend the styling engine :
http://ian01.geog.psu.edu/geoserver_docs/cartogram/discontinous.html#discontinuous-cartograms