Skip to content

Managing Mosaic Layers

Simone Giannecchini edited this page Aug 1, 2013 · 14 revisions

Publishing an external mosaic in geoserver

The following code will create an external coverage store in GeoServer also publishing the layer:

// layer encoder
final GSLayerEncoder layerEnc = new GSLayerEncoder();
String style=getDefaultStyle();
if (style==null || style.isEmpty())
 style="raster";
layerEnc.setDefaultStyle(style);

// coverage encoder
final GSImageMosaicEncoder coverageEnc=new GSImageMosaicEncoder();
coverageEnc.setName(mosaicDescriptor.getCoverageStoreId());
coverageEnc.setTitle(mosaicDescriptor.getCoverageStoreId());
if (config.getCrs()!=null){
 coverageEnc.setSRS(config.getCrs());
}
coverageEnc.setMaxAllowedTiles(Integer.MAX_VALUE); 

// ... many other options are supported

// create a new ImageMosaic layer...
final boolean published = gsPublisher.publishExternalMosaic(workspace, storeName, baseDir, coverageEnc, layerEnc);

// check the results
if (!published) {
 final String msg="Error creating the new store: " + layerName;
 Exception ex = new Exception(this.getClass(), msg);
} 

Complete Example to create, configure and query an ImageMosaic from REST

The code is taken from a test-case that does configure a small ImageMosaic with custom dimensions. Check the internal comments for more information, the code is quite documented.

The test data and the mosaic configuration used in the example can be found here.

The link to the live code can be found here