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;
}
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;
}
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();
}
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();
}
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));
}
Aggregations