Search in sources :

Example 1 with ColorMap

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

the class RasterSymbolizerRenderer method prepareCoverageToResampling.

/**
 * Analyse input coverage to know if we need to add an alpha channel. Alpha channel is required in photographic
 * coverage case, in order for the resample to deliver a ready to style image.
 *
 * @param source The coverage to analyse.
 * @param symbolizer contain color Map.
 * @return The same coverage as input if style do not require an ARGB data to properly render, or a new ARGB coverage
 * computed from source data.
 */
@Override
protected final GridCoverage prepareCoverageToResampling(final GridCoverage source, final CachedRasterSymbolizer symbolizer) {
    final ColorMap cMap = symbolizer.getSource().getColorMap();
    if (cMap != null && cMap.getFunction() != null) {
        // Coloration is handled externally
        return source;
    }
    final List<SampleDimension> sds = source.getSampleDimensions();
    if (sds == null || sds.size() != 3) {
        return source;
    }
    if (source != source.forConvertedValues(false)) {
        return source;
    }
    for (SampleDimension sd : sds) {
        if (sd.getTransferFunction().isPresent())
            return source;
    }
    // At this point, no geophysic information has been found. We will consider input coverage as a colorized image.
    return new ForcedAlpha(source);
}
Also used : ColorMap(org.opengis.style.ColorMap) SampleDimension(org.apache.sis.coverage.SampleDimension)

Example 2 with ColorMap

use of org.opengis.style.ColorMap 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)

Example 3 with ColorMap

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

the class Tester method createRasterSymbolizer.

private static RasterSymbolizer createRasterSymbolizer() {
    String name = "Raster symbolizer name";
    Description desc = STYLE_FACTORY.description("Raster symbolizer title", "Raster symbolizer description");
    Unit uom = Units.METRE;
    String geom = "geom";
    Expression opacity = FILTER_FACTORY.literal(0.5);
    ChannelSelection selection = STYLE_FACTORY.channelSelection(STYLE_FACTORY.selectedChannelType("chanel2", FILTER_FACTORY.literal(1)));
    OverlapBehavior overlap = OverlapBehavior.RANDOM;
    ColorMap colorMap = STYLE_FACTORY.colorMap();
    ContrastEnhancement enchance = STYLE_FACTORY.contrastEnhancement();
    ShadedRelief relief = STYLE_FACTORY.shadedRelief(FILTER_FACTORY.literal(3), true);
    Symbolizer outline = createLineSymbolizer();
    return STYLE_FACTORY.rasterSymbolizer(name, geom, desc, uom, opacity, selection, overlap, colorMap, enchance, relief, outline);
}
Also used : Description(org.opengis.style.Description) ContrastEnhancement(org.opengis.style.ContrastEnhancement) Expression(org.opengis.filter.Expression) ChannelSelection(org.opengis.style.ChannelSelection) ColorMap(org.opengis.style.ColorMap) SimpleInternationalString(org.apache.sis.util.SimpleInternationalString) Unit(javax.measure.Unit) ShadedRelief(org.opengis.style.ShadedRelief) PointSymbolizer(org.opengis.style.PointSymbolizer) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) LineSymbolizer(org.opengis.style.LineSymbolizer) RasterSymbolizer(org.opengis.style.RasterSymbolizer) TextSymbolizer(org.opengis.style.TextSymbolizer) Symbolizer(org.opengis.style.Symbolizer) OverlapBehavior(org.opengis.style.OverlapBehavior)

Example 4 with ColorMap

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

the class XMLUtilitiesTest method createRasterSymbolizer.

private static RasterSymbolizer createRasterSymbolizer() {
    String name = "Raster symbolizer name";
    Description desc = STYLE_FACTORY.description("Raster symbolizer title", "Raster symbolizer description");
    Unit uom = Units.METRE;
    String geom = "geom";
    Expression opacity = FILTER_FACTORY.literal(0.5);
    ChannelSelection selection = STYLE_FACTORY.channelSelection(STYLE_FACTORY.selectedChannelType("chanel2", FILTER_FACTORY.literal(1)));
    OverlapBehavior overlap = OverlapBehavior.RANDOM;
    ColorMap colorMap = STYLE_FACTORY.colorMap();
    ContrastEnhancement enchance = STYLE_FACTORY.contrastEnhancement();
    ShadedRelief relief = STYLE_FACTORY.shadedRelief(FILTER_FACTORY.literal(3), true);
    Symbolizer outline = createLineSymbolizer();
    return STYLE_FACTORY.rasterSymbolizer(name, geom, desc, uom, opacity, selection, overlap, colorMap, enchance, relief, outline);
}
Also used : Description(org.opengis.style.Description) ContrastEnhancement(org.opengis.style.ContrastEnhancement) Expression(org.opengis.filter.Expression) ChannelSelection(org.opengis.style.ChannelSelection) ColorMap(org.opengis.style.ColorMap) SimpleInternationalString(org.apache.sis.util.SimpleInternationalString) Unit(javax.measure.Unit) ShadedRelief(org.opengis.style.ShadedRelief) PointSymbolizer(org.opengis.style.PointSymbolizer) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) LineSymbolizer(org.opengis.style.LineSymbolizer) RasterSymbolizer(org.opengis.style.RasterSymbolizer) TextSymbolizer(org.opengis.style.TextSymbolizer) Symbolizer(org.opengis.style.Symbolizer) OverlapBehavior(org.opengis.style.OverlapBehavior)

