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); } }
/** * Extracts a ath iterator from the shape * * @param shape * @return */ private PathIterator getPathIterator(final LiteShape2 shape) { return shape.getPathIterator(IDENTITY_TRANSFORM); }
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))); }
/** * 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); } }
if (shape.getGeometry() instanceof GeometryCollection) gc = (GeometryCollection) shape.getGeometry(); else { Geometry[] gs = new Geometry[1]; gs[0] = shape.getGeometry(); gc = shape.getGeometry().getFactory().createGeometryCollection( PathIterator iter = shape.getPathIterator(IDENTITY_TRANSFORM); iter.currentSegment(coords);
/** Construct <code>LabelCacheItem</code>. */ public LabelCacheItem( String layerId, TextStyle2D textStyle, LiteShape2 shape, String label, TextSymbolizer symbolizer) { this.textStyle = textStyle; this.geoms.add(shape.getGeometry()); this.label = label; this.layerIds.add(layerId); this.symbolizer = symbolizer; }
/** * Returns an integer {@link Rectangle}that completely encloses the <code>Shape</code>. Note * that there is no guarantee that the returned <code>Rectangle</code> is the smallest bounding * box that encloses the <code>Shape</code>, only that the <code>Shape</code> lies entirely * within the indicated <code>Rectangle</code>. The returned <code>Rectangle</code> might also * fail to completely enclose the <code>Shape</code> if the <code>Shape</code> overflows the * limited range of the integer data type. The <code>getBounds2D</code> method generally returns * a tighter bounding box due to its greater flexibility in representation. * * @return an integer <code>Rectangle</code> that completely encloses the <code>Shape</code>. * @see #getBounds2D */ public Rectangle getBounds() { Rectangle2D env = getBounds2D(); return new Rectangle( (int) Math.round(env.getMinX()), (int) Math.round(env.getMinY()), (int) Math.ceil(env.getWidth()), (int) Math.ceil(env.getHeight())); }
/** * Converts the Rectangle2D passed as parameter in a jts Geometry object * * @param r the rectangle to be converted * @return a geometry with the same vertices as the rectangle */ private Geometry rectangleToGeometry(Rectangle2D r) { return createRectangle(r.getMinX(), r.getMinY(), r.getWidth(), r.getHeight()); }
env.expandBy(clipBuffer); final GeometryClipper clipper = new GeometryClipper(env); Geometry source = shape.getGeometry(); || source instanceof MultiPolygon); Geometry g = clipper.clipSafe(shape.getGeometry(), preserveTopology, 1); continue; } else { shape = new LiteShape2(g, null, null, false);
groupItem.getGeoms().add(shape.getGeometry());
Rectangle2D bounds = shape.getBounds2D(); return bounds.getWidth() < lineWidth || bounds.getHeight() < lineWidth;
Geometry rect = createRectangle(x, y, w, h);
/** * 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); } }
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))); }
/** * Construct <code>LabelCacheItem</code>. */ public LabelCacheItem(String layerId, TextStyle2D textStyle, LiteShape2 shape, String label) { this.textStyle = textStyle; this.geoms.add(shape.getGeometry()); this.label = label; this.layerIds.add(layerId); }
return getPathIterator(at);
labelCache.put(shape.getBounds2D());
Geometry rect = createRectangle(x, y, w, h);
try { stippleShape = new LiteShape2(stipplePoint, identityTransf, nullDecimator, false); } catch (Exception e) { throw new RuntimeException("Unxpected exception building lite shape", e);