Search in sources :

Example 1 with RenderListener

use of org.geotools.renderer.RenderListener in project sldeditor by robward-scisys.

the class RendererErrorsTest method testRendererErrors.

/**
 * Test method for {@link com.sldeditor.render.RendererErrors#RendererErrors(boolean)}.
 */
@Test
public void testRendererErrors() {
    RenderListener instance1 = RendererErrors.getInstance();
    RenderListener instance2 = RendererErrors.getInstance();
    String exceptionMessage1 = "test exception";
    Exception e = new FileNotFoundException(exceptionMessage1);
    instance1.errorOccurred(null);
    instance1.errorOccurred(e);
    instance2.errorOccurred(e);
    instance1.featureRenderer(null);
    instance2.featureRenderer(null);
}
Also used : FileNotFoundException(java.io.FileNotFoundException) RenderListener(org.geotools.renderer.RenderListener) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.Test)

Example 2 with RenderListener

use of org.geotools.renderer.RenderListener in project polymap4-core by Polymap4.

the class FeatureRenderProcessor2 method getMapRequest.

@Override
public void getMapRequest(GetMapRequest request, ProcessorContext context) throws Exception {
    long start = System.currentTimeMillis();
    // result
    BufferedImage result = new BufferedImage(request.getWidth(), request.getHeight(), TYPE_4BYTE_ABGR);
    result.setAccelerationPriority(1);
    final Graphics2D g = result.createGraphics();
    // log.info( "IMAGE: accelerated=" + result.getCapabilities( g.getDeviceConfiguration() ).isAccelerated() );
    MapContent mapContent = new MapContent();
    try {
        // MapContent
        mapContent.getViewport().setCoordinateReferenceSystem(request.getBoundingBox().getCoordinateReferenceSystem());
        mapContent.addLayer(new FeatureLayer(fs.get(), style.get()));
        StreamingRenderer renderer = new NoThreadStreamingRenderer();
        // error handler
        renderer.addRenderListener(new RenderListener() {

            @Override
            public void featureRenderer(SimpleFeature feature) {
            }

            @Override
            public void errorOccurred(Exception e) {
                if (e.getMessage() == null || e.getMessage().contains("Error transforming bbox") || e.getMessage().contains("too close to a pole")) {
                    log.warn("Renderer: " + e.getMessage());
                } else {
                    log.error("Renderer error: ", e);
                    drawErrorMsg(g, "Unable to render.", e);
                }
            }
        });
        // rendering hints
        RenderingHints hints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        hints.add(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
        hints.add(new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON));
        hints.add(new RenderingHints(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON));
        // hints.add( new RenderingHints(
        // RenderingHints.KEY_TEXT_ANTIALIASING,
        // RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB ) );
        // geoserver compatibility to support *env* in SLD functions
        double scale = RendererUtilities.calculateOGCScale(request.getBoundingBox(), request.getWidth(), Collections.EMPTY_MAP);
        EnvFunction.setLocalValue("wms_scale_denominator", scale);
        renderer.setJava2DHints(hints);
        g.setRenderingHints(hints);
        // render params
        Map rendererParams = new HashMap();
        rendererParams.put("optimizedDataLoadingEnabled", Boolean.TRUE);
        renderer.setRendererHints(rendererParams);
        renderer.setMapContent(mapContent);
        Rectangle paintArea = new Rectangle(request.getWidth(), request.getHeight());
        renderer.paint(g, paintArea, request.getBoundingBox());
    } catch (Throwable e) {
        log.error("Renderer error: ", e);
        drawErrorMsg(g, "Unable to render.", e);
    } finally {
        mapContent.dispose();
        EnvFunction.clearLocalValues();
        if (g != null) {
            g.dispose();
        }
    }
    log.debug("   ...done: (" + (System.currentTimeMillis() - start) + "ms).");
    context.sendResponse(new ImageResponse(result));
}
Also used : MapContent(org.geotools.map.MapContent) HashMap(java.util.HashMap) Rectangle(java.awt.Rectangle) BufferedImage(java.awt.image.BufferedImage) SimpleFeature(org.opengis.feature.simple.SimpleFeature) IOException(java.io.IOException) RenderingHints(java.awt.RenderingHints) Graphics2D(java.awt.Graphics2D) NoThreadStreamingRenderer(org.geotools.renderer.lite.NoThreadStreamingRenderer) StreamingRenderer(org.geotools.renderer.lite.StreamingRenderer) FeatureLayer(org.geotools.map.FeatureLayer) NoThreadStreamingRenderer(org.geotools.renderer.lite.NoThreadStreamingRenderer) ImageResponse(org.polymap.core.data.image.ImageResponse) RenderListener(org.geotools.renderer.RenderListener) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with RenderListener

