ResourceInfo with native style
- Contact: Jorge Gustavo Rocha
- Tracker: https://osgeo-org.atlassian.net/browse/GEOT-1234
- TLDR: Access native styles through ResourceInfo
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:
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
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
- Introduce ResourceInfo with
getDefaultStyle()
,getNativeStyles()
andgetNativeStyle(name)
methods - Implement for ShapefileDataStore, using uDig as an example
- Implement for GeoPackage
- Implement for PostGIS, using GeoPackage as an example
- Update the user guide with code example
Proposed:
public interface ResourceInfo {
StyledLayerDescriptor getDefaultStyle() {
return null;
}
List<String> getNativeStyles(){
return Collections.emptyList();
}
StyledLayerDescriptor getNativeStyle(String name) {
return null;
}
}
https://github.com/geotools/geotools/pull/1851
Simple screen cast, working on the geotools tutorial to show how the new API works.
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);
}