This page last changed on Aug 24, 2008 by jdeolive.

Some quick and dirty notes about supporting KML extrudes in GeoServer.

The Template

The approach taken to generate extrude or elevation values is similar to that used to generate timestamps via templates. This involves the addition of another template, called height.ftl.

The template can contain a reference to attributes, an algebraic expression, etc... Some examples:

height.ftl
# single attribute
${x.value}

# expression on a single attribute
${x.value}*3 + 50;

# expression on multiple attributes
${x.value}%${y.value}

Loading and executing the template should draw inspiration from the FeatureTimeTemplate class, creating a class called FeatureHeightTemplate:

public class FeatureHeightTemplate {

    FeatureTemplate delegate;

    public Double execute( Feature feature ) {
       //execute the template
       String output = delegate.template(feature, "height.ftl", getClass() );
       
       //convert to double
       return Double.parseDouble( output );
    }
}

KML Output

The next step is modify the KML transformer to utilize the height value. This will occur in the method KMLMapTransformer#encodePlacemarkGeometry()}. When the {{height.ftl exists the method should:

  1. output the kml extrude element
      <extrude>1</extrude>
      <altitudeMode>relativeToGround</altitudeMode>
    
  2. execute the template
  3. append the result as the "z" value for each coordinate in the geometry

In order to set the z value the class KMLGeometryTransformer should be subclassed / modified. One possible approach is to introduce a template method called from GeometryTransformer#encode(Geometry,String,int which is used to get the CoordinateSequence from a geometry. KMLGeometryTransformer can then override the method and wrap the coordinate sequence in a class which forces 3 dimensions, and returns the height value for the third dimension of each coordinate.

Format Options

By default, the altitude mode used for elevation values is relativeToGround. However there are cases where absolute mode will be desired, so a format option should be added to support this case:

geoserver/wms/kml?layers=topp:states&format_options=altitudeMode:absolute
Document generated by Confluence on May 14, 2014 23:00