public static BufferedImage renderImage( GTRenderer renderer, ReferencedEnvelope bounds, RenderListener listener) { int w = 300; int h = 300; return renderImage(renderer, bounds, listener, w, h); }
public void testPartialLineLabelTrue() throws Exception { // System.setProperty("java.awt.headless", "false"); Thread.sleep(1000); Style style = RendererBaseTest.loadStyle(this, "partialLineLabelTrue.sld"); DefaultMapContext mc = new DefaultMapContext(DefaultGeographicCRS.WGS84); mc.addLayer(fs_line, style); renderer.setContext(mc); final BufferedImage image = RendererBaseTest.renderImage(renderer, bounds, null); // RenderedImageBrowser.showChain(image); RendererBaseTest.assertPixel(image, 150, 1, Color.BLACK, 30); }
public void testPointLabelFalse() throws Exception { // System.setProperty("java.awt.headless", "false"); Thread.sleep(1000); Style style = RendererBaseTest.loadStyle(this, "partialPointLabelFalse.sld"); DefaultMapContext mc = new DefaultMapContext(DefaultGeographicCRS.WGS84); mc.addLayer(fs_point, style); renderer.setContext(mc); final BufferedImage image = RendererBaseTest.renderImage(renderer, bounds, null); RendererBaseTest.assertPixel(image, 282, 152, Color.WHITE); // Write to file // ImageIO.write(image, "png", new File("C:/Temp/testPartialPointLabelFalse.png")); // Interactive visualization // PartialsTest.showImage("Point Partials:False", TIME, image); }
public void testPartialPointLabelNo() throws Exception { // System.setProperty("java.awt.headless", "false"); Thread.sleep(1000); Style style = RendererBaseTest.loadStyle(this, "partialPointLabelNo.sld"); DefaultMapContext mc = new DefaultMapContext(DefaultGeographicCRS.WGS84); mc.addLayer(fs_point, style); renderer.setContext(mc); final BufferedImage image = RendererBaseTest.renderImage(renderer, bounds, null); RendererBaseTest.assertPixel(image, 282, 152, Color.WHITE); // Write to file // ImageIO.write(image, "png", new File("C:/Temp/testPartialPointLabelNo.png")); // Interactive visualization // PartialsTest.showImage("Point Partials:No", TIME, image); }
public void testPartialAreaLabelNo() throws Exception { // System.setProperty("java.awt.headless", "false"); Thread.sleep(1000); Style style = RendererBaseTest.loadStyle(this, "partialAreaLabelNo.sld"); DefaultMapContext mc = new DefaultMapContext(DefaultGeographicCRS.WGS84); mc.addLayer(fs_area, style); renderer.setContext(mc); final BufferedImage image = RendererBaseTest.renderImage(renderer, bounds, null); RendererBaseTest.assertPixel(image, 282, 152, Color.WHITE); // Write to file // ImageIO.write(image, "png", new File("C:/Temp/testPartialAreaLabelNo.png")); // Interactive visualization // PartialsTest.showImage("Area Partials:No", TIME, image); }
public void testPartialAreaLabelFalse() throws Exception { // System.setProperty("java.awt.headless", "false"); Thread.sleep(1000); Style style = RendererBaseTest.loadStyle(this, "partialAreaLabelFalse.sld"); DefaultMapContext mc = new DefaultMapContext(DefaultGeographicCRS.WGS84); mc.addLayer(fs_area, style); renderer.setContext(mc); final BufferedImage image = RendererBaseTest.renderImage(renderer, bounds, null); RendererBaseTest.assertPixel(image, 282, 152, Color.WHITE); // Write to file // ImageIO.write(image, "png", new File("C:/Temp/testPartialAreaLabelFalse.png")); // Interactive visualization // PartialsTest.showImage("Area Partials:False", TIME, image); }
public void testPartialPointLabelTrue() throws Exception { // System.setProperty("java.awt.headless", "false"); Thread.sleep(1000); Style style = RendererBaseTest.loadStyle(this, "partialPointLabelTrue.sld"); DefaultMapContext mc = new DefaultMapContext(DefaultGeographicCRS.WGS84); mc.addLayer(fs_point, style); renderer.setContext(mc); final BufferedImage image = RendererBaseTest.renderImage(renderer, bounds, null); RendererBaseTest.assertPixel(image, 282, 152, Color.BLACK); // Write to file // ImageIO.write(image, "png", new File("C:/Temp/testPartialPointLabelTrue.png")); // Interactive visualization // PartialsTest.showImage("Point Partials:True", TIME, image); }
public void testPartialLineLabelNo() throws Exception { // System.setProperty("java.awt.headless", "false"); Thread.sleep(1000); Style style = RendererBaseTest.loadStyle(this, "partialLineLabelNo.sld"); DefaultMapContext mc = new DefaultMapContext(DefaultGeographicCRS.WGS84); mc.addLayer(fs_line, style); renderer.setContext(mc); final BufferedImage image = RendererBaseTest.renderImage(renderer, bounds, null); RendererBaseTest.assertPixel(image, 282, 155, Color.WHITE); // Write to file // ImageIO.write(image, "png", new File("C:/Temp/testPartialLineLabelNo.png")); // Interactive visualization // PartialsTest.showImage("Line Partials:No", TIME, image); }
public void testPartialLineLabelFalse() throws Exception { // System.setProperty("java.awt.headless", "false"); Thread.sleep(1000); Style style = RendererBaseTest.loadStyle(this, "partialLineLabelFalse.sld"); DefaultMapContext mc = new DefaultMapContext(DefaultGeographicCRS.WGS84); mc.addLayer(fs_line, style); renderer.setContext(mc); final BufferedImage image = RendererBaseTest.renderImage(renderer, bounds, null); RendererBaseTest.assertPixel(image, 282, 155, Color.WHITE); // Write to file // ImageIO.write(image, "png", new File("C:/Temp/testPartialLineLabelFalse.png")); // Interactive visualization // PartialsTest.showImage("Line Partials:False", TIME, image); }
public void testPartialAreaLabelTrue() throws Exception { // System.setProperty("java.awt.headless", "false"); Thread.sleep(1000); Style style = RendererBaseTest.loadStyle(this, "partialAreaLabelTrue.sld"); DefaultMapContext mc = new DefaultMapContext(DefaultGeographicCRS.WGS84); mc.addLayer(fs_area, style); renderer.setContext(mc); final BufferedImage image = RendererBaseTest.renderImage(renderer, bounds, null); RendererBaseTest.assertPixel(image, 282, 152, Color.BLACK); // Write to file // ImageIO.write(image, "png", new File("C:/Temp/testPartialAreaLabelTrue.png")); // Interactive visualization // PartialsTest.showImage("Area Partials:True", TIME, image); }
@Test public void testFillSLD10HighDPI() throws Exception { Style style = RendererBaseTest.loadStyle(this, "margin/fill10.sld"); MapContent mc = new MapContent(); mc.addLayer(new FeatureLayer(bfs, style)); StreamingRenderer renderer = new StreamingRenderer(); renderer.setMapContent(mc); Map hints = Collections.singletonMap(StreamingRenderer.DPI_KEY, 300); renderer.setRendererHints(hints); BufferedImage image = RendererBaseTest.renderImage(renderer, bounds, null, 480, 480); ImageAssert.assertEquals( new File( "./src/test/resources/org/geotools/renderer/lite/test-data/margin/expected-dpi300.png"), image, 100); }
public void testFeatureCount(String sldFilename, int expectedCount) throws Exception { Style style = RendererBaseTest.loadStyle(this, sldFilename); MapContent mc = new MapContent(DefaultGeographicCRS.WGS84); mc.addLayer(new FeatureLayer(squareFS, style)); StreamingRenderer renderer = new StreamingRenderer(); renderer.setMapContent(mc); AtomicInteger count = new AtomicInteger(); renderer.addRenderListener( new RenderListener() { public void featureRenderer(SimpleFeature feature) { count.incrementAndGet(); } public void errorOccurred(Exception e) {} }); RendererBaseTest.renderImage(renderer, bounds, null); mc.dispose(); assertEquals(expectedCount, count.get()); } }
private void testCoverageStyle(Style style, String styleName) throws IOException { GridCoverage2D coverage = createCoverage(); StreamingRenderer renderer = new StreamingRenderer(); MapContent context = new MapContent(); context.addLayer(new GridCoverageLayer(coverage, style)); renderer.setMapContent(context); RenderListener listener = 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("Failed to render coverage"); } }; BufferedImage image = RendererBaseTest.renderImage(renderer, env, listener); File reference = new File( "./src/test/resources/org/geotools/renderer/lite/gridcoverage2d/" + styleName + ".png"); ImageAssert.assertEquals(reference, image, 0); }
private void checkRepeatedLabels(String styleName) throws Exception { Style style = RendererBaseTest.loadStyle(this, styleName + ".sld"); MapContent mc = new MapContent(); mc.addLayer(new FeatureLayer(fs_line, style)); mc.getViewport().setBounds(bounds); StreamingRenderer renderer = new StreamingRenderer(); renderer.setMapContent(mc); renderer.setJava2DHints(new RenderingHints(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON)); renderer.setMapContent(mc); BufferedImage image = RendererBaseTest.renderImage(renderer, bounds, null, 500, 500); File expected = new File( "src/test/resources/org/geotools/renderer/lite/test-data/" + styleName + ".png"); int tolerance = 2000; ImageAssert.assertEquals(expected, image, tolerance); }
@Test public void testArrowHeight() throws Exception { Style pStyle = RendererBaseTest.loadStyle(this, "arrowHeight.sld"); Style dotStyle = RendererBaseTest.loadStyle(this, "dot.sld"); MapContent mc = new MapContent(); mc.addLayer(new FeatureLayer(arrowBasesFS, pStyle)); mc.addLayer(new FeatureLayer(arrowBasesFS, dotStyle)); StreamingRenderer renderer = new StreamingRenderer(); renderer.setMapContent(mc); renderer.setJava2DHints(new RenderingHints(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON)); BufferedImage image = RendererBaseTest.renderImage(renderer, arrowBounds, null, 600, 100); ImageAssert.assertEquals(file("arrowHeight"), image, 50); }
@Test public void testArrowThickness() throws Exception { Style pStyle = RendererBaseTest.loadStyle(this, "arrowThickness.sld"); Style dotStyle = RendererBaseTest.loadStyle(this, "dot.sld"); MapContent mc = new MapContent(); mc.addLayer(new FeatureLayer(arrowBasesFS, pStyle)); mc.addLayer(new FeatureLayer(arrowBasesFS, dotStyle)); StreamingRenderer renderer = new StreamingRenderer(); renderer.setMapContent(mc); renderer.setJava2DHints(new RenderingHints(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON)); BufferedImage image = RendererBaseTest.renderImage(renderer, arrowBounds, null, 600, 100); ImageAssert.assertEquals(file("arrowThickness"), image, 50); }
@Test public void testArrowBase() throws Exception { Style pStyle = RendererBaseTest.loadStyle(this, "arrowBase.sld"); Style dotStyle = RendererBaseTest.loadStyle(this, "dot.sld"); MapContent mc = new MapContent(); mc.addLayer(new FeatureLayer(arrowBasesFS, pStyle)); mc.addLayer(new FeatureLayer(arrowBasesFS, dotStyle)); StreamingRenderer renderer = new StreamingRenderer(); renderer.setMapContent(mc); renderer.setJava2DHints(new RenderingHints(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON)); BufferedImage image = RendererBaseTest.renderImage(renderer, arrowBounds, null, 600, 100); ImageAssert.assertEquals(file("arrowBase"), image, 50); }
@Test public void testArrowHeightRotation() throws Exception { Style pStyle = RendererBaseTest.loadStyle(this, "arrowHeightRotation.sld"); Style dotStyle = RendererBaseTest.loadStyle(this, "dot.sld"); MapContent mc = new MapContent(); mc.addLayer(new FeatureLayer(arrowBasesFS, pStyle)); mc.addLayer(new FeatureLayer(arrowBasesFS, dotStyle)); StreamingRenderer renderer = new StreamingRenderer(); renderer.setMapContent(mc); renderer.setJava2DHints(new RenderingHints(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON)); BufferedImage image = RendererBaseTest.renderImage(renderer, arrowBounds, null, 600, 100); ImageAssert.assertEquals(file("arrowHeightRotation"), image, 50); }
@Test public void testEnvFunctionInColorMap() throws Exception { EnvFunction.setLocalValue("low", "-0.001"); EnvFunction.setLocalValue("lowColor", "#000000"); // get the source data File coverageFile = TestData.copy(this, "geotiff/float64.tif"); assertTrue(coverageFile.exists()); GridCoverage2DReader reader = new GeoTiffReader(coverageFile); // Apply the symbolizer Style style = RendererBaseTest.loadStyle(this, "float64.sld"); final MapContent mc = new MapContent(); mc.addLayer(new GridReaderLayer(reader, style)); StreamingRenderer renderer = new StreamingRenderer(); renderer.setMapContent(mc); BufferedImage image = RendererBaseTest.renderImage(renderer, mc.getViewport().getBounds(), null, 50, 50); // Check the image File reference = new File( "src/test/resources/org/geotools/renderer/lite/gridcoverage2d/flippedAffineParametric.png"); ImageAssert.assertEquals(reference, image, 2); }
public void testLetterConflictEnabled2Lines() throws Exception { LabelCacheImpl.DISABLE_LETTER_LEVEL_CONFLICT = true; Style style = RendererBaseTest.loadStyle(this, "letterConflict20.sld"); MapContent mc = new MapContent(); mc.getViewport().setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84); mc.addLayer(new FeatureLayer(fs_line2, style)); StreamingRenderer renderer = getNewRenderer(mc); final BufferedImage image1 = RendererBaseTest.renderImage(renderer, bounds1, null); mc.dispose(); LabelCacheImpl.DISABLE_LETTER_LEVEL_CONFLICT = false; style = RendererBaseTest.loadStyle(this, "letterConflict20.sld"); mc = new MapContent(); mc.getViewport().setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84); mc.addLayer(new FeatureLayer(fs_line2, style)); renderer = getNewRenderer(mc); final BufferedImage image2 = RendererBaseTest.renderImage(renderer, bounds1, null); assertTrue( "More labels in image2 than image1", countPixels(image2, Color.BLACK) > countPixels(image1, Color.BLACK)); writeImage("letterConflictEnabled2False", image1); writeImage("letterConflictEnabled2True", image2); showImage("letterConflictEnabled2 false", TIME, image1); showImage("letterConflictEnabled2 true", TIME, image2); mc.dispose(); }