Search in sources :

Example 1 with CachedRasterSymbolizer

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);
    }
}
Also used : org.geotoolkit.process(org.geotoolkit.process) DataStoreException(org.apache.sis.storage.DataStoreException) Parameters(org.apache.sis.parameter.Parameters) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) MapLayer(org.apache.sis.portrayal.MapLayer) CoverageQuery(org.apache.sis.storage.CoverageQuery) ExceptionPresentation(org.apache.sis.internal.map.ExceptionPresentation) Presentation(org.apache.sis.internal.map.Presentation) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) MutableStyle(org.geotoolkit.style.MutableStyle) TextSymbolizer(org.opengis.style.TextSymbolizer) LineSymbolizer(org.opengis.style.LineSymbolizer) ExceptionPresentation(org.apache.sis.internal.map.ExceptionPresentation) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) FeatureSet(org.apache.sis.storage.FeatureSet) CachedRasterSymbolizer(org.geotoolkit.display2d.style.CachedRasterSymbolizer)

Aggregations

GridCoverage (org.apache.sis.coverage.grid.GridCoverage)1 ExceptionPresentation (org.apache.sis.internal.map.ExceptionPresentation)1 Presentation (org.apache.sis.internal.map.Presentation)1 Parameters (org.apache.sis.parameter.Parameters)1 MapLayer (org.apache.sis.portrayal.MapLayer)1 CoverageQuery (org.apache.sis.storage.CoverageQuery)1 DataStoreException (org.apache.sis.storage.DataStoreException)1 FeatureSet (org.apache.sis.storage.FeatureSet)1 GridCoverageResource (org.apache.sis.storage.GridCoverageResource)1 CachedRasterSymbolizer (org.geotoolkit.display2d.style.CachedRasterSymbolizer)1 org.geotoolkit.process (org.geotoolkit.process)1 InMemoryGridCoverageResource (org.geotoolkit.storage.memory.InMemoryGridCoverageResource)1 MutableStyle (org.geotoolkit.style.MutableStyle)1 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)1 LineSymbolizer (org.opengis.style.LineSymbolizer)1 TextSymbolizer (org.opengis.style.TextSymbolizer)1