Class StreamingRenderer
- Object
-
- StreamingRenderer
-
- All Implemented Interfaces:
GTRenderer
public class StreamingRenderer extends Object implements GTRenderer
A streaming implementation of the GTRenderer interface.- Uses as little memory as possible by processing features as they come from the data source, instead of accumulating them up-front
The streaming renderer is not thread safe
- Author:
- James Macgill, dblasby, jessie eichar, Simone Giannecchini, Andrea Aime, Alessio Fabiani
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classStreamingRenderer.EndRequestMarks the end of the request flow, instructs the painting thread to exitprotected classStreamingRenderer.FeatureRenderedRequestA request to paint a shape with a specific Style2Dprotected classStreamingRenderer.MargeCompositingGroupRequestprotected classStreamingRenderer.MergeLayersRequestA request to merge multiple back buffers to the main graphicsprotected classStreamingRenderer.PaintShapeRequestA request to paint a shape with a specific Style2Dprotected classStreamingRenderer.RenderCoverageReaderRequestA request to render a rasterprotected classStreamingRenderer.RenderDirectLayerRequestclassStreamingRenderer.RenderingBlockingQueueA blocking queue subclass with a special behavior for the occasion when the rendering stop has been requested: puts are getting ignored, and take always returns an EndRequestprotected classStreamingRenderer.RenderingRequestA request sent to the painting threadprotected classStreamingRenderer.RenderRasterRequestA request to render a rasterclassStreamingRenderer.RenderTimeStatisticsRequest
-
Field Summary
Fields Modifier and Type Field Description static StringADVANCED_PROJECTION_DENSIFICATION_KEYBoolean flag indicating whether advanced projection densification should be used when needed.static StringADVANCED_PROJECTION_DENSIFICATION_TOLERANCE_KEYDensification Tolerance, to be used when densification is enabled.static StringADVANCED_PROJECTION_HANDLING_KEYEnables advanced reprojection handling.static StringBYLAYER_INTERPOLATIONstatic StringCONTINUOUS_MAP_WRAPPINGEnabled continuous cartographic wrapping for projections that can wrap around their edges (e.g., Mercator): this results in a continous horizontal map much like Google Mapsstatic StringDATELINE_WRAPPING_HEURISTIC_KEYBoolean flag indicating whether advanced projection wrapping heuristic should be used or nto.static StringDECLARED_SCALE_DENOM_KEYstatic StringDPI_KEYprotected static FilterFactoryfilterFactoryFilter factory for creating bounding box filtersstatic StringFORCE_EPSG_AXIS_ORDER_KEYstatic StringLABEL_CACHE_KEYprotected LabelCachelabelCachestatic StringLINE_WIDTH_OPTIMIZATION_KEYWhether the thin line width optimization should be used, or not.static StringOPTIMIZE_FTS_RENDERING_KEYBoolean flag controlling a memory/speed trade off related to how multiple feature type styles are rendered.protected StyledShapePainterpainterThe painter class we use to depict shapes onto the screenstatic StringRENDERING_BUFFERThe rendering buffer grows the query area to account for features that are contributing to the requested area due to their large symbolizer, or long labelstatic StringSCALE_ACCURATEComputes the scale as the ratio between map distances and real world distances, assuming 90dpi and taking into consideration projection deformations and actual earth shape.static StringSCALE_COMPUTATION_METHOD_KEYstatic StringSCALE_OGCVery simple and lenient scale computation method that conforms to the OGC SLD specification 1.0, page 26.protected doublescaleDenominatorThe ratio required to scale the features to be rendered so that they fit into the output space.protected static StyleFactorySTYLE_FACTORYstatic StringTEXT_RENDERING_ADAPTIVEWill use STRING mode for horizontal labels, OUTLINE mode for all other labels.static StringTEXT_RENDERING_KEYThe text rendering method, either TEXT_RENDERING_OUTLINE or TEXT_RENDERING_STRINGstatic StringTEXT_RENDERING_OUTLINEText will be rendered using the associatedGlyphVectoroutline, that is, aShape.static StringTEXT_RENDERING_STRINGText will be rendered using the usual calls gc.drawString/drawGlyphVector.static StringVECTOR_RENDERING_KEYBoolean flag indicating whether vector rendering should be preferred when painting graphic fills.
-
Constructor Summary
Constructors Constructor Description StreamingRenderer()Creates a new instance of LiteRenderer without a context.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddRenderListener(RenderListener listener)adds a listener that responds to error events of feature rendered events.protected voidfillBackground(Graphics2D graphics, Rectangle paintArea, Style style)booleangetConcatTransforms()Flag which controls behaviour for applying affine transformation to the graphics object.doublegetGeneralizationDistance()Returns the generalization distance in the screen space.RenderingHintsgetJava2DHints()Hints used to configure Java2D Graphics prior to rendering.MapContentgetMapContent()Gets theMapContentinstance which contains the data being rendered.static MathTransformgetMathTransform(CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem destCRS)intgetMaxBackBufferMemory(int width, int height)When drawing in optimized mode a 32bit surface is created for each FeatureTypeStyle other than the first in order to draw features in parallel while respecting the feature draw ordering multiple FTS impose.Map<Object,Object>getRendererHints()Hints used to configure rendering processprotected BlockingQueue<StreamingRenderer.RenderingRequest>getRequestsQueue()Builds the blocking queue used to bridge between the data loading thread and the painting onebooleanisCanTransform()booleanisInteractive()Getter for property interactive.voidpaint(Graphics2D graphics, Rectangle paintArea, AffineTransform worldToScreen)Renders features based on the map layers and their styles as specified in the map context usingsetContext.voidpaint(Graphics2D graphics, Rectangle paintArea, ReferencedEnvelope mapArea)Renders features based on the map layers and their styles as specified in the map context usingsetContext.voidpaint(Graphics2D graphics, Rectangle paintArea, ReferencedEnvelope mapArea, AffineTransform worldToScreen)Renders features based on the map layers and their styles as specified in the map context usingsetContext.voidpaint(Graphics2D graphics, Rectangle paintArea, Envelope mapArea)Renders features based on the map layers and their styles as specified in the map context usingsetContext.voidpaint(Graphics2D graphics, Rectangle paintArea, Envelope mapArea, AffineTransform worldToScreen)Renders features based on the map layers and their styles as specified in the map context usingsetContext.voidremoveRenderListener(RenderListener listener)Removes a render listener.voidsetConcatTransforms(boolean flag)Sets the flag which controls behaviour for applying affine transformation to the graphics object.voidsetGeneralizationDistance(double d)Sets the generalizazion distance in the screen space.voidsetInteractive(boolean interactive)Sets the interactive status of the renderer.voidsetJava2DHints(RenderingHints hints)Hints used to configure Java2D Graphics prior to rendering.voidsetMapContent(MapContent mapContent)Sets theMapContentwhich contains the data to be rendered.voidsetRendererHints(Map<?,?> hints)Hints used to configure rendering process.voidsetThreadPool(ExecutorService threadPool)Sets a thread pool to be used in parallel renderingvoidstopRendering()If you call this method from another thread than the one that calledpaintorrenderthe rendering will be forcefully stopped before terminationprotected ReferencedEnvelopetransformEnvelope(ReferencedEnvelope envelope, CoordinateReferenceSystem crs)
-
-
-
Field Detail
-
SCALE_ACCURATE
public static final String SCALE_ACCURATE
Computes the scale as the ratio between map distances and real world distances, assuming 90dpi and taking into consideration projection deformations and actual earth shape.
Use this method only when in need of accurate computation. Will break if the data extent is outside of the currenct projection definition area.- See Also:
- Constant Field Values
-
SCALE_OGC
public static final String SCALE_OGC
Very simple and lenient scale computation method that conforms to the OGC SLD specification 1.0, page 26.
This method is quite approximative, but should never break and ensure constant scale even on lat/lon unprojected maps (because in that case scale is computed as if the area was along the equator no matter what the real position is).- See Also:
- Constant Field Values
-
RENDERING_BUFFER
public static final String RENDERING_BUFFER
The rendering buffer grows the query area to account for features that are contributing to the requested area due to their large symbolizer, or long label- See Also:
- Constant Field Values
-
filterFactory
protected static final FilterFactory filterFactory
Filter factory for creating bounding box filters
-
STYLE_FACTORY
protected static final StyleFactory STYLE_FACTORY
-
scaleDenominator
protected double scaleDenominator
The ratio required to scale the features to be rendered so that they fit into the output space.
-
labelCache
protected LabelCache labelCache
-
painter
protected StyledShapePainter painter
The painter class we use to depict shapes onto the screen
-
TEXT_RENDERING_STRING
public static final String TEXT_RENDERING_STRING
Text will be rendered using the usual calls gc.drawString/drawGlyphVector. This is a little faster, and more consistent with how the platform renders the text in other applications. The downside is that on most platform the label and its eventual halo are not properly centered.
-
TEXT_RENDERING_OUTLINE
public static final String TEXT_RENDERING_OUTLINE
Text will be rendered using the associatedGlyphVectoroutline, that is, aShape. This ensures perfect centering between the text and the halo, but introduces more text aliasing.
-
TEXT_RENDERING_ADAPTIVE
public static final String TEXT_RENDERING_ADAPTIVE
Will use STRING mode for horizontal labels, OUTLINE mode for all other labels. Works best when coupled withRenderingHints.VALUE_FRACTIONALMETRICS_ON
-
TEXT_RENDERING_KEY
public static final String TEXT_RENDERING_KEY
The text rendering method, either TEXT_RENDERING_OUTLINE or TEXT_RENDERING_STRING- See Also:
- Constant Field Values
-
LINE_WIDTH_OPTIMIZATION_KEY
public static final String LINE_WIDTH_OPTIMIZATION_KEY
Whether the thin line width optimization should be used, or not.When rendering non antialiased lines adopting a width of 0 makes the java2d renderer get into a fast path that generates the same output as a 1 pixel wide line
Unfortunately for antialiased rendering that optimization does not help, and disallows controlling the width of thin lines. It is provided as an explicit option as the optimization has been hard coded for years, removing it when antialiasing is on by default will invalidate lots of existing styles (making lines appear thicker).
- See Also:
- Constant Field Values
-
OPTIMIZE_FTS_RENDERING_KEY
public static final String OPTIMIZE_FTS_RENDERING_KEY
Boolean flag controlling a memory/speed trade off related to how multiple feature type styles are rendered.When enabled (by default) multiple feature type styles against the same data source will be rendered in separate memory back buffers in a way that allows the source to be scanned only once (each back buffer is as big as the image being rendered).
When disabled no memory back buffers will be used but the feature source will be scanned once for every feature type style declared against it
- See Also:
- Constant Field Values
-
ADVANCED_PROJECTION_HANDLING_KEY
public static final String ADVANCED_PROJECTION_HANDLING_KEY
Enables advanced reprojection handling. Geometries will be sliced to fit into the area of definition of the rendering projection.- See Also:
- Constant Field Values
-
CONTINUOUS_MAP_WRAPPING
public static final String CONTINUOUS_MAP_WRAPPING
Enabled continuous cartographic wrapping for projections that can wrap around their edges (e.g., Mercator): this results in a continous horizontal map much like Google Maps- See Also:
- Constant Field Values
-
VECTOR_RENDERING_KEY
public static final String VECTOR_RENDERING_KEY
Boolean flag indicating whether vector rendering should be preferred when painting graphic fills. SeeSLDStyleFactory.isVectorRenderingEnabled()for more details.- See Also:
- Constant Field Values
-
ADVANCED_PROJECTION_DENSIFICATION_KEY
public static final String ADVANCED_PROJECTION_DENSIFICATION_KEY
Boolean flag indicating whether advanced projection densification should be used when needed.- See Also:
- Constant Field Values
-
ADVANCED_PROJECTION_DENSIFICATION_TOLERANCE_KEY
public static final String ADVANCED_PROJECTION_DENSIFICATION_TOLERANCE_KEY
Densification Tolerance, to be used when densification is enabled.- See Also:
- Constant Field Values
-
DATELINE_WRAPPING_HEURISTIC_KEY
public static final String DATELINE_WRAPPING_HEURISTIC_KEY
Boolean flag indicating whether advanced projection wrapping heuristic should be used or nto.- See Also:
- Constant Field Values
-
LABEL_CACHE_KEY
public static final String LABEL_CACHE_KEY
- See Also:
- Constant Field Values
-
FORCE_EPSG_AXIS_ORDER_KEY
public static final String FORCE_EPSG_AXIS_ORDER_KEY
- See Also:
- Constant Field Values
-
DPI_KEY
public static final String DPI_KEY
- See Also:
- Constant Field Values
-
DECLARED_SCALE_DENOM_KEY
public static final String DECLARED_SCALE_DENOM_KEY
- See Also:
- Constant Field Values
-
SCALE_COMPUTATION_METHOD_KEY
public static final String SCALE_COMPUTATION_METHOD_KEY
- See Also:
- Constant Field Values
-
BYLAYER_INTERPOLATION
public static final String BYLAYER_INTERPOLATION
- See Also:
- Constant Field Values
-
-
Method Detail
-
setThreadPool
public void setThreadPool(ExecutorService threadPool)
Sets a thread pool to be used in parallel rendering
-
setConcatTransforms
public void setConcatTransforms(boolean flag)
Sets the flag which controls behaviour for applying affine transformation to the graphics object.- Parameters:
flag- If true then the transform will be concatenated to the existing transform. If false it will be replaced.
-
getConcatTransforms
public boolean getConcatTransforms()
Flag which controls behaviour for applying affine transformation to the graphics object.- Returns:
- a boolean flag. If true then the transform will be concatenated to the existing transform. If false it will be replaced.
-
addRenderListener
public void addRenderListener(RenderListener listener)
adds a listener that responds to error events of feature rendered events.- Specified by:
addRenderListenerin interfaceGTRenderer- Parameters:
listener- the listener to add.- See Also:
RenderListener
-
removeRenderListener
public void removeRenderListener(RenderListener listener)
Removes a render listener.- Specified by:
removeRenderListenerin interfaceGTRenderer- Parameters:
listener- the listener to remove.- See Also:
RenderListener
-
stopRendering
public void stopRendering()
If you call this method from another thread than the one that calledpaintorrenderthe rendering will be forcefully stopped before termination- Specified by:
stopRenderingin interfaceGTRenderer
-
paint
public void paint(Graphics2D graphics, Rectangle paintArea, AffineTransform worldToScreen)
Renders features based on the map layers and their styles as specified in the map context usingsetContext.This version of the method assumes that the size of the output area and the transformation from coordinates to pixels are known. The latter determines the map scale. The viewport (the visible part of the map) will be calculated internally.
- Specified by:
paintin interfaceGTRenderer- Parameters:
graphics- The graphics object to draw to.paintArea- The size of the output area in output units (eg: pixels).worldToScreen- A transform which converts World coordinates to Screen coordinates.- TODO:
- Need to check if the Layer CoordinateSystem is different to the BoundingBox rendering CoordinateSystem and if so, then transform the coordinates.
-
paint
public void paint(Graphics2D graphics, Rectangle paintArea, Envelope mapArea)
Renders features based on the map layers and their styles as specified in the map context usingsetContext.This version of the method assumes that the area of the visible part of the map and the size of the output area are known. The transform between the two is calculated internally.
- Specified by:
paintin interfaceGTRenderer- Parameters:
graphics- The graphics object to draw to.paintArea- The size of the output area in output units (eg: pixels).mapArea- the map's visible area (viewport) in map coordinates.
-
paint
public void paint(Graphics2D graphics, Rectangle paintArea, ReferencedEnvelope mapArea)
Renders features based on the map layers and their styles as specified in the map context usingsetContext.This version of the method assumes that the area of the visible part of the map and the size of the output area are known. The transform between the two is calculated internally.
- Specified by:
paintin interfaceGTRenderer- Parameters:
graphics- The graphics object to draw to.paintArea- The size of the output area in output units (eg: pixels).mapArea- the map's visible area (viewport) in map coordinates.
-
paint
public void paint(Graphics2D graphics, Rectangle paintArea, Envelope mapArea, AffineTransform worldToScreen)
Renders features based on the map layers and their styles as specified in the map context usingsetContext.This version of the method assumes that paint area, envelope and worldToScreen transform are already computed. Use this method to avoid recomputation. Note however that no check is performed that they are really in sync!
- Specified by:
paintin interfaceGTRenderer- Parameters:
graphics- The graphics object to draw to.paintArea- The size of the output area in output units (eg: pixels).mapArea- the map's visible area (viewport) in map coordinates.worldToScreen- A transform which converts World coordinates to Screen coordinates.
-
paint
public void paint(Graphics2D graphics, Rectangle paintArea, ReferencedEnvelope mapArea, AffineTransform worldToScreen)
Renders features based on the map layers and their styles as specified in the map context usingsetContext.This version of the method assumes that paint area, envelope and worldToScreen transform are already computed. Use this method to avoid recomputation. Note however that no check is performed that they are really in sync!
- Specified by:
paintin interfaceGTRenderer- Parameters:
graphics- The graphics object to draw to.paintArea- The size of the output area in output units (eg: pixels).mapArea- the map's visible area (viewport) in map coordinates. Its associate CRS is ALWAYS 2DworldToScreen- A transform which converts World coordinates to Screen coordinates.
-
fillBackground
protected void fillBackground(Graphics2D graphics, Rectangle paintArea, Style style)
-
getRequestsQueue
protected BlockingQueue<StreamingRenderer.RenderingRequest> getRequestsQueue()
Builds the blocking queue used to bridge between the data loading thread and the painting one
-
transformEnvelope
protected ReferencedEnvelope transformEnvelope(ReferencedEnvelope envelope, CoordinateReferenceSystem crs) throws TransformException, FactoryException
- Throws:
TransformExceptionFactoryException
-
getMaxBackBufferMemory
public int getMaxBackBufferMemory(int width, int height)When drawing in optimized mode a 32bit surface is created for each FeatureTypeStyle other than the first in order to draw features in parallel while respecting the feature draw ordering multiple FTS impose. This method allows to estimate how many megabytes will be needed, in terms of back buffers, to draw the currentMapContent, assuming the feature type style optimizations are turned on (in the case they are off, no extra memory will be used).- Parameters:
width- the image widthheight- the image height
-
isInteractive
public boolean isInteractive()
Getter for property interactive.- Returns:
- Value of property interactive.
-
setInteractive
public void setInteractive(boolean interactive)
Sets the interactive status of the renderer. An interactive renderer won't wait for long image loading, preferring an alternative mark instead- Parameters:
interactive- new value for the interactive property
-
getGeneralizationDistance
public double getGeneralizationDistance()
Returns the generalization distance in the screen space.
-
setGeneralizationDistance
public void setGeneralizationDistance(double d)
Sets the generalizazion distance in the screen space.Default value is 0.8, meaning that two subsequent points are collapsed to one if their on screen distance is less than one pixel
Set the distance to 0 if you don't want any kind of generalization
-
setJava2DHints
public void setJava2DHints(RenderingHints hints)
Description copied from interface:GTRendererHints used to configure Java2D Graphics prior to rendering.- Specified by:
setJava2DHintsin interfaceGTRenderer
-
getJava2DHints
public RenderingHints getJava2DHints()
Description copied from interface:GTRendererHints used to configure Java2D Graphics prior to rendering.- Specified by:
getJava2DHintsin interfaceGTRenderer- Returns:
- Hints
-
setRendererHints
public void setRendererHints(Map<?,?> hints)
Description copied from interface:GTRendererHints used to configure rendering process.- Specified by:
setRendererHintsin interfaceGTRenderer
-
getRendererHints
public Map<Object,Object> getRendererHints()
Description copied from interface:GTRendererHints used to configure rendering process- Specified by:
getRendererHintsin interfaceGTRenderer- Returns:
- Hints used to configure rendering process
-
setMapContent
public void setMapContent(MapContent mapContent)
Description copied from interface:GTRendererSets theMapContentwhich contains the data to be rendered.- Specified by:
setMapContentin interfaceGTRenderer- Parameters:
mapContent- the map content
-
getMapContent
public MapContent getMapContent()
Description copied from interface:GTRendererGets theMapContentinstance which contains the data being rendered.- Specified by:
getMapContentin interfaceGTRenderer- Returns:
- the
MapContentinstance
-
isCanTransform
public boolean isCanTransform()
-
getMathTransform
public static MathTransform getMathTransform(CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem destCRS)
-
-