Example 5 with ColorMap

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

the class Styles method colorCategorizeRaster.

public static MutableStyle colorCategorizeRaster() {
    final Map<Expression, Expression> values = new HashMap<>();
    values.put(StyleConstants.CATEGORIZE_LESS_INFINITY, SF.literal(new Color(46, 154, 88)));
    values.put(FF.literal(1003), SF.literal(new Color(46, 154, 88)));
    values.put(FF.literal(1800), SF.literal(new Color(251, 255, 128)));
    values.put(FF.literal(2800), SF.literal(new Color(224, 108, 31)));
    values.put(FF.literal(3500), SF.literal(new Color(200, 55, 55)));
    values.put(FF.literal(4397), SF.literal(new Color(215, 244, 244)));
    final Expression lookup = DEFAULT_CATEGORIZE_LOOKUP;
    final Literal fallback = DEFAULT_FALLBACK;
    final Expression function = SF.categorizeFunction(lookup, values, ThreshholdsBelongTo.SUCCEEDING, fallback);
    final ChannelSelection selection = null;
    final Expression opacity = LITERAL_ONE_FLOAT;
    final OverlapBehavior overlap = OverlapBehavior.LATEST_ON_TOP;
    final ColorMap colorMap = SF.colorMap(function);
    final ContrastEnhancement enchance = SF.contrastEnhancement(LITERAL_ONE_FLOAT, ContrastMethod.NONE);
    final ShadedRelief relief = SF.shadedRelief(LITERAL_ONE_FLOAT);
    final Symbolizer outline = null;
    final Unit uom = Units.POINT;
    final String geom = DEFAULT_GEOM;
    final String name = "raster symbol name";
    final Description desc = DEFAULT_DESCRIPTION;
    final RasterSymbolizer symbol = SF.rasterSymbolizer(name, geom, desc, uom, opacity, selection, overlap, colorMap, enchance, relief, outline);
    return SF.style(symbol);
}
Also used : Description(org.opengis.style.Description) HashMap(java.util.HashMap) ColorMap(org.opengis.style.ColorMap) Unit(javax.measure.Unit) ShadedRelief(org.opengis.style.ShadedRelief) PointSymbolizer(org.opengis.style.PointSymbolizer) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) LineSymbolizer(org.opengis.style.LineSymbolizer) RasterSymbolizer(org.opengis.style.RasterSymbolizer) TextSymbolizer(org.opengis.style.TextSymbolizer) Symbolizer(org.opengis.style.Symbolizer) RasterSymbolizer(org.opengis.style.RasterSymbolizer) ContrastEnhancement(org.opengis.style.ContrastEnhancement) Expression(org.opengis.filter.Expression) ChannelSelection(org.opengis.style.ChannelSelection) Literal(org.opengis.filter.Literal) OverlapBehavior(org.opengis.style.OverlapBehavior)

Aggregations

ColorMap (org.opengis.style.ColorMap)20 Expression (org.opengis.filter.Expression)15 RasterSymbolizer (org.opengis.style.RasterSymbolizer)10 InterpolationPoint (org.geotoolkit.style.function.InterpolationPoint)9 ChannelSelection (org.opengis.style.ChannelSelection)9 ContrastEnhancement (org.opengis.style.ContrastEnhancement)9 LineSymbolizer (org.opengis.style.LineSymbolizer)9 PointSymbolizer (org.opengis.style.PointSymbolizer)9 PolygonSymbolizer (org.opengis.style.PolygonSymbolizer)9 ShadedRelief (org.opengis.style.ShadedRelief)9 Symbolizer (org.opengis.style.Symbolizer)9 TextSymbolizer (org.opengis.style.TextSymbolizer)9 Color (java.awt.Color)7 Unit (javax.measure.Unit)7 Description (org.opengis.style.Description)7 OverlapBehavior (org.opengis.style.OverlapBehavior)7 Categorize (org.geotoolkit.style.function.Categorize)6 Test (org.junit.Test)5 DefaultInterpolationPoint (org.geotoolkit.style.function.DefaultInterpolationPoint)4 Interpolate (org.geotoolkit.style.function.Interpolate)4