Skip to content

GSIP 131

Jody Garnett edited this page Oct 5, 2015 · 16 revisions

GSIP 131 - Style Generation for all formats

Overview

Promote org.geoserver.importer.StyleGenerator to a core class and add support for generating styles of all formats (SLD, CSS, ...).

Proposed By

Torben Barsballe

Assigned to Release

This proposal is for GeoServer 2.8-beta (the API and UI changes are compelte), the REST API will be ready later.

State

  • Under Discussion
  • In Progress
  • Completed
  • Rejected
  • Deferred

Motivation

Style Generation is a useful utility that has so far been limited to SLD styles generated by the importer extension. This change would allow core GeoServer methods to access this functionality, and extend style generation to support all formats. One potential future use case is the ability to generate a default style when creating a new style in geoserver (Either through the Web UI, the REST API, or programatically). One particular benefit is the ability to generate default CSS styles. Currently, SLD styles cannot be converted to CSS, and there is no code that generates CSS styles - all styles must be written by hand (or copied from the documentation). While importer will retain its current functionality, this also opens up the potential to generate non-SLD default styles during an import, in cases where other formats are preferred.

Proposal

API Change

Move org.geoserver.importer.StyleGenerator and associated tests (StyleGeneratorTest) and resources (template_point.sld, template_line.sld, template_polygon.sld, template_generic.sld) in gs-importer to org.geoserver.catalog.StyleGenerator in gs-main.

Add the public String getTemplate() method to the abstract class StyleHandler in gs-main. StyleGenerator will call this method to obtain the template for a given StyleHandler.

public abstract class StyleHandler {
    /**
     * Generates a template style using provided substitutionMap from StyleGenerator.
     *
     * @param type: the template type, see {@link org.geoserver.catalog.StyleType}.
     * @param color: java.aw.Color to use during substitution
     * @param colorName: Human readable color name, for use generating comments
     * @param layerName: Layer name, for use generating comments
     */
    String getTemplate(StyleType type, Color color, String colorName, String layerName);
}

Where StyleType has been made public:

public enum StyleType {
    POINT,      //Point Feature Type
    LINE,       //Line Feature Type
    POLYGON,    //Polygon Feature Type
    RASTER,     //Coverage Type
    GENERIC     //Unknown Type
}

Add a new Generate from template style section to the New/Edit Style page, with a drop-down menu to select a template and a link to generate the style.

Implementation

StyleGenerator.createStyle() will be modified to accept a StyleHandler, used to retrieve the style templates an other information specific to the style format. The importer extension will be modified to use the updated StyleGenerator. CSS template styles will be created, to be returned by CSSHandler.getTemplate().

Feedback

Backwards Compatibility

Since this is solely an addition to the core geoserver API, there should be no conflicts. When a StyleHandler does not implement getTemplate(), and UnsupportedOperationException will be thrown. In this case, the StyleGenerator try to convert an SLD template to the requisite format. This provides some measure of support for third-party formats.

Voting

  • Alessio Fabiani
  • Andrea Aime +1
  • Ben Caradoc-Davies +0
  • Christian Mueller
  • Jody Garnett +1
  • Jukka Rahkonen
  • Phil Scadden +1
  • Simone Giannecchini

Links

Email Discussion

Pull request - initial pull request

Clone this wiki locally