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