Search in sources :

Example 1 with RasterSymbolizer

use of org.opengis.style.RasterSymbolizer in project geotoolkit by Geomatys.

the class KmzContextInterpreter method writeSymbolizer.

/**
 * Writes KML color styles mapping SLD Symbolizers.
 * Color styles are written into KML Style selector.
 */
private AbstractStyleSelector writeSymbolizer(Symbolizer symbolizer, Style styleSelector) {
    if (symbolizer instanceof ExtensionSymbolizer) {
    } else // LineSymbolizer mapping
    if (symbolizer instanceof LineSymbolizer) {
        final LineSymbolizer lineSymbolizer = (LineSymbolizer) symbolizer;
        final LineStyle lineStyle = ((styleSelector.getLineStyle() == null) ? KML_FACTORY.createLineStyle() : styleSelector.getLineStyle());
        lineStyle.setWidth((Double) this.writeExpression(lineSymbolizer.getStroke().getWidth(), Double.class, null));
        lineStyle.setColor((Color) this.writeExpression(lineSymbolizer.getStroke().getColor(), Color.class, null));
        styleSelector.setLineStyle(lineStyle);
    } else // PointSymbolizezr mapping
    if (symbolizer instanceof PointSymbolizer) {
    // PointSymbolizer pointSymbolizer = (PointSymbolizer) symbolizer;
    // IconStyle iconStyle = KML_FACTORY.createIconStyle();
    // GraphicalSymbol gs = ((GraphicalSymbol) pointSymbolizer.getGraphic().graphicalSymbols().get(0));
    // gs.
    } else // PolygonSymbolizer mapping
    if (symbolizer instanceof PolygonSymbolizer) {
        final PolygonSymbolizer polygonSymbolizer = (PolygonSymbolizer) symbolizer;
        final PolyStyle polyStyle = KML_FACTORY.createPolyStyle();
        // Fill
        if (polygonSymbolizer.getFill() == null) {
            polyStyle.setFill(false);
        } else {
            polyStyle.setFill(true);
            polyStyle.setColor((Color) this.writeExpression(polygonSymbolizer.getFill().getColor(), Color.class, null));
        }
        // Outline
        if (polygonSymbolizer.getStroke() == null) {
            polyStyle.setOutline(false);
        } else if (styleSelector.getLineStyle() == null) {
            polyStyle.setOutline(true);
            final LineStyle lineStyle = KML_FACTORY.createLineStyle();
            lineStyle.setColor((Color) this.writeExpression(polygonSymbolizer.getStroke().getColor(), Color.class, null));
            lineStyle.setWidth((Double) this.writeExpression(polygonSymbolizer.getStroke().getWidth(), Double.class, null));
            styleSelector.setLineStyle(lineStyle);
        }
        styleSelector.setPolyStyle(polyStyle);
    } else if (symbolizer instanceof RasterSymbolizer) {
    } else if (symbolizer instanceof TextSymbolizer) {
        final TextSymbolizer textSymbolizer = (TextSymbolizer) symbolizer;
        final LabelStyle labelStyle = KML_FACTORY.createLabelStyle();
        if (textSymbolizer.getFont() != null) {
            textSymbolizer.getFont().getSize();
        }
        if (textSymbolizer.getFill() != null) {
            labelStyle.setColor((Color) this.writeExpression(textSymbolizer.getFill().getColor(), Color.class, null));
        }
        styleSelector.setLabelStyle(labelStyle);
    }
    return styleSelector;
}
Also used : RasterSymbolizer(org.opengis.style.RasterSymbolizer) PointSymbolizer(org.opengis.style.PointSymbolizer) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) TextSymbolizer(org.opengis.style.TextSymbolizer) LineStyle(org.geotoolkit.data.kml.model.LineStyle) LineSymbolizer(org.opengis.style.LineSymbolizer) Color(java.awt.Color) LabelStyle(org.geotoolkit.data.kml.model.LabelStyle) ExtensionSymbolizer(org.opengis.style.ExtensionSymbolizer) PolyStyle(org.geotoolkit.data.kml.model.PolyStyle)

Example 2 with RasterSymbolizer

use of org.opengis.style.RasterSymbolizer in project geotoolkit by Geomatys.

the class MeridianTest method createCoverageLayer.

