private void paintLine( StyledShapePainter painter, Graphics2D graphics, LineStyle2D lineStyle, AffineTransform2D identityTransf, Decimator nullDecimator, LineString stippleLine) { stippleLine.geometryChanged(); LiteShape2 stippleShape; try { stippleShape = new LiteShape2(stippleLine, identityTransf, nullDecimator, false); } catch (Exception e) { throw new RuntimeException("Unxpected exception building lite shape", e); } painter.paintLineStyle(graphics, stippleShape, lineStyle, false, 0); } }
/** * Compute the footprint. * * @param geometriesList the List of all the geometries found across the dataset * @param transform * @throws MismatchedDimensionException * @throws TransformException * @throws FactoryException */ private void computeFootprint(List<Polygon> geometriesList, MathTransform transform) throws MismatchedDimensionException, TransformException, FactoryException { // Creating the final multipolygon Polygon[] polArray = new Polygon[geometriesList.size()]; Polygon[] polygons = geometriesList.toArray(polArray); final Geometry innerGeometry = new MultiPolygon(polygons, GF); if (footprintCoordinates == FootprintCoordinates.MODEL_SPACE) { this.footprint = JTS.transform(innerGeometry, transform); } else { this.footprint = innerGeometry; innerGeometry.setSRID(NO_SRID); } // Compute the ROIShape if (!innerGeometry.isEmpty()) { LiteShape2 shape = new LiteShape2(innerGeometry, TRANSLATED_TX, null, false); roiShape = (ROIShape) new ROIShape(shape); } }
/** * Filling multipolygons might result in holes where two polygons overlap. In this method we * work around that by drawing each polygon as a separate shape * * @param g * @param shape */ void fillLiteShape(Graphics2D g, LiteShape2 shape) { if (shape.getGeometry() instanceof MultiPolygon && shape.getGeometry().getNumGeometries() > 1) { MultiPolygon mp = (MultiPolygon) shape.getGeometry(); for (int i = 0; i < mp.getNumGeometries(); i++) { Polygon p = (Polygon) mp.getGeometryN(i); try { g.fill(new LiteShape2(p, null, null, false, false)); } catch (Exception e) { // should not really happen, but anyways throw new RuntimeException( "Unexpected error occurred while rendering a multipolygon", e); } } } else { g.fill(shape); } }
@Before public void setUp() throws TransformException, FactoryException { graphics = Mockito.mock(Graphics2D.class); Mockito.when(graphics.getFontRenderContext()) .thenReturn( new FontRenderContext( new AffineTransform(), RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT, RenderingHints.VALUE_FRACTIONALMETRICS_DEFAULT)); style = new TextStyle2D(); style.setFont(new Font("Serif", Font.PLAIN, 10)); shape = new LiteShape2( geometryFactory.createPoint(new Coordinate(10, 10)), ProjectiveTransform.create(new AffineTransform()), null, false); symbolizer = styleFactory.createTextSymbolizer(); }
@Test public void testUsesCustomLabelPainter() throws Exception { LabelPainter painter = Mockito.mock(LabelPainter.class); Graphics2D graphics = Mockito.mock(Graphics2D.class); cache.setConstructPainter((x, y) -> painter); TextSymbolizer ts = sb.createTextSymbolizer(Color.BLACK, (Font) null, "name"); SimpleFeature f1 = createFeature("label1", L1); cache.put( LAYER_ID, ts, f1, new LiteShape2((Geometry) f1.getDefaultGeometry(), null, null, false), ALL_SCALES); cache.endLayer(LAYER_ID, graphics, new Rectangle(0, 0, 256, 256)); cache.end(graphics, new Rectangle(0, 0, 256, 256)); Mockito.verify(painter).setLabel(Mockito.any(LabelCacheItem.class)); Mockito.verify(painter, Mockito.atLeastOnce()).getLabel(); }
public void testGraphicLegendNullLegend() throws Exception { StyledShapePainter painter = new StyledShapePainter(); BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = (Graphics2D) image.getGraphics(); MathTransform transform = ProjectiveTransform.create(new AffineTransform()); Decimator decimator = new Decimator(transform); Point point = new GeometryFactory().createPoint(new Coordinate(10, 10)); LiteShape2 pointShape = new LiteShape2(point, transform, decimator, false); try { painter.paint(g2, pointShape, (GraphicLegend) null, 1, false); fail(); } catch (NullPointerException e) { assertEquals("ShapePainter has been asked to paint a null legend!!", e.getMessage()); } }
@Test public void testGraphicLegendNegativeScale() throws Exception { // Load image directly from file, for comparison with painter output final URL imageURL = TestData.getResource(this, "icon64.png"); final BufferedImage testImage = ImageIO.read(imageURL); final int width = testImage.getWidth(); final int height = testImage.getHeight(); // Get graphic legend from style final Style style = RendererBaseTest.loadStyle(this, "testGraphicLegend.sld"); final Rule rule = style.featureTypeStyles().get(0).rules().get(0); final GraphicLegend legend = (GraphicLegend) rule.getLegend(); // Paint legend using StyledShapePainter final Point point = new GeometryFactory().createPoint(new Coordinate(width / 2, height / 2)); final LiteShape2 shape = new LiteShape2(point, null, null, false); int imageType = testImage.getType(); if (imageType == BufferedImage.TYPE_CUSTOM) { imageType = BufferedImage.TYPE_INT_RGB; } final BufferedImage paintedImage = new BufferedImage(width, height, imageType); final Graphics2D graphics = paintedImage.createGraphics(); final StyledShapePainter painter = new StyledShapePainter(); painter.paint(graphics, shape, legend, -1, false); graphics.dispose(); // Ensure painted legend matches image from file Assert.assertTrue(imagesIdentical(paintedImage, testImage)); }
shape = new LiteShape2(geom, null, null, false, false); MathTransform xform = null; if (sa != null) xform = sa.xform; shape = new LiteShape2(geom, xform, getDecimator(xform), false, false);
@Test public void testGraphicLegend() throws Exception { // Load image directly from file, for comparison with painter output final URL imageURL = TestData.getResource(this, "icon64.png"); final BufferedImage testImage = ImageIO.read(imageURL); final int width = testImage.getWidth(); final int height = testImage.getHeight(); // Get graphic legend from style final Style style = RendererBaseTest.loadStyle(this, "testGraphicLegend.sld"); final Rule rule = style.featureTypeStyles().get(0).rules().get(0); final GraphicLegend legend = (GraphicLegend) rule.getLegend(); // Paint legend using StyledShapePainter final Point point = new GeometryFactory().createPoint(new Coordinate(width / 2, height / 2)); final LiteShape2 shape = new LiteShape2(point, null, null, false); int imageType = testImage.getType(); if (imageType == BufferedImage.TYPE_CUSTOM) { imageType = BufferedImage.TYPE_INT_RGB; } final BufferedImage paintedImage = new BufferedImage(width, height, imageType); final Graphics2D graphics = paintedImage.createGraphics(); final StyledShapePainter painter = new StyledShapePainter(); painter.paint(graphics, shape, legend, 1, false); graphics.dispose(); // Ensure painted legend matches image from file Assert.assertTrue(imagesIdentical(paintedImage, testImage)); }
ts, f1, new LiteShape2((Geometry) f1.getDefaultGeometry(), null, null, false), ALL_SCALES); cache.endLayer("layerId", null, null);
public void testGraphicLegendRotation() throws Exception { FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(); GeometryFactory gf = JTSFactoryFinder.getGeometryFactory(); // Load image directly from file, for comparison with painter output final URL imageURL = TestData.getResource(this, "icon64.png"); final BufferedImage testImage = ImageIO.read(imageURL); final int width = testImage.getWidth(); final int height = testImage.getHeight(); // Get graphic legend from style final Style style = RendererBaseTest.loadStyle(this, "testGraphicLegend.sld"); final Rule rule = style.featureTypeStyles().get(0).rules().get(0); final GraphicLegend legend = (GraphicLegend) rule.getLegend(); // Set rotation to 45 degrees legend.setRotation(ff.literal(45.0)); // Paint legend using StyledShapePainter final Point point = gf.createPoint(new Coordinate(width / 2, height / 2)); final LiteShape2 shape = new LiteShape2(point, null, null, false); int imageType = testImage.getType(); if (imageType == BufferedImage.TYPE_CUSTOM) { imageType = BufferedImage.TYPE_INT_RGB; } final BufferedImage paintedImage = new BufferedImage(width, height, imageType); final Graphics2D graphics = paintedImage.createGraphics(); final StyledShapePainter painter = new StyledShapePainter(); painter.paint(graphics, shape, legend, 1, false); graphics.dispose(); // Ensure painted legend does not match image from file Assert.assertFalse(imagesIdentical(paintedImage, testImage)); }
@Test public void testSimpleGrouping() throws Exception { TextSymbolizer ts = sb.createTextSymbolizer(Color.BLACK, (Font) null, "name"); ts.getOptions().put(TextSymbolizer.GROUP_KEY, "true"); SimpleFeature f1 = createFeature("label1", L1); SimpleFeature f2 = createFeature("label1", L2); cache.put( LAYER_ID, ts, f1, new LiteShape2((Geometry) f1.getDefaultGeometry(), null, null, false), ALL_SCALES); cache.put( LAYER_ID, ts, f2, new LiteShape2((Geometry) f2.getDefaultGeometry(), null, null, false), ALL_SCALES); // we have just one List<LabelCacheItem> labels = cache.getActiveLabels(); assertEquals(1, labels.size()); LabelCacheItem item = labels.get(0); assertEquals("label1", item.getLabel()); assertEquals(2, item.getGeoms().size()); }
@Test public void testGroupDifferentSymbolizers() throws Exception { TextSymbolizer ts1 = sb.createTextSymbolizer(Color.BLACK, (Font) null, "name"); ts1.getOptions().put(TextSymbolizer.GROUP_KEY, "true"); TextSymbolizer ts2 = sb.createTextSymbolizer(Color.YELLOW, (Font) null, "name"); ts2.getOptions().put(TextSymbolizer.GROUP_KEY, "true"); SimpleFeature f1 = createFeature("label1", L1); SimpleFeature f2 = createFeature("label1", L2); cache.put( LAYER_ID, ts1, f1, new LiteShape2((Geometry) f1.getDefaultGeometry(), null, null, false), ALL_SCALES); cache.put( LAYER_ID, ts2, f2, new LiteShape2((Geometry) f2.getDefaultGeometry(), null, null, false), ALL_SCALES); // two different symbolizers, we should have two List<LabelCacheItem> labels = cache.getActiveLabels(); assertEquals(2, labels.size()); }
ts, f1, new LiteShape2((Geometry) f1.getDefaultGeometry(), null, null, false), ALL_SCALES);
@Test public void testRendererListener() throws Exception { TextSymbolizer ts = sb.createTextSymbolizer(Color.BLACK, (Font) null, "name"); AtomicReference<Exception> exception = new AtomicReference<Exception>(null); RenderListener listener = new RenderListener() { @Override public void featureRenderer(SimpleFeature feature) { // TODO Auto-generated method stub } @Override public void errorOccurred(Exception e) { exception.set(e); } }; cache.addRenderListener(listener); SimpleFeature f1 = createFeature("label1", L1); cache.put( LAYER_ID, ts, f1, new LiteShape2((Geometry) f1.getDefaultGeometry(), null, null, false), ALL_SCALES); cache.endLayer("layerId", null, null); TestGraphics testGraphics = new TestGraphics(); testGraphics.setRenderingHints(Collections.emptyMap()); cache.end(testGraphics, new Rectangle(0, 0, 10, 10)); // got here, did we get the exception assertNotNull(exception.get()); }
tsGroup, f1, new LiteShape2((Geometry) f1.getDefaultGeometry(), null, null, false), ALL_SCALES); cache.put( ts, f2, new LiteShape2((Geometry) f2.getDefaultGeometry(), null, null, false), ALL_SCALES); cache.put( tsGroup, f3, new LiteShape2((Geometry) f3.getDefaultGeometry(), null, null, false), ALL_SCALES);
public void testPolygonShape() throws TransformException, FactoryException { GeometryFactory geomFac = new GeometryFactory(); Polygon polygon = makeSamplePolygon(geomFac, 0, 0); LiteShape2 lineShape = new LiteShape2( polygon, ProjectiveTransform.create(new AffineTransform()), new Decimator(ProjectiveTransform.create(new AffineTransform())), false); assertFalse(lineShape.contains(0, 0)); assertTrue(lineShape.contains(100, 100)); assertFalse(lineShape.contains(50, 50, 10, 10)); assertTrue(lineShape.contains(100, 100, 10, 10)); assertTrue(lineShape.contains(new java.awt.Point(70, 90))); assertFalse(lineShape.contains(new java.awt.geom.Rectangle2D.Float(50, 50, 10, 10))); assertTrue(lineShape.getBounds2D().equals(new Rectangle2D.Double(60, 70, 70, 50))); assertTrue(lineShape.getBounds().equals(new java.awt.Rectangle(60, 70, 70, 50))); assertTrue(lineShape.intersects(0, 0, 100, 100)); assertTrue(lineShape.intersects(new Rectangle2D.Double(0, 0, 100, 100))); assertFalse(lineShape.intersects(55, 55, 3, 100)); assertFalse(lineShape.intersects(new Rectangle2D.Double(55, 55, 3, 100))); }
Decimator decimator = new Decimator(transform); Point point = new GeometryFactory().createPoint(new Coordinate(10, 10)); LiteShape2 pointShape = new LiteShape2(point, transform, decimator, false); painter.paint(g2, pointShape, legend, 1, false);
public void testLineShape2() throws TransformException, FactoryException { GeometryFactory geomFac = new GeometryFactory(); LineString lineString = makeSampleLineString(geomFac, 0, 0); MathTransform transform = ProjectiveTransform.create(new AffineTransform()); Decimator decimator = new Decimator(transform); LiteShape2 lineShape = new LiteShape2(lineString, transform, decimator, false); assertFalse(lineShape.contains(0, 0)); assertTrue(lineShape.contains(60, 60)); assertFalse(lineShape.contains(50, 50, 10, 10)); assertTrue(lineShape.contains(new java.awt.Point(60, 60))); assertFalse(lineShape.contains(new java.awt.geom.Rectangle2D.Float(50, 50, 10, 10))); assertTrue(lineShape.getBounds2D().equals(new Rectangle2D.Double(50, 50, 80, 250))); assertTrue(lineShape.getBounds().equals(new java.awt.Rectangle(50, 50, 80, 250))); assertTrue(lineShape.intersects(0, 0, 100, 100)); assertTrue(lineShape.intersects(new Rectangle2D.Double(0, 0, 100, 100))); assertFalse(lineShape.intersects(55, 55, 3, 100)); assertFalse(lineShape.intersects(new Rectangle2D.Double(55, 55, 3, 100))); }
public void testCloning() throws TransformException, FactoryException { LiteCoordinateSequenceFactory csFac = new LiteCoordinateSequenceFactory(); GeometryFactory geomFac = new GeometryFactory(csFac); CoordinateSequence cs = csFac.create(4, 2); cs.setOrdinate(0, 0, 10); cs.setOrdinate(0, 1, 10); cs.setOrdinate(1, 0, 12); cs.setOrdinate(1, 1, 12); cs.setOrdinate(2, 0, 14); cs.setOrdinate(2, 1, 12); cs.setOrdinate(3, 0, 30); cs.setOrdinate(3, 1, 10); LineString ls = geomFac.createLineString(cs); LineString copy = (LineString) ls.copy(); LiteShape2 ltCloning = new LiteShape2( ls, ProjectiveTransform.create(AffineTransform.getScaleInstance(10, 10)), new Decimator(4, 4), true); assertTrue(ls.equalsExact(copy)); LiteShape2 ltNotCloning = new LiteShape2( ls, ProjectiveTransform.create(AffineTransform.getScaleInstance(10, 10)), new Decimator(4, 4), true, false); assertFalse(ls.equalsExact(copy)); }