/** * Renders features based on the map layers and their styles as specified in the map context * using <code>setContext</code>. * * <p>This version of the method assumes that the area of the visible part of the map and the * size of the output area are known. The transform between the two is calculated internally. * * @param graphics The graphics object to draw to. * @param paintArea The size of the output area in output units (eg: pixels). * @param mapArea the map's visible area (viewport) in map coordinates. */ public void paint(Graphics2D graphics, Rectangle paintArea, ReferencedEnvelope mapArea) { if (mapArea == null || paintArea == null) { LOGGER.info("renderer passed null arguments"); return; } // Other arguments get checked later paint( graphics, paintArea, mapArea, RendererUtilities.worldToScreenTransform(mapArea, paintArea)); }
/** * Renders features based on the map layers and their styles as specified in the map context * using <code>setContext</code>. * * <p>This version of the method assumes that the area of the visible part of the map and the * size of the output area are known. The transform between the two is calculated internally. * * @param graphics The graphics object to draw to. * @param paintArea The size of the output area in output units (eg: pixels). * @param mapArea the map's visible area (viewport) in map coordinates. * @deprecated Use paint(Graphics2D graphics, Rectangle paintArea, ReferencedEnvelope mapArea) * or paint(Graphics2D graphics, Rectangle paintArea, ReferencedEnvelope mapArea, * AffineTransform worldToScreen) instead. */ public void paint(Graphics2D graphics, Rectangle paintArea, Envelope mapArea) { if (mapArea == null || paintArea == null) { LOGGER.info("renderer passed null arguments"); return; } // Other arguments get checked later paint( graphics, paintArea, mapArea, RendererUtilities.worldToScreenTransform(mapArea, paintArea)); }
/** * Renders features based on the map layers and their styles as specified in the map context * using <code>setContext</code>. * * <p>This version of the method assumes that paint area, envelope and worldToScreen transform * are already computed. Use this method to avoid recomputation. <b>Note however that no check * is performed that they are really in sync!<b/> * * @param graphics The graphics object to draw to. * @param paintArea The size of the output area in output units (eg: pixels). * @param mapArea the map's visible area (viewport) in map coordinates. * @param worldToScreen A transform which converts World coordinates to Screen coordinates. * @deprecated Use paint(Graphics2D graphics, Rectangle paintArea, ReferencedEnvelope mapArea) * or paint(Graphics2D graphics, Rectangle paintArea, ReferencedEnvelope mapArea, * AffineTransform worldToScreen) instead. */ public void paint( Graphics2D graphics, Rectangle paintArea, Envelope mapArea, AffineTransform worldToScreen) { paint( graphics, paintArea, new ReferencedEnvelope(mapArea, mapContent.getCoordinateReferenceSystem()), worldToScreen); }
try { mapArea = RendererUtilities.createMapEnvelope(paintArea, worldToScreen); paint(graphics, paintArea, mapArea, worldToScreen); } catch (NoninvertibleTransformException e) { fireErrorEvent(e);
private void renderAndStop(MapContent content, ReferencedEnvelope bounds) { StreamingRenderer renderer = new StreamingRenderer(); renderer.setMapContent(content); // stop rendering after 10 features renderer.addRenderListener( new RenderListener() { int count = 0; @Override public void featureRenderer(SimpleFeature feature) { count++; if (count > 10) { renderer.stopRendering(); } } @Override public void errorOccurred(Exception e) {} }); Rectangle area = new Rectangle(0, 0, 2000, 2000); BufferedImage img = new BufferedImage(area.width, area.height, BufferedImage.TYPE_INT_ARGB); renderer.paint((Graphics2D) img.getGraphics(), area, bounds); }
protected BufferedImage renderNonStraightLines( SimpleFeatureSource featureSource, Style style, int width, int height, ReferencedEnvelope bounds) { MapContent mapContent = new MapContent(); mapContent.addLayer(new FeatureLayer(featureSource, style)); // instantiate and initiate the render StreamingRenderer renderer = new StreamingRenderer(); renderer.setMapContent(mapContent); renderer.setJava2DHints(new RenderingHints(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON)); // create the output image and add a dark background for testing the halo BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR); Graphics2D graphics = image.createGraphics(); graphics.setColor(Color.LIGHT_GRAY); graphics.fillRect(0, 0, image.getWidth(), image.getHeight()); // render the lines with the chosen style renderer.paint(graphics, new Rectangle(0, 0, image.getWidth(), image.getHeight()), bounds); mapContent.dispose(); return image; } }
private void runSingleLayerTest(String styleName, int threshold) throws Exception { Style style = RendererBaseTest.loadStyle(this, styleName); MapContent mc = new MapContent(); mc.addLayer(new FeatureLayer(fs, style)); StreamingRenderer renderer = new StreamingRenderer(); renderer.setMapContent(mc); renderer.setJava2DHints(new RenderingHints(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON)); // prepare an opaque background BufferedImage image = new BufferedImage(256, 256, BufferedImage.TYPE_3BYTE_BGR); Graphics2D graphics = image.createGraphics(); graphics.setColor(Color.lightGray); graphics.fillRect(0, 0, image.getWidth(), image.getHeight()); renderer.paint(graphics, new Rectangle(0, 0, image.getWidth(), image.getHeight()), bounds); mc.dispose(); File reference = new File( "./src/test/resources/org/geotools/renderer/lite/test-data/" + styleName + ".png"); ImageAssert.assertEquals(reference, image, threshold); } }
@Test public void testCrossFillZoomedOut() throws Exception { String styleName = "fillCrossUom.sld"; Style style = RendererBaseTest.loadStyle(this, styleName); MapContent mc = new MapContent(); mc.addLayer(new FeatureLayer(fs, style)); StreamingRenderer renderer = new StreamingRenderer(); renderer.setMapContent(mc); renderer.setJava2DHints(new RenderingHints(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON)); // this used to blow up while building the repeatable tile used to perform the fill BufferedImage bi = new BufferedImage(10, 10, BufferedImage.TYPE_4BYTE_ABGR); Graphics2D graphics = bi.createGraphics(); renderer.paint(graphics, new Rectangle(0, 0, 10, 10), bounds); graphics.dispose(); mc.dispose(); }
public void testAutoWrapLocalTransform() throws Exception { Style style = RendererBaseTest.loadStyle(this, "textWrapEnabled.sld"); MapContent mc = new MapContent(); mc.getViewport().setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84); mc.addLayer(new FeatureLayer(fs, style)); StreamingRenderer renderer = new StreamingRenderer(); renderer.setJava2DHints(new RenderingHints(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON)); renderer.setMapContent(mc); int SIZE = 300; final BufferedImage image = new BufferedImage(SIZE, SIZE, BufferedImage.TYPE_INT_ARGB); Graphics2D g = (Graphics2D) image.getGraphics(); g.setColor(Color.white); g.fillRect(0, 0, SIZE, SIZE); g.setTransform( new AffineTransform( 1.1, Math.sin(Math.toRadians(15)), -Math.sin(Math.toRadians(15)), 1.1, 15, 20)); renderer.paint(g, new Rectangle(SIZE, SIZE), bounds); mc.dispose(); renderer.getMapContent().dispose(); String refPath = "./src/test/resources/org/geotools/renderer/lite/test-data/textWrapEnabledLocalTransform.png"; ImageAssert.assertEquals(new File(refPath), image, 3000); }
15, 20)); renderer.paint(g, new Rectangle(SIZE, SIZE), bounds); mc.dispose(); renderer.getMapContent().dispose();
@Test public void testCrossFillZoomedOut() throws Exception { String styleName = "fillCrossUom.sld"; Style style = RendererBaseTest.loadStyle(this, styleName); MapContent mc = new MapContent(); mc.addLayer(new FeatureLayer(fs, style)); StreamingRenderer renderer = new StreamingRenderer(); renderer.setMapContent(mc); renderer.setJava2DHints(new RenderingHints(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON)); // this used to blow up while building the repeatable tile used to perform the fill BufferedImage bi = new BufferedImage(10, 10, BufferedImage.TYPE_4BYTE_ABGR); Graphics2D graphics = bi.createGraphics(); renderer.paint(graphics, new Rectangle(0, 0, 10, 10), bounds); mc.dispose(); graphics.dispose(); mc.dispose(); }
@Test public void test() throws IOException, URISyntaxException, MismatchedDimensionException, NoSuchAuthorityCodeException, FactoryException { StreamingRenderer renderer = new StreamingRenderer(); MapContent map = new MapContent(); URL raster = getClass().getResource(rasterBase + ".png"); GridCoverage2D gc = readGeoReferencedImageFile(new File(raster.toURI())); map.addLayer(loadGeoReferencedImageFile(gc, "test")); renderer.setMapContent(map); BufferedImage image = new BufferedImage(400, 300, BufferedImage.TYPE_INT_ARGB); Envelope env = new Envelope(1880352, 5825436, 1884352, 5828436); ReferencedEnvelope refenv = new ReferencedEnvelope(env, gc.getCoordinateReferenceSystem()); AtomicReference<Exception> error = new AtomicReference<>(); renderer.addRenderListener( new RenderListener() { @Override public void featureRenderer(SimpleFeature feature) {} @Override public void errorOccurred(Exception e) { error.set(e); } }); renderer.paint(image.createGraphics(), new Rectangle(400, 300), refenv); map.dispose(); assertNull(error.get()); }
renderer.paint(destGraphics, SCREEN, WORLD); mapContent.dispose();
private static BufferedImage renderImage( SimpleFeatureSource featureSource, int width, int height, Rectangle2D mapArea, Style style, Map renderingHints) { BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = (Graphics2D) image.getGraphics(); g.setColor(Color.WHITE); g.fillRect(0, 0, width, height); MapContent mapContent = new MapContent(); MapViewport viewport = mapContent.getViewport(); viewport.setBounds(new ReferencedEnvelope(mapArea, DefaultGeographicCRS.WGS84)); viewport.setScreenArea(new Rectangle(width, height)); mapContent.addLayer(new FeatureLayer(featureSource, style)); StreamingRenderer renderer = new StreamingRenderer(); renderer.setRendererHints(renderingHints); renderer.setMapContent(mapContent); renderer.paint(g, viewport.getScreenArea(), viewport.getBounds()); return image; }
private void renderEmptyGeometry(SimpleFeature f, Style style) { SimpleFeatureCollection fc = DataUtilities.collection(f); MapContext mc = new DefaultMapContext(); mc.addLayer(fc, style); StreamingRenderer sr = new StreamingRenderer(); sr.setContext(mc); BufferedImage bi = new BufferedImage(640, 480, BufferedImage.TYPE_4BYTE_ABGR); sr.addRenderListener( new RenderListener() { public void featureRenderer(SimpleFeature feature) {} public void errorOccurred(Exception e) { java.util.logging.Logger.getGlobal() .log(java.util.logging.Level.INFO, "", e); fail( "Got an exception during rendering, this should not happen, " + "not even with emtpy geometries"); } }); sr.paint( (Graphics2D) bi.getGraphics(), new Rectangle(640, 480), new ReferencedEnvelope(new Envelope(0, 10, 0, 10), DefaultGeographicCRS.WGS84)); mc.dispose(); } }
g.setColor(Color.white); g.fillRect(0, 0, 400, 80); renderer.paint(g, new Rectangle(0, 0, 400, 80), bounds); mc.dispose();
new ReferencedEnvelope( -38207011.656556, -12735670.552185, 12735670.552186, 38207011.656556, crs); renderer.paint(g2d, new Rectangle(0, 0, 256, 256), envelope); g2d.dispose(); content.dispose();
private BufferedImage composeFts(GridCoverage2D first, GridCoverage2D second) { // build the map content MapContent mc = new MapContent(); StyleBuilder sb = new StyleBuilder(); Style baseStyle = sb.createStyle(sb.createRasterSymbolizer()); mc.addLayer(new GridCoverageLayer(first, baseStyle)); FeatureTypeStyle compositeFts = sb.createFeatureTypeStyle(sb.createRasterSymbolizer()); compositeFts.getOptions().put(FeatureTypeStyle.COMPOSITE, composite); Style compositeStyle = sb.createStyle(); compositeStyle.featureTypeStyles().add(compositeFts); mc.addLayer(new GridCoverageLayer(second, compositeStyle)); // prepare the graphics for the streaming renderer and paint RenderedImage referenceImage = first.getRenderedImage(); BufferedImage blended = new BufferedImage( referenceImage.getWidth(), referenceImage.getWidth(), BufferedImage.TYPE_4BYTE_ABGR); Graphics2D graphics = blended.createGraphics(); StreamingRenderer sr = new StreamingRenderer(); sr.setMapContent(mc); sr.paint( graphics, new Rectangle(0, 0, referenceImage.getWidth(), referenceImage.getHeight()), ReferencedEnvelope.reference(first.getEnvelope())); graphics.dispose(); mc.dispose(); return blended; }
/** * Tests what happens when the grid coverage is associated with a broken style with no * symbolizers inside. It should just render nothing, a NPE was reported instead in GEOT-2543. * * @throws Exception */ @Test public void paintWrongStyle() throws Exception { final GridCoverage2D gc = getGC(); final MapContext context = new DefaultMapContext(DefaultGeographicCRS.WGS84); // final Style style = new StyleBuilder().createStyle((Symbolizer) null); final Style style = RendererBaseTest.loadStyle(this, "empty.sld"); context.addLayer(gc, style); final StreamingRenderer renderer = new StreamingRenderer(); CountingRenderListener counter = new CountingRenderListener(); renderer.addRenderListener(counter); renderer.setContext(context); BufferedImage image = new BufferedImage(300, 300, BufferedImage.TYPE_4BYTE_ABGR); Graphics2D g2d = (Graphics2D) image.getGraphics(); renderer.paint(g2d, new Rectangle(0, 0, 300, 300), context.getLayerBounds()); g2d.dispose(); context.dispose(); // make sure no errors and no features assertEquals(0, counter.errors); assertEquals(0, counter.features); }
final StreamingRenderer sr = new StreamingRenderer(); sr.setContext(mapContext); sr.paint(image.createGraphics(), screen, worldToScreen); assertTrue("Pixel should be drawn at 0,0 ", image.getRGB(0, 0) != 0); assertTrue(