Search in sources :

Example 1 with ExternalGraphicType

use of org.geotoolkit.se.xml.v110.ExternalGraphicType in project geotoolkit by Geomatys.

the class SE110toGTTransformer method visit.

/**
 * Transform a SLD v1.1 graphic in GT graphic.
 */
public Graphic visit(final GraphicType graphic) {
    if (graphic == null)
        return null;
    final List<GraphicalSymbol> symbols = new ArrayList<GraphicalSymbol>();
    for (final Object obj : graphic.getExternalGraphicOrMark()) {
        if (obj instanceof MarkType) {
            symbols.add(visit((MarkType) obj));
        } else if (obj instanceof ExternalGraphicType) {
            symbols.add(visit((ExternalGraphicType) obj));
        }
    }
    final Expression opacity = visitExpression(graphic.getOpacity());
    final Expression size = visitExpression(graphic.getSize());
    final Expression rotation = visitExpression(graphic.getRotation());
    final AnchorPoint anchor = visit(graphic.getAnchorPoint());
    final Displacement disp = visit(graphic.getDisplacement());
    return styleFactory.graphic(symbols, opacity, size, rotation, anchor, disp);
}
Also used : AnchorPoint(org.opengis.style.AnchorPoint) Expression(org.opengis.filter.Expression) GraphicalSymbol(org.opengis.style.GraphicalSymbol) ExternalGraphicType(org.geotoolkit.se.xml.v110.ExternalGraphicType) ArrayList(java.util.ArrayList) MarkType(org.geotoolkit.se.xml.v110.MarkType) Displacement(org.opengis.style.Displacement)

Example 2 with ExternalGraphicType

use of org.geotoolkit.se.xml.v110.ExternalGraphicType in project geotoolkit by Geomatys.

the class SE110toGTTransformer method visit.

