Skip to content

ResourceInfo with native style

Jorge Gustavo Rocha edited this page Apr 3, 2018 · 5 revisions

Description

Take a couple paragraphs to describe the change, motivations and link out to any design documents. It is especially important to highlight any customer requirements or deadlines.

GeoPackage, PostGIS and Shapefile sidecar files can all be used to associate a StyleLayerDescriptor with a GeoTools FeatureSource.

This proposal enhances ResoureInfo with additional methods to access these native styles.

Context:

  • The uDig application already uses SLD sidecar files and serves as a prototype for this work.
  • GeoPackage has a layer_styles table that contains QGIS and SLD files
  • PostGIS has a layer_styles table that contains QGIS and SLD files

Open design questions:

  • Should the native styles should be StyleLayerDescriptor, or just FeatureTypeStyle as they are defined per-layer.

  • The GeoPackage layer_styles table has a column for styleqml and stylesld, this is probably a mistake for a general purpose specification as it does not allow different versions of the SLD specification to be used and is product specific (the styleqml) file. Recommend switching to schema (name, format, style), where format could be "sld-1.0", "se-1.1", "sld-1.1", "qml-2","mbstyle-8" etc...

References:

Status

Choose one of:

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

Voting:

  • Andrea Aime
  • Ben Caradoc-Davies
  • Christian Mueller
  • Ian Turton
  • Justin Deoliveira
  • Jody Garnett
  • Simone Giannecchini

Tasks

This section is used to make sure your proposal is complete (did you remember documentation?) and has enough paid or volunteer time lined up to be a success. Use initials to indicate volunteer, or ⚠️ where volunteer is neededs. Proposals that lack resources to be successful are unlikely to be approved.

  1. Introduce ResourceInfo with getDefaultStyle(), getNativeStyles() and getNativeStyle(name) methods
  2. Implement for ShapefileDataStore, using uDig as an example
  3. Implement for GeoPackage
  4. Implement for PostGIS, using GeoPackage as an example
  5. Update the user guide with code example

API Change

Proposed:

public interface ResourceInfo {
   StyledLayerDescriptor getDefaultStyle() {
      return null;
   }
   List<String> getNativeStyles(){
      return Collections.emptyList();
   }
   StyledLayerDescriptor getNativeStyle(String name) {
      return null;
   }
}

PR

https://github.com/geotools/geotools/pull/1851

Usage example

Simple screen cast, working on the geotools tutorial to show how the new API works.

Screen cast

Code example

The first code example, that can be used in the Map Style Tutorial would be:

    private void displayShapefile() throws Exception {
        Style style = null;

        File file = JFileDataStoreChooser.showOpenFile("shp", null);
        if (file == null) {
            return;
        }

        FileDataStore store = FileDataStoreFinder.getDataStore(file);
        FeatureSource featureSource = store.getFeatureSource();
        ResourceInfo rinfo = featureSource.getInfo();
        StyledLayerDescriptor styledld = rinfo.getDefaultStyle();
        if (styledld != null) {
            NamedLayer nlayer = (NamedLayer) styledld.getStyledLayers()[0];
            style = nlayer.getStyles()[0];
        }

        MapContent map = new MapContent();
        map.setTitle("GeoTools Native Style Lab");

        if (style == null) {
            // There is no sidecar SLD file
            style = createStyle(file, featureSource);
        }
        Layer layer = new FeatureLayer(featureSource, style);
        map.addLayer(layer);

        JMapFrame.showMap(map);
    }
Clone this wiki locally