Search in sources :

Example 6 with TransformedShape

use of org.geotoolkit.display.shape.TransformedShape in project geotoolkit by Geomatys.

the class CachedMark method getImage.

public BufferedImage getImage(final Object candidate, final Float size, final RenderingHints hints) {
    evaluate();
    final Expression wkn = styleElement.getWellKnownName();
    final ExternalMark external = styleElement.getExternalMark();
    int j2dSize = 16;
    float margin = 0;
    int maxWidth = 0;
    int center = 0;
    Shape candidateShape = getShape(candidate, hints);
    if (wkn != null || external != null) {
        j2dSize = (size != null) ? size.intValue() : 16;
        if (j2dSize < 0)
            j2dSize = 0;
        if (j2dSize > 1000)
            j2dSize = 1000;
        margin = cachedStroke.getMargin(candidate, 1);
        maxWidth = (int) (margin * 2 + 0.5f) + j2dSize;
        center = maxWidth / 2;
    }
    if (maxWidth < 1)
        maxWidth = 1;
    if (candidateShape != null) {
        BufferedImage buffer = new BufferedImage(maxWidth, maxWidth, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = (Graphics2D) buffer.getGraphics();
        if (hints != null)
            g2.setRenderingHints(hints);
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.translate(center, center);
        TransformedShape trs = new TransformedShape();
        trs.setOriginalShape(candidateShape);
        trs.scale(j2dSize, j2dSize);
        // trs.createTransformedShape(marker);
        Shape shp = trs;
        // test if we need to paint the fill
        if (cachedFill.isVisible(candidate)) {
            g2.setPaint(cachedFill.getJ2DPaint(candidate, 0, 0, 1, hints));
            g2.setComposite(cachedFill.getJ2DComposite(candidate));
            g2.fill(shp);
        }
        // test if we need to paint the stroke
        if (cachedStroke.isVisible(candidate)) {
            g2.setStroke(cachedStroke.getJ2DStroke(candidate, 1));
            g2.setPaint(cachedStroke.getJ2DPaint(candidate, 0, 0, 1, hints));
            g2.setComposite(cachedStroke.getJ2DComposite(candidate));
            g2.draw(shp);
        }
        g2.dispose();
        return buffer;
    } else if (external != null) {
        return createImage(external, j2dSize, hints);
    }
    return null;
}
Also used : Shape(java.awt.Shape) TransformedShape(org.geotoolkit.display.shape.TransformedShape) ExternalMark(org.opengis.style.ExternalMark) TransformedShape(org.geotoolkit.display.shape.TransformedShape) Expression(org.opengis.filter.Expression) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 7 with TransformedShape

use of org.geotoolkit.display.shape.TransformedShape in project geotoolkit by Geomatys.

the class PolygonSymbolizerRendererService method glyph.

/**
 * {@inheritDoc }
 */
@Override
public void glyph(final Graphics2D g, final Rectangle2D rectangle, final CachedPolygonSymbolizer symbol, final MapLayer layer) {
    final AffineTransform affine = new AffineTransform(rectangle.getWidth(), 0, 0, rectangle.getHeight(), rectangle.getX(), rectangle.getY());
    g.setClip(rectangle);
    final TransformedShape shape = new TransformedShape();
    shape.setOriginalShape(GO2Utilities.GLYPH_POLYGON);
    shape.setTransform(affine);
    final Fill fill = symbol.getSource().getFill();
    final Stroke stroke = symbol.getSource().getStroke();
    if (fill != null) {
        GO2Utilities.renderFill(shape, symbol.getSource().getFill(), g);
    }
    if (stroke != null) {
        GO2Utilities.renderStroke(shape, symbol.getSource().getStroke(), symbol.getSource().getUnitOfMeasure(), g);
    }
}
Also used : Fill(org.opengis.style.Fill) Stroke(org.opengis.style.Stroke) TransformedShape(org.geotoolkit.display.shape.TransformedShape) AffineTransform(java.awt.geom.AffineTransform)

Aggregations

TransformedShape (org.geotoolkit.display.shape.TransformedShape)7 Expression (org.opengis.filter.Expression)4 Graphics2D (java.awt.Graphics2D)3 Rectangle (java.awt.Rectangle)3 Shape (java.awt.Shape)3 BufferedImage (java.awt.image.BufferedImage)3 AffineTransform (java.awt.geom.AffineTransform)2 AlphaComposite (java.awt.AlphaComposite)1 Composite (java.awt.Composite)1 RenderingHints (java.awt.RenderingHints)1 PathIterator (java.awt.geom.PathIterator)1 Rectangle2D (java.awt.geom.Rectangle2D)1 ArrayList (java.util.ArrayList)1 GeneralEnvelope (org.apache.sis.geometry.GeneralEnvelope)1 NumberGraduation (org.geotoolkit.display.axis.NumberGraduation)1 TickIterator (org.geotoolkit.display.axis.TickIterator)1 ProjectedGeometry (org.geotoolkit.display2d.primitive.ProjectedGeometry)1 DefaultLabelLayer (org.geotoolkit.display2d.style.labeling.DefaultLabelLayer)1 DefaultLinearLabelDescriptor (org.geotoolkit.display2d.style.labeling.DefaultLinearLabelDescriptor)1 LabelLayer (org.geotoolkit.display2d.style.labeling.LabelLayer)1