use of org.geotools.renderer.RenderListener in project polymap4-core by Polymap4.

the class RasterRenderProcessor method getMapRequest.

@Override
public void getMapRequest(GetMapRequest request, ProcessorContext context) throws Exception {
    // result
    BufferedImage result = new BufferedImage(request.getWidth(), request.getHeight(), TYPE_4BYTE_ABGR);
    final Graphics2D g = result.createGraphics();
    MapContent mapContent = new MapContent();
    try {
        mapContent.getViewport().setCoordinateReferenceSystem(request.getBoundingBox().getCoordinateReferenceSystem());
        mapContent.addLayer(new GridReaderLayer(reader, style.get()));
        // renderer
        StreamingRenderer renderer = new StreamingRenderer();
        // error handler
        renderer.addRenderListener(new RenderListener() {

            public void featureRenderer(SimpleFeature feature) {
            }

            public void errorOccurred(Exception e) {
                log.error("Renderer error: ", e);
                drawErrorMsg(g, "Fehler bei der Darstellung.", e);
            }
        });
        // rendering hints
        RenderingHints hints = new RenderingHints(KEY_RENDERING, VALUE_RENDER_QUALITY);
        hints.add(new RenderingHints(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON));
        hints.add(new RenderingHints(KEY_TEXT_ANTIALIASING, VALUE_TEXT_ANTIALIAS_ON));
        renderer.setJava2DHints(hints);
        // render params
        Map rendererParams = new HashMap();
        rendererParams.put("optimizedDataLoadingEnabled", Boolean.TRUE);
        renderer.setRendererHints(rendererParams);
        renderer.setMapContent(mapContent);
        Rectangle paintArea = new Rectangle(request.getWidth(), request.getHeight());
        renderer.paint(g, paintArea, request.getBoundingBox());
    } catch (Throwable e) {
        log.error("Renderer error: ", e);
        drawErrorMsg(g, null, e);
    } finally {
        mapContent.dispose();
        EnvFunction.clearLocalValues();
        if (g != null) {
            g.dispose();
        }
    }
    context.sendResponse(new ImageResponse(result));
}
Also used : MapContent(org.geotools.map.MapContent) HashMap(java.util.HashMap) Rectangle(java.awt.Rectangle) BufferedImage(java.awt.image.BufferedImage) SimpleFeature(org.opengis.feature.simple.SimpleFeature) RenderingHints(java.awt.RenderingHints) Graphics2D(java.awt.Graphics2D) StreamingRenderer(org.geotools.renderer.lite.StreamingRenderer) GridReaderLayer(org.geotools.map.GridReaderLayer) ImageResponse(org.polymap.core.data.image.ImageResponse) RenderListener(org.geotools.renderer.RenderListener) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

RenderListener (org.geotools.renderer.RenderListener)3 Graphics2D (java.awt.Graphics2D)2 Rectangle (java.awt.Rectangle)2 RenderingHints (java.awt.RenderingHints)2 BufferedImage (java.awt.image.BufferedImage)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 MapContent (org.geotools.map.MapContent)2 StreamingRenderer (org.geotools.renderer.lite.StreamingRenderer)2 SimpleFeature (org.opengis.feature.simple.SimpleFeature)2 ImageResponse (org.polymap.core.data.image.ImageResponse)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 FeatureLayer (org.geotools.map.FeatureLayer)1 GridReaderLayer (org.geotools.map.GridReaderLayer)1 NoThreadStreamingRenderer (org.geotools.renderer.lite.NoThreadStreamingRenderer)1 Test (org.junit.Test)1