Search in sources :

Example 1 with GridReaderLayer

use of org.geotools.map.GridReaderLayer in project sldeditor by robward-scisys.

the class RenderPanelImpl method renderRasterMap.

/**
 * Render raster map.
 *
 * @param imageSize the image size
 * @param style the style
 * @param dpi the dpi
 */
private void renderRasterMap(Rectangle imageSize, Style style, int dpi) {
    DataSourceInterface dataSource = DataSourceFactory.getDataSource();
    AbstractGridCoverage2DReader gridCoverage = dataSource.getGridCoverageReader();
    if (gridCoverage == null) {
        validSymbol = false;
    }
    GridReaderLayer rasterLayer = null;
    MapViewport viewport = null;
    List<Layer> layerList = new ArrayList<Layer>();
    if (style != null) {
        rasterLayer = new GridReaderLayer(gridCoverage, style);
        layerList.add(rasterLayer);
        viewport = new MapViewport(rasterLayer.getBounds());
    }
    boolean hasGeometry = true;
    MapContent map = new MapContent();
    map.addLayers(layerList);
    map.setViewport(viewport);
    try {
        Map<Object, Object> hints = new HashMap<Object, Object>();
        if (OVERRIDE_DPI) {
            hints.put(StreamingRenderer.DPI_KEY, dpi);
        }
        // This ensures all the labelling is cleared
        hints.put(StreamingRenderer.LABEL_CACHE_KEY, new LabelCacheImpl());
        renderer.setRendererHints(hints);
        renderer.setMapContent(map);
        BufferedImage image = new BufferedImage(imageSize.width, imageSize.height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D graphics = image.createGraphics();
        if (useAntiAlias) {
            graphics.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
        }
        try {
            if (!hasGeometry) {
                graphics.setColor(Color.BLACK);
                int y = imageSize.height / 2;
                Font font = new Font(Font.SERIF, Font.BOLD, 14);
                graphics.setFont(font);
                graphics.drawString(Localisation.getString(RenderPanelImpl.class, "RenderPanelImpl.error1"), 10, y - 14);
            } else {
                if (rasterLayer != null) {
                    ReferencedEnvelope bounds = rasterLayer.getBounds();
                    renderer.paint(graphics, imageSize, bounds);
                }
                this.bImage = image;
            }
        } finally {
            graphics.dispose();
        }
    } finally {
        map.dispose();
    }
}
Also used : MapContent(org.geotools.map.MapContent) HashMap(java.util.HashMap) AbstractGridCoverage2DReader(org.geotools.coverage.grid.io.AbstractGridCoverage2DReader) ArrayList(java.util.ArrayList) LabelCacheImpl(org.geotools.renderer.label.LabelCacheImpl) GridReaderLayer(org.geotools.map.GridReaderLayer) FeatureLayer(org.geotools.map.FeatureLayer) Layer(org.geotools.map.Layer) BufferedImage(java.awt.image.BufferedImage) RenderingHints(java.awt.RenderingHints) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D) DataSourceInterface(com.sldeditor.datasource.DataSourceInterface) GridReaderLayer(org.geotools.map.GridReaderLayer) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) MapViewport(org.geotools.map.MapViewport)

Example 2 with GridReaderLayer

use of org.geotools.map.GridReaderLayer in project sldeditor by robward-scisys.

the class MapRender method renderSymbol.

/**
 * Render symbol.
 *
 * @param mapContent the map content
 * @param styledLayer the styled layer
 * @param style the style
 */
private void renderSymbol(MapContent mapContent, StyledLayer styledLayer, Style style) {
    for (Layer layer : mapContent.layers()) {
        mapContent.removeLayer(layer);
    }
    switch(geometryType) {
        case RASTER:
            {
                GridReaderLayer gridLayer = new GridReaderLayer(gridCoverage, (org.geotools.styling.Style) style);
                mapContent.addLayer(gridLayer);
                mapContent.getViewport().setBounds(gridLayer.getBounds());
                if (gridCoverage != null) {
                    mapPane.setDisplayArea(gridCoverage.getOriginalEnvelope());
                }
            }
            break;
        case POINT:
        case LINE:
        case POLYGON:
            {
                FeatureSource<SimpleFeatureType, SimpleFeature> tmpFeatureList = null;
                if (styledLayer instanceof UserLayer) {
                    if (userLayerFeatureListMap != null) {
                        tmpFeatureList = userLayerFeatureListMap.get(styledLayer);
                    }
                } else {
                    tmpFeatureList = featureList;
                }
                if (tmpFeatureList != null) {
                    mapContent.addLayer(new FeatureLayer(tmpFeatureList, (org.geotools.styling.Style) style));
                    try {
                        mapPane.setDisplayArea(tmpFeatureList.getBounds());
                    } catch (IOException e) {
                        ConsoleManager.getInstance().exception(this, e);
                    }
                }
            }
            break;
        default:
            break;
    }
    wmsEnvVarValues.setMapBounds(mapBounds);
    EnvironmentVariableManager.getInstance().setWMSEnvVarValues(wmsEnvVarValues);
}
Also used : GridReaderLayer(org.geotools.map.GridReaderLayer) FeatureSource(org.geotools.data.FeatureSource) FeatureLayer(org.geotools.map.FeatureLayer) Style(org.opengis.style.Style) IOException(java.io.IOException) UserLayer(org.geotools.styling.UserLayer) GridReaderLayer(org.geotools.map.GridReaderLayer) FeatureLayer(org.geotools.map.FeatureLayer) Layer(org.geotools.map.Layer) UserLayer(org.geotools.styling.UserLayer) StyledLayer(org.geotools.styling.StyledLayer)

Example 3 with GridReaderLayer

use of org.geotools.map.GridReaderLayer 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

GridReaderLayer (org.geotools.map.GridReaderLayer)3 Graphics2D (java.awt.Graphics2D)2 RenderingHints (java.awt.RenderingHints)2 BufferedImage (java.awt.image.BufferedImage)2 HashMap (java.util.HashMap)2 FeatureLayer (org.geotools.map.FeatureLayer)2 Layer (org.geotools.map.Layer)2 MapContent (org.geotools.map.MapContent)2 DataSourceInterface (com.sldeditor.datasource.DataSourceInterface)1 Font (java.awt.Font)1 Rectangle (java.awt.Rectangle)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 AbstractGridCoverage2DReader (org.geotools.coverage.grid.io.AbstractGridCoverage2DReader)1 FeatureSource (org.geotools.data.FeatureSource)1 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)1 MapViewport (org.geotools.map.MapViewport)1 RenderListener (org.geotools.renderer.RenderListener)1 LabelCacheImpl (org.geotools.renderer.label.LabelCacheImpl)1