/** * Returns an estimate of the rendering buffer needed to properly display this layer taking into * consideration the constant stroke sizes in the feature type styles. * * @param styles the feature type styles to be applied to the layer * @return an estimate of the buffer that should be used to properly display a layer rendered * with the specified styles */ private int findRenderingBuffer(List<LiteFeatureTypeStyle> styles) { final MetaBufferEstimator rbe = new MetaBufferEstimator(); for (LiteFeatureTypeStyle lfts : styles) { Rule[] rules = lfts.elseRules; for (int j = 0; j < rules.length; j++) { rbe.visit(rules[j]); } rules = lfts.ruleList; for (int j = 0; j < rules.length; j++) { rbe.visit(rules[j]); } } if (!rbe.isEstimateAccurate()) LOGGER.fine( "Assuming rendering buffer = " + rbe.getBuffer() + ", but estimation is not accurate, you may want to set a buffer manually"); // the actual amount we have to grow the rendering area by is half of the stroke/symbol // sizes // plus one extra pixel for antialiasing effects return (int) Math.round(rbe.getBuffer() / 2.0 + 1); }
/** @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.Stroke) */ public void visit(Stroke stroke) { try { Expression width = stroke.getWidth(); if (!isNull(width)) { evaluateWidth(width); } if (stroke.getGraphicStroke() != null) { stroke.getGraphicStroke().accept(this); } } catch (ClassCastException e) { estimateAccurate = false; LOGGER.info("Could not parse stroke width, " + "it's a literal but not a Number..."); } }
int textSize = getPositiveValue(font.getSize()); int delta = -1; if (text.getLabelPlacement() instanceof PointPlacement) { Displacement pd = pp.getDisplacement(); if (pd != null) { int dx = getPositiveValue(pd.getDisplacementX()); int dy = getPositiveValue(pd.getDisplacementY()); delta = Math.max(dx, dy); double ax = Math.abs(getDouble(ap.getAnchorPointX()) - 0.5); double ay = Math.abs(getDouble(ap.getAnchorPointY()) - 0.5); int anchorDelta = (int) Math.ceil(Math.max(ax, ay) * textSize); if (delta > 0) {
@Test public void testExternalGraphic() throws Exception { Style style = RendererBaseTest.loadStyle(this, "externalGraphic.sld"); MetaBufferEstimator estimator = new MetaBufferEstimator(); style.accept(estimator); assertTrue(estimator.isEstimateAccurate()); assertEquals(48, estimator.getBuffer()); }
/** * Computes the rendering buffer for this layer * * @param style * @param scaleDenominator */ static int computeLayerBuffer(Style style, double scaleDenominator) { final double TOLERANCE = 1e-6; MetaBufferEstimator estimator = new MetaBufferEstimator(); for (FeatureTypeStyle fts : style.featureTypeStyles()) { for (Rule rule : fts.rules()) { if (((rule.getMinScaleDenominator() - TOLERANCE) <= scaleDenominator) && ((rule.getMaxScaleDenominator() + TOLERANCE) > scaleDenominator)) { estimator.visit(rule); } } } // we get any estimate, it's better than nothing... return estimator.getBuffer(); }
public static int getComputedBuffer( final int requestBufferScreen, List<LiteFeatureTypeStyle> styleList) { final int bufferScreen; if (requestBufferScreen <= 0) { MetaBufferEstimator bufferEstimator = new MetaBufferEstimator(); styleList .stream() .flatMap( fts -> Stream.concat( Arrays.stream(fts.elseRules), Arrays.stream(fts.ruleList))) .forEach(bufferEstimator::visit); bufferScreen = bufferEstimator.getBuffer(); } else { bufferScreen = requestBufferScreen; } return bufferScreen; }
@Test public void testDynamicSize() throws Exception { Style style = RendererBaseTest.loadStyle(this, "externalGraphicDynamicSize.sld"); MetaBufferEstimator estimator = new MetaBufferEstimator(); style.accept(estimator); assertFalse(estimator.isEstimateAccurate()); }
for (int i = 0; i < ruleCount; i++) { Feature sample = getSampleFeatureForRule(featureType, feature, rules[i]); MetaBufferEstimator estimator = new MetaBufferEstimator(sample); final Symbolizer[] symbolizers = rules[i].getSymbolizers(); for (int sIdx = 0; sIdx < symbolizers.length; sIdx++) {
/** @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.Symbolizer) */ public void visit(Symbolizer sym) { if (sym instanceof PointSymbolizer) { visit((PointSymbolizer) sym); } if (sym instanceof LineSymbolizer) { visit((LineSymbolizer) sym); } if (sym instanceof PolygonSymbolizer) { visit((PolygonSymbolizer) sym); } if (sym instanceof TextSymbolizer) { visit((TextSymbolizer) sym); } if (sym instanceof RasterSymbolizer) { visit((RasterSymbolizer) sym); } }
/** * Gets a numeric value for the given PointSymbolizer * * @param feature sample to be used for evals * @param symbolizer symbolizer * @param defaultSize size to use is none can be taken from the symbolizer */ private double getSymbolizerSize( MetaBufferEstimator estimator, Symbolizer symbolizer, double defaultSize) { estimator.reset(); symbolizer.accept(estimator); int buffer = estimator.getBuffer(); if (buffer > 0) { return buffer; } else { return defaultSize; } }
protected int getPositiveValue(Expression ex) { double value = getDouble(ex); if (value == -1) { return -1; } else { return (int) Math.ceil(value); } }
@Test public void testMark() throws Exception { Style style = RendererBaseTest.loadStyle(this, "markCircle.sld"); MetaBufferEstimator estimator = new MetaBufferEstimator(); style.accept(estimator); assertTrue(estimator.isEstimateAccurate()); assertEquals(32, estimator.getBuffer()); }
} else { MetaBufferEstimator estimator = new MetaBufferEstimator(); for (Rule rule : rules) { rule.accept(estimator); int estimatedRadius = estimator.getBuffer() / 2; if (estimatedRadius < MIN_BUFFER_SIZE) { radius = MIN_BUFFER_SIZE;
MetaBufferEstimator estimator = new MetaBufferEstimator(sampleFeature); for (int i = 0; i < ruleCount; i++) {
/** * @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.Symbolizer) */ public void visit(Symbolizer sym) { if (sym instanceof PointSymbolizer) { visit((PointSymbolizer) sym); } if (sym instanceof LineSymbolizer) { visit((LineSymbolizer) sym); } if (sym instanceof PolygonSymbolizer) { visit((PolygonSymbolizer) sym); } if (sym instanceof TextSymbolizer) { visit((TextSymbolizer) sym); } if (sym instanceof RasterSymbolizer) { visit((RasterSymbolizer) sym); } }
@Test public void testTextNoStroke() { Style style = sb.createStyle(sb.createTextSymbolizer()); MetaBufferEstimator rbe = new MetaBufferEstimator(); assertEquals(0, rbe.getBuffer()); assertTrue(rbe.isEstimateAccurate()); rbe.visit(style); assertEquals(15, rbe.getBuffer()); assertTrue(rbe.isEstimateAccurate()); }
@Test public void testPolygon() throws Exception { Style style = RendererBaseTest.loadStyle(this, "polygon.sld"); MetaBufferEstimator estimator = new MetaBufferEstimator(); style.accept(estimator); assertTrue(estimator.isEstimateAccurate()); assertEquals(1, estimator.getBuffer()); }
/** * @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.Symbolizer) */ public void visit(Symbolizer sym) { if (sym instanceof PointSymbolizer) { visit((PointSymbolizer) sym); } if (sym instanceof LineSymbolizer) { visit((LineSymbolizer) sym); } if (sym instanceof PolygonSymbolizer) { visit((PolygonSymbolizer) sym); } if (sym instanceof TextSymbolizer) { visit((TextSymbolizer) sym); } if (sym instanceof RasterSymbolizer) { visit((RasterSymbolizer) sym); } }
/** * @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.Stroke) */ public void visit(Stroke stroke) { try { Expression width = stroke.getWidth(); if (!isNull(width)) { evaluateWidth(width); } if(stroke.getGraphicStroke() != null) { stroke.getGraphicStroke().accept(this); } } catch (ClassCastException e) { estimateAccurate = false; LOGGER.info("Could not parse stroke width, " + "it's a literal but not a Number..."); } }
@Test public void testSimpleStroke() { Style style = sb.createStyle(sb.createLineSymbolizer(sb.createStroke(10.0))); MetaBufferEstimator rbe = new MetaBufferEstimator(); rbe.visit(style); assertEquals(10, rbe.getBuffer()); assertTrue(rbe.isEstimateAccurate()); }