GeometryClipper( final Envelope viewPort, final int width ) { this.viewPort = viewPort; this.clippingArea = calculateClippingArea( viewPort, width ); }
/** * Clips the passed geometry with the drawing area if the drawing area does not contain the passed geometry * completely. * * @param geom * the geometry to clip, must not be <code>null</code> and in the same CRS as the clipping area * @return the clipped geometry or the original geometry if the geometry lays completely in the drawing area. */ Geometry clipGeometry( final Geometry geom ) { return clipGeometry( geom, clippingArea ); }
public static boolean isGenerationExpensive( PolygonStyling styling ) { if ( styling == null ) return false; return ( !isZero( styling.perpendicularOffset ) || isGenerationExpensive( styling.stroke )); }
private void handlePolygonWithAutoPlacement( TextStyling styling, Font font, String text, Polygon geom ) { Geometry transformedGeom = renderer.rendererContext.geomHelper.transform( geom ); MultiPoint points = renderer.rendererContext.clipper.calculateInteriorPoints( transformedGeom ); if ( geom == null ) return; handleMultiGeometry( styling, text, font, (MultiGeometry) points ); }
Geometry clipGeometry( final Geometry geom, Geometry clippingArea ) { if ( clippingArea != null && !clippingArea.contains( geom ) ) { try { Geometry clippedGeometry = clippingArea.getIntersection( geom ); if ( clippedGeometry == null ) { return null; } com.vividsolutions.jts.geom.Geometry jtsOrig = ( (AbstractDefaultGeometry) geom ).getJTSGeometry(); com.vividsolutions.jts.geom.Geometry jtsClipped = ( (AbstractDefaultGeometry) clippedGeometry ).getJTSGeometry(); if ( jtsOrig == jtsClipped ) { return geom; } if ( isInvertedOrientation( jtsOrig ) ) { return clippedGeometry; } return fixOrientation( clippedGeometry, clippedGeometry.getCoordinateSystem() ); } catch ( UnsupportedOperationException e ) { // use original geometry if intersection not supported by JTS return geom; } } return geom; }
RendererContext( double pixelSize, double res, Graphics2D graphics, Java2DRenderer renderer, Envelope bbox, int width, AffineTransform worldToScreen ) { this.graphics = graphics; if ( bbox != null ) { geomHelper = new GeometryHelper( bbox, width, worldToScreen ); clipper = new GeometryClipper( bbox, width ); } uomCalculator = new UomCalculator( pixelSize, res ); fillRenderer = new Java2DFillRenderer( uomCalculator, graphics ); strokeRenderer = new Java2DStrokeRenderer( graphics, uomCalculator, fillRenderer ); svgRenderer = new SvgRenderer(); polygonRenderer = new PolygonRenderer( geomHelper, fillRenderer, strokeRenderer, graphics, renderer ); curveRenderer = new CurveRenderer( renderer ); pointRenderer = new PointRenderer( renderer.worldToScreen, this ); }
public static boolean isGenerationExpensive( LineStyling styling ) { if ( styling == null ) return false; return ( !isZero( styling.perpendicularOffset ) || isGenerationExpensive( styling.stroke ) ); }
Geometry transformToWorldCrsAndClip( final Geometry geom ) { final Geometry geomInWorldCrs = rendererContext.geomHelper.transform( geom ); if ( rendererContext.clipper == null ) { LOG.warn( "No clipper defined, geometry will be ignored for rendering" ); return null; } return rendererContext.clipper.clipGeometry( geomInWorldCrs ); }
if ( isGenerationExpensive( styling ) ) { renderGeometry = transformToWorldCrsAndClip( geom ); if ( renderGeometry == null ) {
@Override public void createLabel( TextStyling styling, String text, Geometry geom ) { if ( geom == null ) { LOG.debug( "Trying to render null geometry." ); } if ( text == null || text.length() == 0 ) { LOG.debug( "Trying to render null or zero length text." ); } geom = renderer.rendererContext.geomHelper.transform( geom ); geom = renderer.rendererContext.clipper.clipGeometry( geom ); Font font = textRenderer.convertFont( styling ); handleGeometryTypes( styling, text, font, geom ); }
if ( isGenerationExpensive( styling ) ) { renderGeometry = transformToWorldCrsAndClip( geom ); if ( renderGeometry == null ) {
/** * Calculates the points inside the geometry and inside the view port. First the passed geometry is clipped * by the view port. A multipolygon may result. For each of the polygon in this multipolygon one interior point * is created * * @param geom to create labels for, must not be <code>null</code> and in the same CRS as the viewPort * @return a MultiPoint with all calculated labels */ MultiPoint calculateInteriorPoints( final Geometry geom ) { if ( geom == null ) return null; Geometry clippedGeometry = clipGeometry( geom, viewPort ); List<Point> points = new ArrayList<Point>(); if ( clippedGeometry != null && clippedGeometry instanceof DefaultSurface ) { points.add( ( (DefaultSurface) clippedGeometry ).getInteriorPoint() ); } if ( clippedGeometry != null && clippedGeometry instanceof MultiPolygon ) { for ( Polygon p : ( (MultiPolygon) clippedGeometry ) ) { if ( p instanceof DefaultSurface ) { points.add( ( (DefaultSurface) p ).getInteriorPoint() ); } } } return new GeometryFactory().createMultiPoint( null, geom.getCoordinateSystem(), points ); }