use of org.geotoolkit.display2d.style.CachedRasterSymbolizer in project geotoolkit by Geomatys.
the class IsolineSymbolizerRenderer method presentations.
@Override
public Stream<Presentation> presentations(MapLayer layer, Resource resource) {
if (!(resource instanceof GridCoverageResource)) {
return Stream.empty();
}
final GridCoverageResource coverageReference = (GridCoverageResource) resource;
final IsolineSymbolizer isolineSymbolizer = symbol.getSource();
try {
Stream<Presentation> stream = Stream.empty();
// //////////////////
// 1 - Render raster
// //////////////////
final CachedRasterSymbolizer cachedRasterSymbolizer = symbol.getCachedRasterSymbolizer();
if (!isolineSymbolizer.getIsolineOnly() || isJenksFunction(cachedRasterSymbolizer)) {
final MapLayer sublayer = MapBuilder.createLayer(coverageReference);
sublayer.setStyle(GO2Utilities.STYLE_FACTORY.style(cachedRasterSymbolizer.getSource()));
stream = Stream.concat(stream, DefaultPortrayalService.present(sublayer, coverageReference, renderingContext));
}
final LineSymbolizer lineSymbolizer = isolineSymbolizer.getLineSymbolizer();
final TextSymbolizer textSymbolizer = isolineSymbolizer.getTextSymbolizer();
// //////////////////
if (lineSymbolizer != null) {
double[] intervales = symbol.getSteps();
final CoverageQuery query = new CoverageQuery();
query.setSelection(renderingContext.getGridGeometry());
query.setSourceDomainExpansion(2);
final GridCoverageResource res = coverageReference.subset(query);
final GridCoverage inCoverage = res.read(null).forConvertedValues(true);
final GridCoverageResource resampledCovRef = new InMemoryGridCoverageResource(coverageReference.getIdentifier().orElse(null), inCoverage);
// ///////////////////
// 2.2 - Compute isolines
// //////////////////
FeatureSet isolines = null;
final ProcessDescriptor isolineDesc = symbol.getIsolineDesc();
if (isolineDesc != null) {
final Parameters inputs = Parameters.castOrWrap(isolineDesc.getInputDescriptor().createValue());
inputs.getOrCreate(IsolineDescriptor.COVERAGE_REF).setValue(resampledCovRef);
inputs.getOrCreate(IsolineDescriptor.INTERVALS).setValue(intervales);
final org.geotoolkit.process.Process process = isolineDesc.createProcess(inputs);
final ParameterValueGroup result = process.call();
isolines = (FeatureSet) result.parameter(IsolineDescriptor.FCOLL.getName().getCode()).getValue();
}
// //////////////////
if (isolines != null) {
MutableStyle featureStyle = null;
if (textSymbolizer != null) {
featureStyle = GO2Utilities.STYLE_FACTORY.style(lineSymbolizer, textSymbolizer);
} else {
featureStyle = GO2Utilities.STYLE_FACTORY.style(lineSymbolizer);
}
MapLayer fml = MapBuilder.createLayer(isolines);
fml.setStyle(featureStyle);
stream = Stream.concat(stream, DefaultPortrayalService.present(fml, isolines, renderingContext));
}
}
return stream;
} catch (DataStoreException | ProcessException ex) {
ExceptionPresentation ep = new ExceptionPresentation(ex);
ep.setLayer(layer);
ep.setResource(resource);
return Stream.of(ep);
}
}
Aggregations