private static MapLayers createCoverageLayer(Envelope env) {
    final BufferedImage image = new BufferedImage((int) env.getSpan(0), (int) env.getSpan(1), BufferedImage.TYPE_INT_RGB);
    final Graphics2D g2d = image.createGraphics();
    g2d.setColor(Color.RED);
    g2d.fillRect(0, 0, image.getWidth(), image.getHeight());
    final GridCoverageBuilder gcb = new GridCoverageBuilder();
    gcb.setDomain(new GridGeometry(null, PixelInCell.CELL_CORNER, new AffineTransform2D(1, 0, 0, -1, env.getMinimum(0), env.getMaximum(1)), env.getCoordinateReferenceSystem()));
    gcb.setValues(image);
    final GridCoverage coverage = gcb.build();
    final RasterSymbolizer symbol = SF.rasterSymbolizer();
    final MutableStyle style = SF.style(symbol);
    final MapLayer layer = MapBuilder.createCoverageLayer(coverage, style, "test");
    final MapLayers context = MapBuilder.createContext();
    context.getComponents().add(layer);
    return context;
}
Also used : RasterSymbolizer(org.opengis.style.RasterSymbolizer) GridGeometry(org.apache.sis.coverage.grid.GridGeometry) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) MutableStyle(org.geotoolkit.style.MutableStyle) GridCoverageBuilder(org.apache.sis.coverage.grid.GridCoverageBuilder) MapLayer(org.apache.sis.portrayal.MapLayer) BufferedImage(java.awt.image.BufferedImage) AffineTransform2D(org.apache.sis.internal.referencing.j2d.AffineTransform2D) Graphics2D(java.awt.Graphics2D) MapLayers(org.apache.sis.portrayal.MapLayers)

Example 3 with RasterSymbolizer

use of org.opengis.style.RasterSymbolizer in project geotoolkit by Geomatys.

the class RasterSymbolizerRenderer method presentations.

@Override
public Stream<Presentation> presentations(MapLayer layer, Feature feature) {
    final RasterSymbolizer sourceSymbol = symbol.getSource();
    final Object candidate = GO2Utilities.evaluate(sourceSymbol.getGeometry(), feature, null, null);
    GridCoverageResource ref = null;
    if (candidate instanceof GridCoverageResource) {
        ref = (GridCoverageResource) candidate;
    } else if (candidate instanceof GridCoverage) {
        ref = new InMemoryGridCoverageResource((GridCoverage) candidate);
    } else {
        return Stream.empty();
    }
    try {
        final int[] channelSelection = channelSelection(sourceSymbol, ref);
        final GridCoverage dataCoverage = getObjectiveCoverage(ref, renderingContext.getGridGeometry(), false, channelSelection);
        if (dataCoverage == null) {
            return Stream.empty();
        }
        final GridCoverage2D dataImage = applyStyle(ref, dataCoverage, sourceSymbol);
        final RasterPresentation rasterPresentation = new RasterPresentation(layer, ref, dataImage);
        rasterPresentation.forGrid(renderingContext);
        return Stream.concat(Stream.of(rasterPresentation), outline(layer, dataImage.getGridGeometry()));
    } catch (NoSuchDataException | DisjointExtentException e) {
        LOGGER.log(Level.FINE, "Disjoint exception: " + e.getMessage(), e);
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "Portrayal exception: " + e.getMessage(), e);
    }
    return Stream.empty();
}
Also used : RasterSymbolizer(org.opengis.style.RasterSymbolizer) CachedRasterSymbolizer(org.geotoolkit.display2d.style.CachedRasterSymbolizer) DisjointExtentException(org.apache.sis.coverage.grid.DisjointExtentException) GridCoverage2D(org.apache.sis.coverage.grid.GridCoverage2D) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) RasterPresentation(org.geotoolkit.display2d.presentation.RasterPresentation) NoSuchDataException(org.apache.sis.storage.NoSuchDataException) PortrayalException(org.geotoolkit.display.PortrayalException) NoSuchDataException(org.apache.sis.storage.NoSuchDataException) FactoryException(org.opengis.util.FactoryException) CannotEvaluateException(org.opengis.coverage.CannotEvaluateException) IOException(java.io.IOException) DisjointExtentException(org.apache.sis.coverage.grid.DisjointExtentException) TransformException(org.opengis.referencing.operation.TransformException) ProcessException(org.geotoolkit.process.ProcessException) DataStoreException(org.apache.sis.storage.DataStoreException)

Example 4 with RasterSymbolizer

use of org.opengis.style.RasterSymbolizer in project geotoolkit by Geomatys.

the class RasterSymbolizerRenderer method presentations.