public ExternalGraphic visit(final ExternalGraphicType externalGraphicType) {
    if (externalGraphicType == null)
        return null;
    OnlineResource resource = null;
    // check online resource
    if (externalGraphicType.getOnlineResource() != null) {
        resource = visitOnlineResource(externalGraphicType.getOnlineResource());
    }
    Icon icon = null;
    // check inline content
    if (externalGraphicType.getInlineContent() != null) {
        final InlineContentType ict = externalGraphicType.getInlineContent();
        final List<Object> contents = ict.getContent();
        for (Object obj : contents) {
            if (obj instanceof String) {
                try {
                    final byte[] b64 = Base64.getDecoder().decode((String) obj);
                    final ByteArrayInputStream is = new ByteArrayInputStream(b64);
                    final BufferedImage image = ImageIO.read(is);
                    icon = new ImageIcon(image);
                } catch (IOException ex) {
                    Logger.getLogger("org.geotoolkit.sld.xml").log(Level.WARNING, null, ex);
                }
            }
        }
    }
    final String format = externalGraphicType.getFormat();
    // rebuild color replacements
    final Collection<ColorReplacement> replaces = new ArrayList<>();
    for (final ColorReplacementType crt : externalGraphicType.getColorReplacement()) {
        final RecodeType rt = crt.getRecode();
        if (rt != null) {
            for (final MapItemType mit : rt.getMapItem()) {
                final double d = mit.getData();
                final Expression val = visitExpression(mit.getValue());
            }
        }
        final RecolorType rc = crt.getRecolor();
        if (rc != null) {
            List<ColorItem> items = new ArrayList<ColorItem>();
            for (final ColorItemType mit : rc.getColorItem()) {
                final Literal data = (Literal) visitExpression(mit.getData());
                final Literal value = (Literal) visitExpression(mit.getValue());
                items.add(new ColorItem(data, value));
            }
            RecolorFunction recolor = new RecolorFunction(items, null);
            replaces.add(new DefaultColorReplacement(recolor));
        }
    }
    if (resource != null) {
        return styleFactory.externalGraphic(resource, format, replaces);
    } else if (icon != null) {
        return styleFactory.externalGraphic(icon, replaces);
    } else {
        return null;
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) RecolorType(org.geotoolkit.se.xml.vext.RecolorType) ArrayList(java.util.ArrayList) ColorItem(org.geotoolkit.style.function.ColorItem) DefaultColorReplacement(org.geotoolkit.style.DefaultColorReplacement) BufferedImage(java.awt.image.BufferedImage) MapItemType(org.geotoolkit.se.xml.v110.MapItemType) RecodeType(org.geotoolkit.se.xml.v110.RecodeType) Literal(org.opengis.filter.Literal) RecolorFunction(org.geotoolkit.style.function.RecolorFunction) ColorReplacementType(org.geotoolkit.se.xml.v110.ColorReplacementType) InlineContentType(org.geotoolkit.se.xml.v110.InlineContentType) DefaultColorReplacement(org.geotoolkit.style.DefaultColorReplacement) ColorReplacement(org.opengis.style.ColorReplacement) IOException(java.io.IOException) OnlineResource(org.opengis.metadata.citation.OnlineResource) ByteArrayInputStream(java.io.ByteArrayInputStream) Expression(org.opengis.filter.Expression) ColorItemType(org.geotoolkit.se.xml.vext.ColorItemType) ImageIcon(javax.swing.ImageIcon) Icon(javax.swing.Icon)

Example 3 with ExternalGraphicType

use of org.geotoolkit.se.xml.v110.ExternalGraphicType in project geotoolkit by Geomatys.

the class GTtoSE110Transformer method visit.

@Override
public ExternalGraphicType visit(final ExternalGraphic externalGraphic, final Object data) {
    final ExternalGraphicType egt = se_factory.createExternalGraphicType();
    egt.setFormat(externalGraphic.getFormat());
    if (externalGraphic.getInlineContent() != null) {
        final Icon icon = externalGraphic.getInlineContent();
        final InlineContentType ict = new InlineContentType();
        ict.setEncoding("base64");
        Image image;
        if (icon instanceof ImageIcon) {
            image = ((ImageIcon) icon).getImage();
        } else {
            image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
            icon.paintIcon(null, image.getGraphics(), 0, 0);
        }
        if (!(image instanceof BufferedImage)) {
            final BufferedImage bi = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
            bi.createGraphics().drawImage(image, new AffineTransform(), null);
            image = bi;
        }
        try {
            final ByteArrayOutputStream out = new ByteArrayOutputStream();
            ImageIO.write((RenderedImage) image, "PNG", out);
            final String chars = Base64.getEncoder().encodeToString(out.toByteArray());
            ict.getContent().add(chars);
            egt.setInlineContent(ict);
        } catch (IOException ex) {
            Logger.getLogger("org.geotoolkit.sld.xml").log(Level.WARNING, null, ex);
        }
    }
    if (externalGraphic.getOnlineResource() != null) {
        egt.setOnlineResource(visit(externalGraphic.getOnlineResource(), null));
    }
    for (final ColorReplacement cr : externalGraphic.getColorReplacements()) {
        egt.getColorReplacement().add(visit(cr, data));
    }
    return egt;
}
Also used : ImageIcon(javax.swing.ImageIcon) ExternalGraphicType(org.geotoolkit.se.xml.v110.ExternalGraphicType) AffineTransform(java.awt.geom.AffineTransform) ColorReplacement(org.opengis.style.ColorReplacement) ImageIcon(javax.swing.ImageIcon) Icon(javax.swing.Icon) InlineContentType(org.geotoolkit.se.xml.v110.InlineContentType) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) RenderedImage(java.awt.image.RenderedImage) BufferedImage(java.awt.image.BufferedImage)

Aggregations

BufferedImage (java.awt.image.BufferedImage)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Icon (javax.swing.Icon)2 ImageIcon (javax.swing.ImageIcon)2 ExternalGraphicType (org.geotoolkit.se.xml.v110.ExternalGraphicType)2 InlineContentType (org.geotoolkit.se.xml.v110.InlineContentType)2 Expression (org.opengis.filter.Expression)2 ColorReplacement (org.opengis.style.ColorReplacement)2 Image (java.awt.Image)1 AffineTransform (java.awt.geom.AffineTransform)1 RenderedImage (java.awt.image.RenderedImage)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ColorReplacementType (org.geotoolkit.se.xml.v110.ColorReplacementType)1 MapItemType (org.geotoolkit.se.xml.v110.MapItemType)1 MarkType (org.geotoolkit.se.xml.v110.MarkType)1 RecodeType (org.geotoolkit.se.xml.v110.RecodeType)1 ColorItemType (org.geotoolkit.se.xml.vext.ColorItemType)1 RecolorType (org.geotoolkit.se.xml.vext.RecolorType)1