public void testSkipProjectionErrors() throws Exception { // build map context MapContext mapContext = new DefaultMapContext(DefaultGeographicCRS.WGS84); mapContext.addLayer(createLineCollection(), createLineStyle()); // build projected envelope to work with (small one around the area of // validity of utm zone 1, which being a Gauss projection is a vertical // slice parallel to the central meridian, -177°) ReferencedEnvelope reWgs = new ReferencedEnvelope(new Envelope(-180, -170, 20, 40), DefaultGeographicCRS.WGS84); CoordinateReferenceSystem utm1N = CRS.decode("EPSG:32601"); System.out.println(CRS.getGeographicBoundingBox(utm1N)); ReferencedEnvelope reUtm = reWgs.transform(utm1N, true); BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_4BYTE_ABGR); // setup the renderer and listen for errors StreamingRenderer sr = new StreamingRenderer(); sr.setRendererHints(Collections.singletonMap(sr.OPTIMIZED_DATA_LOADING_KEY, Boolean.FALSE)); sr.setContext(mapContext); sr.addRenderListener( new RenderListener() { public void featureRenderer(SimpleFeature feature) {} public void errorOccurred(Exception e) { e.printStackTrace(); errors++; } }); errors = 0; sr.paint((Graphics2D) image.getGraphics(), new Rectangle(200, 200), reUtm); // we should get two errors since there are two features that cannot be // projected but the renderer itself should not throw exceptions assertEquals(2, errors); }
@Override protected void setUp() throws Exception { // setup data File property = new File(TestData.getResource(this, "diaglines.properties").toURI()); PropertyDataStore ds = new PropertyDataStore(property.getParentFile()); fs = ds.getFeatureSource("diaglines"); bounds = new ReferencedEnvelope(0, 10, 0, 10, DefaultGeographicCRS.WGS84); renderer = new StreamingRenderer(); Map rendererParams = new HashMap(); LabelCacheImpl labelCache = new LabelCacheImpl(); rendererParams.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache); renderer.setRendererHints(rendererParams); renderer.setJava2DHints(new RenderingHints(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON)); // System.setProperty("org.geotools.test.interactive", "true"); }