@Override
public Stream<Presentation> presentations(MapLayer layer, Resource rs) {
    if (rs instanceof BandedCoverageResource) {
        BandedCoverageResource bcr = (BandedCoverageResource) rs;
        try {
            GridCoverage coverage = BandedCoverageResource.sample(bcr, renderingContext.getGridGeometry2D());
            rs = new InMemoryGridCoverageResource(rs.getIdentifier().orElse(null), coverage);
        } catch (DataStoreException ex) {
            ExceptionPresentation ep = new ExceptionPresentation(ex);
            ep.setLayer(layer);
            ep.setResource(rs);
            return Stream.of(ep);
        }
    }
    if (rs instanceof GridCoverageResource) {
        GridCoverageResource ref = (GridCoverageResource) rs;
        try {
            final RasterSymbolizer sourceSymbol = symbol.getSource();
            final int[] channelSelection = channelSelection(sourceSymbol, ref);
            final GridCoverage dataCoverage = getObjectiveCoverage(ref, renderingContext.getGridGeometry(), false, channelSelection);
            if (dataCoverage == null) {
                return Stream.empty();
            }
            final GridCoverage2D dataImage = applyStyle(ref, dataCoverage, sourceSymbol);
            final RasterPresentation rasterPresentation = new RasterPresentation(layer, layer.getData(), dataImage);
            rasterPresentation.forGrid(renderingContext);
            return Stream.concat(Stream.of(rasterPresentation), outline(layer, dataImage.getGridGeometry()));
        } catch (NoSuchDataException | DisjointExtentException e) {
            LOGGER.log(Level.FINE, "Disjoint exception: " + e.getMessage(), e);
        } catch (Exception e) {
            ExceptionPresentation ep = new ExceptionPresentation(e);
            ep.setLayer(layer);
            ep.setResource(rs);
            return Stream.of(ep);
        }
    } else {
        return super.presentations(layer, rs);
    }
    return Stream.empty();
}
Also used : DisjointExtentException(org.apache.sis.coverage.grid.DisjointExtentException) DataStoreException(org.apache.sis.storage.DataStoreException) GridCoverage2D(org.apache.sis.coverage.grid.GridCoverage2D) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) BandedCoverageResource(org.geotoolkit.storage.coverage.BandedCoverageResource) RasterPresentation(org.geotoolkit.display2d.presentation.RasterPresentation) NoSuchDataException(org.apache.sis.storage.NoSuchDataException) PortrayalException(org.geotoolkit.display.PortrayalException) NoSuchDataException(org.apache.sis.storage.NoSuchDataException) FactoryException(org.opengis.util.FactoryException) CannotEvaluateException(org.opengis.coverage.CannotEvaluateException) IOException(java.io.IOException) DisjointExtentException(org.apache.sis.coverage.grid.DisjointExtentException) TransformException(org.opengis.referencing.operation.TransformException) ProcessException(org.geotoolkit.process.ProcessException) DataStoreException(org.apache.sis.storage.DataStoreException) RasterSymbolizer(org.opengis.style.RasterSymbolizer) CachedRasterSymbolizer(org.geotoolkit.display2d.style.CachedRasterSymbolizer) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) ExceptionPresentation(org.apache.sis.internal.map.ExceptionPresentation) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource)

Example 5 with RasterSymbolizer

use of org.opengis.style.RasterSymbolizer in project geotoolkit by Geomatys.

the class RasterSymbolizerTest method coverage_whose_grid_origin_is_lower_left_should_be_flipped.

/**
 * Source coverage will be a matrix <em>with origin lower-left</em>:
 * <table>
 *     <tr><td>4</td><td>3</td></tr>
 *     <tr><td>1</td><td>2</td></tr>
 * </table>
 * @throws PortrayalException
 */
@Test
public void coverage_whose_grid_origin_is_lower_left_should_be_flipped() throws PortrayalException {
    final BufferedImage image = new BufferedImage(2, 2, BufferedImage.TYPE_BYTE_GRAY);
    image.getRaster().setSample(0, 0, 0, 1);
    image.getRaster().setSample(1, 0, 0, 2);
    image.getRaster().setSample(1, 1, 0, 3);
    image.getRaster().setSample(0, 1, 0, 4);
    final GridGeometry geom = new GridGeometry(new GridExtent(2, 2), PixelInCell.CELL_CENTER, new AffineTransform2D(1, 0, 0, 1, 10, 10), CommonCRS.defaultGeographic());
    final GridCoverage baseData = new GridCoverage2D(geom, null, image);
    MapLayer layer = MapBuilder.createLayer(new InMemoryGridCoverageResource(baseData));
    final MapLayers ctx = MapBuilder.createContext();
    ctx.getComponents().add(layer);
    BufferedImage rendering = DefaultPortrayalService.portray(new CanvasDef(new Dimension(2, 2), geom.getEnvelope()), new SceneDef(ctx, new Hints(GO2Hints.KEY_INTERPOLATION, InterpolationCase.NEIGHBOR, RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR)));
    // As display is oriented upper-left, output should be flipped on y axis. Also, the renderer will stretch values
    // along 256 colors, so we have to adapt comparison.
    final int[] pixels = rendering.getRaster().getPixels(0, 0, 2, 2, (int[]) null);
    final int[] expected = { 255, 255, 255, 255, 165, 165, 165, 255, 0, 0, 0, 255, 88, 88, 88, 255 };
    assertArrayEquals(expected, pixels);
    final ColorMap colorMap = SF.colorMap(SF.interpolateFunction(null, Arrays.asList(SF.interpolationPoint(1, FF.literal(Color.RED)), SF.interpolationPoint(2, FF.literal(Color.GREEN)), SF.interpolationPoint(3, FF.literal(Color.BLUE)), SF.interpolationPoint(4, FF.literal(Color.WHITE))), null, null, FF.literal(Color.BLACK)));
    final RasterSymbolizer symbol = SF.rasterSymbolizer(null, null, null, null, colorMap, null, null, null);
    ctx.getComponents().set(0, MapBuilder.createCoverageLayer(baseData, SF.style(symbol), "test"));
    rendering = DefaultPortrayalService.portray(new CanvasDef(new Dimension(2, 2), geom.getEnvelope()), new SceneDef(ctx, new Hints(GO2Hints.KEY_INTERPOLATION, InterpolationCase.NEIGHBOR, RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR)));
    assertEquals(Color.WHITE.getRGB(), rendering.getRGB(0, 0));
    assertEquals(Color.BLUE.getRGB(), rendering.getRGB(1, 0));
    assertEquals(Color.RED.getRGB(), rendering.getRGB(0, 1));
    assertEquals(Color.GREEN.getRGB(), rendering.getRGB(1, 1));
}
Also used : GridGeometry(org.apache.sis.coverage.grid.GridGeometry) GridExtent(org.apache.sis.coverage.grid.GridExtent) GridCoverage2D(org.apache.sis.coverage.grid.GridCoverage2D) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) Hints(org.geotoolkit.factory.Hints) RenderingHints(java.awt.RenderingHints) GO2Hints(org.geotoolkit.display2d.GO2Hints) ColorMap(org.opengis.style.ColorMap) MapLayer(org.apache.sis.portrayal.MapLayer) Dimension(java.awt.Dimension) SampleDimension(org.apache.sis.coverage.SampleDimension) BufferedImage(java.awt.image.BufferedImage) RasterSymbolizer(org.opengis.style.RasterSymbolizer) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) SceneDef(org.geotoolkit.display2d.service.SceneDef) CanvasDef(org.geotoolkit.display2d.service.CanvasDef) AffineTransform2D(org.apache.sis.internal.referencing.j2d.AffineTransform2D) MapLayers(org.apache.sis.portrayal.MapLayers) Test(org.junit.Test)

Aggregations

RasterSymbolizer (org.opengis.style.RasterSymbolizer)22 PolygonSymbolizer (org.opengis.style.PolygonSymbolizer)15 LineSymbolizer (org.opengis.style.LineSymbolizer)14 PointSymbolizer (org.opengis.style.PointSymbolizer)14 TextSymbolizer (org.opengis.style.TextSymbolizer)14 Symbolizer (org.opengis.style.Symbolizer)13 Expression (org.opengis.filter.Expression)10 ColorMap (org.opengis.style.ColorMap)10 ChannelSelection (org.opengis.style.ChannelSelection)9 ContrastEnhancement (org.opengis.style.ContrastEnhancement)9 ShadedRelief (org.opengis.style.ShadedRelief)9 Unit (javax.measure.Unit)7 Description (org.opengis.style.Description)7 OverlapBehavior (org.opengis.style.OverlapBehavior)7 GridCoverage (org.apache.sis.coverage.grid.GridCoverage)4 SimpleInternationalString (org.apache.sis.util.SimpleInternationalString)4 ExtensionSymbolizer (org.opengis.style.ExtensionSymbolizer)4 IOException (java.io.IOException)3 GridCoverage2D (org.apache.sis.coverage.grid.GridCoverage2D)3 MapLayer (org.apache.sis.portrayal.MapLayer)3