anl.aida.gis
Class StreamingRenderer

java.lang.Object
  extended by anl.aida.gis.StreamingRenderer
All Implemented Interfaces:
org.geotools.renderer.GTRenderer

public final class StreamingRenderer
extends java.lang.Object
implements org.geotools.renderer.GTRenderer

A streaming implementation of the GTRenderer interface.

Use this class if you need a stateless renderer that provides low memory footprint and decent rendering performance on the first call but don't need good optimal performance on subsequent calls on the same data. Notice: for the time being, this class doesn't support GridCoverage stylers, that will be rendered using the non geophisics version of the GridCoverage, if available, with the geophisics one, otherwise.

At the moment the streaming renderer is not thread safe

Version:
$Id: StreamingRenderer.java 32821 2009-04-17 21:35:57Z simonegiannecchini $
Author:
James Macgill, dblasby, jessie eichar, Simone Giannecchini, Andrea Aime, Alessio Fabiani

Nested Class Summary
private  class StreamingRenderer.RenderableFeature
          A class transforming (and caching) feature's geometries to shapes
 
Field Summary
private  boolean canTransform
           
private  boolean concatTransforms
          Flag which controls behaviour for applying affine transformation to the graphics object.
private  org.geotools.map.MapContext context
          Context which contains the layers and the bounding box which needs to be rendered.
static java.lang.String DECLARED_SCALE_DENOM_KEY
           
private static org.opengis.filter.expression.PropertyName defaultGeometryPropertyName
           
private static int defaultMaxFiltersToSendToDatastore
           
private  org.opengis.referencing.crs.CoordinateReferenceSystem destinationCrs
           
static java.lang.String DPI_KEY
           
(package private)  int error
           
private static org.opengis.filter.FilterFactory filterFactory
          Filter factory for creating bounding box filters
static java.lang.String FORCE_CRS_KEY
           
private  double generalizationDistance
          Maximum displacement for generalization during rendering
private static org.opengis.filter.expression.PropertyName gridPropertyName
           
private  org.geotools.renderer.lite.IndexedFeatureResults indexedFeatureResults
           
private  boolean inMemoryGeneralization
          Whether the renderer must perform generalization for the current set of features.
private  boolean interactive
          Flag which determines if the renderer is interactive or not.
private  java.awt.RenderingHints java2dHints
           
static java.lang.String LABEL_CACHE_KEY
           
protected  org.geotools.renderer.lite.LabelCache labelCache
           
static java.lang.String LINE_WIDTH_OPTIMIZATION_KEY
          Whether the thin line width optimization should be used, or not.
private static java.util.logging.Logger LOGGER
          The logger for the rendering module.
private  org.geotools.geometry.jts.ReferencedEnvelope mapExtent
          Geographic map extent, eventually expanded to consider buffer area around the map
static java.lang.String MEMORY_PRE_LOADING_KEY
           
private  boolean memoryPreloadingEnabledDEFAULT
           
private static org.geotools.geometry.jts.Decimator NULL_DECIMATOR
          A decimator that will just transform coordinates
static java.lang.String OPTIMIZE_FTS_RENDERING_KEY
          Boolean flag controlling a memory/speed trade off related to how multiple feature type styles are rendered.
static java.lang.String OPTIMIZED_DATA_LOADING_KEY
           
private  boolean optimizedDataLoadingEnabledDEFAULT
           
private  org.geotools.geometry.jts.ReferencedEnvelope originalMapExtent
          Geographic map extent, as provided by the caller
private  org.geotools.renderer.lite.StyledShapePainter painter
          The painter class we use to depict shapes onto the screen
private static org.opengis.filter.expression.PropertyName paramsPropertyName
           
private  java.util.Map rendererHints
          "optimizedDataLoadingEnabled" - Boolean yes/no (see default optimizedDataLoadingEnabledDEFAULT) "memoryPreloadingEnabled" - Boolean yes/no (see default memoryPreloadingEnabledDEFAULT) "declaredScaleDenominator" - Double the value of the scale denominator to use by the renderer.
private  int renderingBufferDEFAULT
           
private  boolean renderingStopRequested
          This flag is set to false when starting rendering, and will be checked during the rendering loop in order to make it stop forcefully
private  org.geotools.renderer.lite.ListenerList renderListeners
           
static java.lang.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.
static java.lang.String SCALE_COMPUTATION_METHOD_KEY
           
static java.lang.String SCALE_OGC
          Very simple and lenient scale computation method that conforms to the OGC SLD specification 1.0, page 26.
private  java.lang.String scaleComputationMethodDEFAULT
           
private  double scaleDenominator
          The ratio required to scale the features to be rendered so that they fit into the output space.
private  java.awt.Rectangle screenSize
          The size of the output area in output units.
private  org.geotools.renderer.style.SLDStyleFactory styleFactory
          Factory that will resolve symbolizers into rendered styles
static java.lang.String TEXT_RENDERING_KEY
          The text rendering method, either TEXT_RENDERING_OUTLINE or TEXT_RENDERING_STRING
static java.lang.String TEXT_RENDERING_OUTLINE
          Text will be rendered using the associated GlyphVector outline, that is, a Shape.
static java.lang.String TEXT_RENDERING_STRING
          Text will be rendered using the usual calls gc.drawString/drawGlyphVector.
private  java.lang.String textRenderingModeDEFAULT
           
private static double TOLERANCE
          Tolerance used to compare doubles for equality
private  java.awt.geom.AffineTransform worldToScreenTransform
           
 
Constructor Summary
StreamingRenderer()
          Creates a new instance of LiteRenderer without a context.
 
Method Summary
 void addRenderListener(org.geotools.renderer.RenderListener listener)
          adds a listener that responds to error events of feature rendered events.
private  org.opengis.referencing.operation.MathTransform2D buildFullTransform(org.opengis.referencing.crs.CoordinateReferenceSystem sourceCRS, org.opengis.referencing.crs.CoordinateReferenceSystem destCRS, java.awt.geom.AffineTransform worldToScreenTransform)
          Builds a full transform going from the source CRS to the denstionan CRS and from there to the screen
private  double computeScale(org.geotools.geometry.jts.ReferencedEnvelope envelope, java.awt.Rectangle paintArea, java.util.Map hints)
           
private  org.opengis.filter.Filter createBBoxFilters(org.opengis.feature.simple.SimpleFeatureType schema, java.lang.String[] attributes, com.vividsolutions.jts.geom.Envelope bbox)
          Creates the bounding box filters (one for each geometric attribute) needed to query a MapLayer's feature source to return just the features for the target rendering extent
private  java.util.ArrayList createLiteFeatureTypeStyles(org.geotools.styling.FeatureTypeStyle[] featureStyles, java.lang.Object typeDescription, java.awt.Graphics2D graphics)
          Creates a list of LiteFeatureTypeStyles with:
    out-of-scale rules removed incompatible FeatureTypeStyles removed
private  java.util.ArrayList createLiteFeatureTypeStyles(org.geotools.styling.FeatureTypeStyle[] featureStyles, org.opengis.feature.simple.SimpleFeatureType ftype, java.awt.Graphics2D graphics)
          creates a list of LiteFeatureTypeStyles a) out-of-scale rules removed b) incompatible FeatureTypeStyles removed
private  void drawOptimized(java.awt.Graphics2D graphics, org.geotools.map.MapLayer currLayer, java.awt.geom.AffineTransform at, org.opengis.referencing.crs.CoordinateReferenceSystem destinationCrs, java.lang.String layerId, java.util.Collection collection, org.geotools.feature.FeatureCollection features, org.geotools.util.NumberRange scaleRange, java.util.ArrayList lfts)
          Performs rendering so that the collection is scanned only once even in presence of multiple feature type styles, using the in memory buffer for each feature type style other than the first one (that uses the graphics provided by the user)s
private  void drawPlain(java.awt.Graphics2D graphics, org.geotools.map.MapLayer currLayer, java.awt.geom.AffineTransform at, org.opengis.referencing.crs.CoordinateReferenceSystem destinationCrs, java.lang.String layerId, java.util.Collection collection, org.geotools.feature.FeatureCollection features, org.geotools.util.NumberRange scaleRange, java.util.ArrayList lfts)
          Performs all rendering on the user provided graphics object by scanning the collection multiple times, one for each feature type style provided
private  com.vividsolutions.jts.geom.Envelope expandEnvelope(com.vividsolutions.jts.geom.Envelope envelope, java.awt.geom.AffineTransform worldToScreen, int buffer)
          Extends the provided Envelope in order to add the number of pixels specified by buffer in every direction.
private  com.vividsolutions.jts.geom.Geometry findGeometry(java.lang.Object drawMe, org.geotools.styling.Symbolizer s)
          Finds the geometric attribute requested by the symbolizer
private  org.opengis.referencing.crs.CoordinateReferenceSystem findGeometryCS(org.geotools.map.MapLayer currLayer, java.lang.Object drawMe, org.geotools.styling.Symbolizer s)
          Finds the geometric attribute coordinate reference system.
private  int findRenderingBuffer(org.geotools.renderer.lite.LiteFeatureTypeStyle[] styles)
          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.
private  java.lang.String[] findStyleAttributes(org.geotools.renderer.lite.LiteFeatureTypeStyle[] styles, org.opengis.feature.simple.SimpleFeatureType schema)
          Inspects the MapLayer's style and retrieves it's needed attribute names, returning at least the default geometry attribute name.
private  void fireErrorEvent(java.lang.Exception e)
           
private  void fireFeatureRenderedEvent(java.lang.Object feature)
           
 boolean getConcatTransforms()
          Flag which controls behaviour for applying affine transformation to the graphics object.
 org.geotools.map.MapContext getContext()
           
 double getGeneralizationDistance()
          Returns the generalization distance in the screen space.
private  org.opengis.filter.expression.PropertyName getGeometryPropertyName(org.geotools.styling.Symbolizer s)
           
 java.awt.RenderingHints getJava2DHints()
           
static org.opengis.referencing.operation.MathTransform getMathTransform(org.opengis.referencing.crs.CoordinateReferenceSystem sourceCRS, org.opengis.referencing.crs.CoordinateReferenceSystem destCRS)
           
private  int getMaxFiltersToSendToDatastore()
          find out the maximum number of filters we're going to send off to the datastore.
private  org.opengis.referencing.crs.CoordinateReferenceSystem getNativeCRS(org.opengis.feature.simple.SimpleFeatureType schema, java.util.List<java.lang.String> attNames)
          Scans the schema for the specified attributes are returns a single CRS if all the geometric attributes in the lot share one CRS, null if there are different ones
 java.util.Map getRendererHints()
           
private  int getRenderingBuffer()
           Returns the rendering buffer, a measure in pixels used to expand the geometry search area enough to capture the geometries that do stay outside of the current rendering bounds but do affect them because of their large strokes (labels and graphic symbols are handled differently, see the label chache).
private  java.lang.String getScaleComputationMethod()
           Returns scale computation algorithm to be used.
private  java.lang.String getTextRenderingMethod()
          Returns the text rendering method
 boolean isCanTransform()
           
 boolean isInteractive()
          Getter for property interactive.
private  boolean isMemoryPreloadingEnabled()
          Deprecated. this method shall be killed, its of no use
private  boolean isOptimizedDataLoadingEnabled()
           Returns true if the optimized data loading is enabled, false otherwise.
private  boolean isOptimizedFTSRenderingEnabled()
          Checks if optimized feature type style rendering is enabled, or not.
private  boolean isWithInScale(org.geotools.styling.Rule r)
          Checks if a rule can be triggered at the current scale level
 void paint(java.awt.Graphics2D graphics, java.awt.Rectangle paintArea, java.awt.geom.AffineTransform worldToScreen)
          Deprecated. Use paint(Graphics2D graphics, Rectangle paintArea, ReferencedEnvelope mapArea) or paint(Graphics2D graphics, Rectangle paintArea, ReferencedEnvelope mapArea, AffineTransform worldToScreen) instead.
 void paint(java.awt.Graphics2D graphics, java.awt.Rectangle paintArea, com.vividsolutions.jts.geom.Envelope mapArea)
          Deprecated. Use paint(Graphics2D graphics, Rectangle paintArea, ReferencedEnvelope mapArea) or paint(Graphics2D graphics, Rectangle paintArea, ReferencedEnvelope mapArea, AffineTransform worldToScreen) instead.
 void paint(java.awt.Graphics2D graphics, java.awt.Rectangle paintArea, com.vividsolutions.jts.geom.Envelope mapArea, java.awt.geom.AffineTransform worldToScreen)
          Deprecated. Use paint(Graphics2D graphics, Rectangle paintArea, ReferencedEnvelope mapArea) or paint(Graphics2D graphics, Rectangle paintArea, ReferencedEnvelope mapArea, AffineTransform worldToScreen) instead.
 void paint(java.awt.Graphics2D graphics, java.awt.Rectangle paintArea, org.geotools.geometry.jts.ReferencedEnvelope mapArea)
          Renders features based on the map layers and their styles as specified in the map context using setContext.
 void paint(java.awt.Graphics2D graphics, java.awt.Rectangle paintArea, org.geotools.geometry.jts.ReferencedEnvelope mapArea, java.awt.geom.AffineTransform worldToScreen)
          Renders features based on the map layers and their styles as specified in the map context using setContext.
private  org.geotools.feature.FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> prepFeatureCollection(org.geotools.feature.FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> features, org.opengis.referencing.crs.CoordinateReferenceSystem sourceCrs)
          Prepair a FeatureCollection for display, this method formally ensured that a FeatureReader produced the correct CRS and has now been updated to work with FeatureCollection.
private  void process(StreamingRenderer.RenderableFeature rf, org.geotools.renderer.lite.LiteFeatureTypeStyle style, org.geotools.util.NumberRange scaleRange, java.awt.geom.AffineTransform at, org.opengis.referencing.crs.CoordinateReferenceSystem destinationCrs, java.lang.String layerId)
           
private  void processRuleForQuery(org.geotools.renderer.lite.LiteFeatureTypeStyle[] styles, org.geotools.data.DefaultQuery q)
          JE: If there is a single rule "and" its filter together with the query's filter and send it off to datastore.
private  void processStylers(java.awt.Graphics2D graphics, org.geotools.map.MapLayer currLayer, java.awt.geom.AffineTransform at, org.opengis.referencing.crs.CoordinateReferenceSystem destinationCrs, com.vividsolutions.jts.geom.Envelope mapArea, java.awt.Rectangle screenSize, java.lang.String layerId)
          Applies each feature type styler in turn to all of the features.
private  void processSymbolizers(java.awt.Graphics2D graphics, StreamingRenderer.RenderableFeature drawMe, org.geotools.styling.Symbolizer[] symbolizers, org.geotools.util.NumberRange scaleRange, java.awt.geom.AffineTransform at, org.opengis.referencing.crs.CoordinateReferenceSystem destinationCrs, java.lang.String layerId)
          Applies each of a set of symbolizers in turn to a given feature.
(package private)  java.util.Collection queryLayer(org.geotools.map.MapLayer currLayer, org.geotools.data.memory.CollectionSource source)
          Queries a given layer's Source instance to be rendered.
(package private)  org.geotools.feature.FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> queryLayer(org.geotools.map.MapLayer currLayer, org.geotools.data.FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> source, org.opengis.feature.simple.SimpleFeatureType schema, org.geotools.renderer.lite.LiteFeatureTypeStyle[] styles, com.vividsolutions.jts.geom.Envelope mapArea, org.opengis.referencing.crs.CoordinateReferenceSystem mapCRS, org.opengis.referencing.crs.CoordinateReferenceSystem featCrs, java.awt.Rectangle screenSize, org.opengis.feature.type.GeometryDescriptor geometryAttribute, java.awt.geom.AffineTransform worldToScreenTransform)
          Queries a given layer's features to be rendered based on the target rendering bounding box.
 void removeRenderListener(org.geotools.renderer.RenderListener listener)
          Removes a render listener.
private  void renderRaster(java.awt.Graphics2D graphics, java.lang.Object drawMe, org.geotools.styling.RasterSymbolizer symbolizer, org.opengis.referencing.crs.CoordinateReferenceSystem destinationCRS, org.geotools.util.Range scaleRange)
          Renders a grid coverage on the device.
 void setConcatTransforms(boolean flag)
          Sets the flag which controls behaviour for applying affine transformation to the graphics object.
 void setContext(org.geotools.map.MapContext context)
           
 void setGeneralizationDistance(double d)
           Sets the generalizazion distance in the screen space.
 void setInteractive(boolean interactive)
          Sets the interactive status of the renderer.
 void setJava2DHints(java.awt.RenderingHints hints)
           
 void setRendererHints(java.util.Map hints)
           
 void stopRendering()
          If you call this method from another thread than the one that called paint or render the rendering will be forcefully stopped before termination
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultMaxFiltersToSendToDatastore

private static final int defaultMaxFiltersToSendToDatastore
See Also:
Constant Field Values

SCALE_ACCURATE

public static final java.lang.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 java.lang.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

TOLERANCE

private static final double TOLERANCE
Tolerance used to compare doubles for equality

See Also:
Constant Field Values

LOGGER

private static final java.util.logging.Logger LOGGER
The logger for the rendering module.


error

int error

filterFactory

private static final org.opengis.filter.FilterFactory filterFactory
Filter factory for creating bounding box filters


gridPropertyName

private static final org.opengis.filter.expression.PropertyName gridPropertyName

paramsPropertyName

private static final org.opengis.filter.expression.PropertyName paramsPropertyName

defaultGeometryPropertyName

private static final org.opengis.filter.expression.PropertyName defaultGeometryPropertyName

context

private org.geotools.map.MapContext context
Context which contains the layers and the bounding box which needs to be rendered.


interactive

private boolean interactive
Flag which determines if the renderer is interactive or not. An interactive renderer will return rather than waiting for time consuming operations to complete (e.g. Image Loading). A non-interactive renderer (e.g. a SVG or PDF renderer) will block for these operations.


concatTransforms

private boolean concatTransforms
Flag which controls behaviour for applying affine transformation to the graphics object. If true then the transform will be concatenated to the existing transform. If false it will be replaced.


mapExtent

private org.geotools.geometry.jts.ReferencedEnvelope mapExtent
Geographic map extent, eventually expanded to consider buffer area around the map


originalMapExtent

private org.geotools.geometry.jts.ReferencedEnvelope originalMapExtent
Geographic map extent, as provided by the caller


screenSize

private java.awt.Rectangle screenSize
The size of the output area in output units.


renderingStopRequested

private boolean renderingStopRequested
This flag is set to false when starting rendering, and will be checked during the rendering loop in order to make it stop forcefully


scaleDenominator

private double scaleDenominator
The ratio required to scale the features to be rendered so that they fit into the output space.


generalizationDistance

private double generalizationDistance
Maximum displacement for generalization during rendering


styleFactory

private org.geotools.renderer.style.SLDStyleFactory styleFactory
Factory that will resolve symbolizers into rendered styles


labelCache

protected org.geotools.renderer.lite.LabelCache labelCache

painter

private org.geotools.renderer.lite.StyledShapePainter painter
The painter class we use to depict shapes onto the screen


indexedFeatureResults

private org.geotools.renderer.lite.IndexedFeatureResults indexedFeatureResults

renderListeners

private org.geotools.renderer.lite.ListenerList renderListeners

java2dHints

private java.awt.RenderingHints java2dHints

optimizedDataLoadingEnabledDEFAULT

private boolean optimizedDataLoadingEnabledDEFAULT

memoryPreloadingEnabledDEFAULT

private boolean memoryPreloadingEnabledDEFAULT

renderingBufferDEFAULT

private int renderingBufferDEFAULT

scaleComputationMethodDEFAULT

private java.lang.String scaleComputationMethodDEFAULT

TEXT_RENDERING_STRING

public static final java.lang.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.

See Also:
Constant Field Values

TEXT_RENDERING_OUTLINE

public static final java.lang.String TEXT_RENDERING_OUTLINE
Text will be rendered using the associated GlyphVector outline, that is, a Shape. This ensures perfect centering between the text and the halo, but introduces more text aliasing.

See Also:
Constant Field Values

TEXT_RENDERING_KEY

public static final java.lang.String TEXT_RENDERING_KEY
The text rendering method, either TEXT_RENDERING_OUTLINE or TEXT_RENDERING_STRING

See Also:
Constant Field Values

textRenderingModeDEFAULT

private java.lang.String textRenderingModeDEFAULT

LINE_WIDTH_OPTIMIZATION_KEY

public static final java.lang.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 java.lang.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

LABEL_CACHE_KEY

public static final java.lang.String LABEL_CACHE_KEY
See Also:
Constant Field Values

FORCE_CRS_KEY

public static final java.lang.String FORCE_CRS_KEY
See Also:
Constant Field Values

DPI_KEY

public static final java.lang.String DPI_KEY
See Also:
Constant Field Values

DECLARED_SCALE_DENOM_KEY

public static final java.lang.String DECLARED_SCALE_DENOM_KEY
See Also:
Constant Field Values

MEMORY_PRE_LOADING_KEY

public static final java.lang.String MEMORY_PRE_LOADING_KEY
See Also:
Constant Field Values

OPTIMIZED_DATA_LOADING_KEY

public static final java.lang.String OPTIMIZED_DATA_LOADING_KEY
See Also:
Constant Field Values

SCALE_COMPUTATION_METHOD_KEY

public static final java.lang.String SCALE_COMPUTATION_METHOD_KEY
See Also:
Constant Field Values

rendererHints

private java.util.Map rendererHints
"optimizedDataLoadingEnabled" - Boolean yes/no (see default optimizedDataLoadingEnabledDEFAULT) "memoryPreloadingEnabled" - Boolean yes/no (see default memoryPreloadingEnabledDEFAULT) "declaredScaleDenominator" - Double the value of the scale denominator to use by the renderer. by default the value is calculated based on the screen size and the displayed area of the map. "dpi" - Integer number of dots per inch of the display 90 DPI is the default (as declared by OGC) "forceCRS" - CoordinateReferenceSystem declares to the renderer that all layers are of the CRS declared in this hint "labelCache" - Declares the label cache that will be used by the renderer.


worldToScreenTransform

private java.awt.geom.AffineTransform worldToScreenTransform

destinationCrs

private org.opengis.referencing.crs.CoordinateReferenceSystem destinationCrs

canTransform

private boolean canTransform

inMemoryGeneralization

private boolean inMemoryGeneralization
Whether the renderer must perform generalization for the current set of features. For each layer we will set this flag depending on whether the datastore can do full generalization for us, or not


NULL_DECIMATOR

private static final org.geotools.geometry.jts.Decimator NULL_DECIMATOR
A decimator that will just transform coordinates

Constructor Detail

StreamingRenderer

public StreamingRenderer()
Creates a new instance of LiteRenderer without a context. Use it only to gain access to utility methods of this class or if you want to render random feature collections instead of using the map context interface

Method Detail

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(org.geotools.renderer.RenderListener listener)
adds a listener that responds to error events of feature rendered events.

Specified by:
addRenderListener in interface org.geotools.renderer.GTRenderer
Parameters:
listener - the listener to add.
See Also:
RenderListener

removeRenderListener

public void removeRenderListener(org.geotools.renderer.RenderListener listener)
Removes a render listener.

Specified by:
removeRenderListener in interface org.geotools.renderer.GTRenderer
Parameters:
listener - the listener to remove.
See Also:
RenderListener

fireFeatureRenderedEvent

private void fireFeatureRenderedEvent(java.lang.Object feature)

fireErrorEvent

private void fireErrorEvent(java.lang.Exception e)

stopRendering

public void stopRendering()
If you call this method from another thread than the one that called paint or render the rendering will be forcefully stopped before termination

Specified by:
stopRendering in interface org.geotools.renderer.GTRenderer

paint

public void paint(java.awt.Graphics2D graphics,
                  java.awt.Rectangle paintArea,
                  java.awt.geom.AffineTransform worldToScreen)
Deprecated. Use paint(Graphics2D graphics, Rectangle paintArea, ReferencedEnvelope mapArea) or paint(Graphics2D graphics, Rectangle paintArea, ReferencedEnvelope mapArea, AffineTransform worldToScreen) instead.

Renders features based on the map layers and their styles as specified in the map context using setContext.

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:
paint in interface org.geotools.renderer.GTRenderer
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.

paint

public void paint(java.awt.Graphics2D graphics,
                  java.awt.Rectangle paintArea,
                  com.vividsolutions.jts.geom.Envelope mapArea)
Deprecated. Use paint(Graphics2D graphics, Rectangle paintArea, ReferencedEnvelope mapArea) or paint(Graphics2D graphics, Rectangle paintArea, ReferencedEnvelope mapArea, AffineTransform worldToScreen) instead.

Renders features based on the map layers and their styles as specified in the map context using setContext.

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:
paint in interface org.geotools.renderer.GTRenderer
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(java.awt.Graphics2D graphics,
                  java.awt.Rectangle paintArea,
                  org.geotools.geometry.jts.ReferencedEnvelope mapArea)
Renders features based on the map layers and their styles as specified in the map context using setContext.

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:
paint in interface org.geotools.renderer.GTRenderer
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(java.awt.Graphics2D graphics,
                  java.awt.Rectangle paintArea,
                  com.vividsolutions.jts.geom.Envelope mapArea,
                  java.awt.geom.AffineTransform worldToScreen)
Deprecated. Use paint(Graphics2D graphics, Rectangle paintArea, ReferencedEnvelope mapArea) or paint(Graphics2D graphics, Rectangle paintArea, ReferencedEnvelope mapArea, AffineTransform worldToScreen) instead.

Renders features based on the map layers and their styles as specified in the map context using setContext.

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:
paint in interface org.geotools.renderer.GTRenderer
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.

computeScale

private double computeScale(org.geotools.geometry.jts.ReferencedEnvelope envelope,
                            java.awt.Rectangle paintArea,
                            java.util.Map hints)

paint

public void paint(java.awt.Graphics2D graphics,
                  java.awt.Rectangle paintArea,
                  org.geotools.geometry.jts.ReferencedEnvelope mapArea,
                  java.awt.geom.AffineTransform worldToScreen)
Renders features based on the map layers and their styles as specified in the map context using setContext.

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:
paint in interface org.geotools.renderer.GTRenderer
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 2D
worldToScreen - A transform which converts World coordinates to Screen coordinates.

expandEnvelope

private com.vividsolutions.jts.geom.Envelope expandEnvelope(com.vividsolutions.jts.geom.Envelope envelope,
                                                            java.awt.geom.AffineTransform worldToScreen,
                                                            int buffer)
Extends the provided Envelope in order to add the number of pixels specified by buffer in every direction.

Parameters:
envelope - to extend.
worldToScreen - by means of which doing the extension.
buffer - to use for the extension.
Returns:
an extended version of the provided Envelope.

queryLayer

java.util.Collection queryLayer(org.geotools.map.MapLayer currLayer,
                                org.geotools.data.memory.CollectionSource source)
Queries a given layer's Source instance to be rendered.

Note: This is proof-of-concept quality only! At the moment the query is not filtered, that means all objects with all fields are read from the datastore for every call to this method. This method should work like #queryLayer(MapLayer, FeatureSource, SimpleFeatureType, LiteFeatureTypeStyle[], Envelope, CoordinateReferenceSystem, CoordinateReferenceSystem, Rectangle, GeometryAttributeType) and eventually replace it.

Parameters:
currLayer - The actually processed layer for rendering
source - Source to read data from

queryLayer

org.geotools.feature.FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> queryLayer(org.geotools.map.MapLayer currLayer,
                                                                                                                                         org.geotools.data.FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> source,
                                                                                                                                         org.opengis.feature.simple.SimpleFeatureType schema,
                                                                                                                                         org.geotools.renderer.lite.LiteFeatureTypeStyle[] styles,
                                                                                                                                         com.vividsolutions.jts.geom.Envelope mapArea,
                                                                                                                                         org.opengis.referencing.crs.CoordinateReferenceSystem mapCRS,
                                                                                                                                         org.opengis.referencing.crs.CoordinateReferenceSystem featCrs,
                                                                                                                                         java.awt.Rectangle screenSize,
                                                                                                                                         org.opengis.feature.type.GeometryDescriptor geometryAttribute,
                                                                                                                                         java.awt.geom.AffineTransform worldToScreenTransform)
                                                                                                                                   throws org.geotools.filter.IllegalFilterException,
                                                                                                                                          java.io.IOException,
                                                                                                                                          org.geotools.feature.IllegalAttributeException
Queries a given layer's features to be rendered based on the target rendering bounding box.

If optimizedDataLoadingEnabled attribute has been set to true, the following optimization will be performed in order to limit the number of features returned:

  • Just the features whose geometric attributes lies within envelope will be queried
  • The queried attributes will be limited to just those needed to perform the rendering, based on the required geometric and non geometric attributes found in the Layer's style rules
  • If a Query has been set to limit the resulting layer's features, the final filter to obtain them will respect it. This means that the bounding box filter and the Query filter will be combined, also including maxFeatures from Query
  • At least that the layer's definition query explicitly says to retrieve some attribute, no attributes will be requested from it, for performance reasons. So it is desirable to not use a Query for filtering a layer which includes attributes. Note that including the attributes in the result is not necessary for the query's filter to get properly processed.

NOTE : This is an internal method and should only be called by paint(Graphics2D, Rectangle, AffineTransform). It is package protected just to allow unit testing it.

Parameters:
currLayer - the actually processing layer for renderition
schema -
source -
envelope - the spatial extent which is the target area of the rendering process
destinationCrs - DOCUMENT ME!
sourceCrs -
screenSize -
geometryAttribute -
Returns:
the set of features resulting from currLayer after querying its feature source
Throws:
org.geotools.filter.IllegalFilterException - if something goes wrong constructing the bbox filter
java.io.IOException
org.geotools.feature.IllegalAttributeException
See Also:
MapLayer.setQuery(org.geotools.data.Query)

buildFullTransform

private org.opengis.referencing.operation.MathTransform2D buildFullTransform(org.opengis.referencing.crs.CoordinateReferenceSystem sourceCRS,
                                                                             org.opengis.referencing.crs.CoordinateReferenceSystem destCRS,
                                                                             java.awt.geom.AffineTransform worldToScreenTransform)
                                                                      throws org.opengis.referencing.FactoryException
Builds a full transform going from the source CRS to the denstionan CRS and from there to the screen

Throws:
org.opengis.referencing.FactoryException

getNativeCRS

private org.opengis.referencing.crs.CoordinateReferenceSystem getNativeCRS(org.opengis.feature.simple.SimpleFeatureType schema,
                                                                           java.util.List<java.lang.String> attNames)
Scans the schema for the specified attributes are returns a single CRS if all the geometric attributes in the lot share one CRS, null if there are different ones

Parameters:
schema -
Returns:

processRuleForQuery

private void processRuleForQuery(org.geotools.renderer.lite.LiteFeatureTypeStyle[] styles,
                                 org.geotools.data.DefaultQuery q)
JE: If there is a single rule "and" its filter together with the query's filter and send it off to datastore. This will allow as more processing to be done on the back end... Very useful if DataStore is a database. Problem is that worst case each filter is ran twice. Next we will modify it to find a "Common" filter between all rules and send that to the datastore. DJB: trying to be smarter. If there are no "elseRules" and no rules w/o a filter, then it makes sense to send them off to the Datastore We limit the number of Filters sent off to the datastore, just because it could get a bit rediculous. In general, for a database, if you can limit 10% of the rows being returned you're probably doing quite well. The main problem is when your filters really mean you're secretly asking for all the data in which case sending the filters to the Datastore actually costs you. But, databases are *much* faster at processing the Filters than JAVA is and can use statistical analysis to do it.

Parameters:
styles -
q -

getMaxFiltersToSendToDatastore

private int getMaxFiltersToSendToDatastore()
find out the maximum number of filters we're going to send off to the datastore. See processRuleForQuery() for details.


isMemoryPreloadingEnabled

private boolean isMemoryPreloadingEnabled()
Deprecated. this method shall be killed, its of no use


isOptimizedFTSRenderingEnabled

private boolean isOptimizedFTSRenderingEnabled()
Checks if optimized feature type style rendering is enabled, or not. See OPTIMIZE_FTS_RENDERING_KEY description for a full explanation.


findRenderingBuffer

private int findRenderingBuffer(org.geotools.renderer.lite.LiteFeatureTypeStyle[] styles)
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.

Parameters:
styles - the feature type styles to be applied to the layer
Returns:
an estimate of the buffer that should be used to properly display a layer rendered with the specified styles

findStyleAttributes

private java.lang.String[] findStyleAttributes(org.geotools.renderer.lite.LiteFeatureTypeStyle[] styles,
                                               org.opengis.feature.simple.SimpleFeatureType schema)
Inspects the MapLayer's style and retrieves it's needed attribute names, returning at least the default geometry attribute name.

Parameters:
layer - the MapLayer to determine the needed attributes from
schema - the layer's FeatureSource schema
Returns:
the minimum set of attribute names needed to render layer

createBBoxFilters

private org.opengis.filter.Filter createBBoxFilters(org.opengis.feature.simple.SimpleFeatureType schema,
                                                    java.lang.String[] attributes,
                                                    com.vividsolutions.jts.geom.Envelope bbox)
                                             throws org.geotools.filter.IllegalFilterException
Creates the bounding box filters (one for each geometric attribute) needed to query a MapLayer's feature source to return just the features for the target rendering extent

Parameters:
schema - the layer's feature source schema
attributes - set of needed attributes
bbox - the expression holding the target rendering bounding box
Returns:
an or'ed list of bbox filters, one for each geometric attribute in attributes. If there are just one geometric attribute, just returns its corresponding GeometryFilter.
Throws:
org.geotools.filter.IllegalFilterException - if something goes wrong creating the filter

isWithInScale

private boolean isWithInScale(org.geotools.styling.Rule r)
Checks if a rule can be triggered at the current scale level

Parameters:
r - The rule
Returns:
true if the scale is compatible with the rule settings

createLiteFeatureTypeStyles

private java.util.ArrayList createLiteFeatureTypeStyles(org.geotools.styling.FeatureTypeStyle[] featureStyles,
                                                        java.lang.Object typeDescription,
                                                        java.awt.Graphics2D graphics)
                                                 throws java.io.IOException

Creates a list of LiteFeatureTypeStyles with:

  1. out-of-scale rules removed
  2. incompatible FeatureTypeStyles removed

Note: This method has a lot of duplication with createLiteFeatureTypeStyles(FeatureTypeStyle[], SimpleFeatureType, Graphics2D).

Parameters:
featureStyles - Styles to process
typeDescription - The type description that has to be matched
Returns:
ArrayList
Throws:
java.io.IOException

createLiteFeatureTypeStyles

private java.util.ArrayList createLiteFeatureTypeStyles(org.geotools.styling.FeatureTypeStyle[] featureStyles,
                                                        org.opengis.feature.simple.SimpleFeatureType ftype,
                                                        java.awt.Graphics2D graphics)
                                                 throws java.io.IOException
creates a list of LiteFeatureTypeStyles a) out-of-scale rules removed b) incompatible FeatureTypeStyles removed

Parameters:
featureStylers -
features -
Returns:
ArrayList
Throws:
java.lang.Exception
java.io.IOException

prepFeatureCollection

private org.geotools.feature.FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> prepFeatureCollection(org.geotools.feature.FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> features,
                                                                                                                                                            org.opengis.referencing.crs.CoordinateReferenceSystem sourceCrs)
Prepair a FeatureCollection for display, this method formally ensured that a FeatureReader produced the correct CRS and has now been updated to work with FeatureCollection.

What is really going on is the need to set up for reprojection; but *after* decimation has occured.

Parameters:
features -
sourceCrs -
Returns:
FeatureCollection that produces results with the correct CRS

processStylers

private final void processStylers(java.awt.Graphics2D graphics,
                                  org.geotools.map.MapLayer currLayer,
                                  java.awt.geom.AffineTransform at,
                                  org.opengis.referencing.crs.CoordinateReferenceSystem destinationCrs,
                                  com.vividsolutions.jts.geom.Envelope mapArea,
                                  java.awt.Rectangle screenSize,
                                  java.lang.String layerId)
                           throws org.geotools.filter.IllegalFilterException,
                                  java.io.IOException,
                                  org.geotools.feature.IllegalAttributeException
Applies each feature type styler in turn to all of the features. This perhaps needs some explanation to make it absolutely clear. featureStylers[0] is applied to all features before featureStylers[1] is applied. This can have important consequences as regards the painting order.

In most cases, this is the desired effect. For example, all line features may be rendered with a fat line and then a thin line. This produces a 'cased' effect without any strange overlaps.

This method is internal and should only be called by render.

Parameters:
graphics - DOCUMENT ME!
features - An array of features to be rendered
featureStylers - An array of feature stylers to be applied
at - DOCUMENT ME!
destinationCrs - - The destination CRS, or null if no reprojection is required
screenSize -
layerId -
Throws:
java.io.IOException
org.geotools.feature.IllegalAttributeException
org.geotools.filter.IllegalFilterException

drawPlain

private void drawPlain(java.awt.Graphics2D graphics,
                       org.geotools.map.MapLayer currLayer,
                       java.awt.geom.AffineTransform at,
                       org.opengis.referencing.crs.CoordinateReferenceSystem destinationCrs,
                       java.lang.String layerId,
                       java.util.Collection collection,
                       org.geotools.feature.FeatureCollection features,
                       org.geotools.util.NumberRange scaleRange,
                       java.util.ArrayList lfts)
Performs all rendering on the user provided graphics object by scanning the collection multiple times, one for each feature type style provided


drawOptimized

private void drawOptimized(java.awt.Graphics2D graphics,
                           org.geotools.map.MapLayer currLayer,
                           java.awt.geom.AffineTransform at,
                           org.opengis.referencing.crs.CoordinateReferenceSystem destinationCrs,
                           java.lang.String layerId,
                           java.util.Collection collection,
                           org.geotools.feature.FeatureCollection features,
                           org.geotools.util.NumberRange scaleRange,
                           java.util.ArrayList lfts)
Performs rendering so that the collection is scanned only once even in presence of multiple feature type styles, using the in memory buffer for each feature type style other than the first one (that uses the graphics provided by the user)s


process

private final void process(StreamingRenderer.RenderableFeature rf,
                           org.geotools.renderer.lite.LiteFeatureTypeStyle style,
                           org.geotools.util.NumberRange scaleRange,
                           java.awt.geom.AffineTransform at,
                           org.opengis.referencing.crs.CoordinateReferenceSystem destinationCrs,
                           java.lang.String layerId)
                    throws org.opengis.referencing.operation.TransformException,
                           org.opengis.referencing.FactoryException
Parameters:
rf -
feature -
style -
layerId -
Throws:
org.opengis.referencing.operation.TransformException
org.opengis.referencing.FactoryException

processSymbolizers

private final void processSymbolizers(java.awt.Graphics2D graphics,
                                      StreamingRenderer.RenderableFeature drawMe,
                                      org.geotools.styling.Symbolizer[] symbolizers,
                                      org.geotools.util.NumberRange scaleRange,
                                      java.awt.geom.AffineTransform at,
                                      org.opengis.referencing.crs.CoordinateReferenceSystem destinationCrs,
                                      java.lang.String layerId)
                               throws org.opengis.referencing.operation.TransformException,
                                      org.opengis.referencing.FactoryException
Applies each of a set of symbolizers in turn to a given feature.

This is an internal method and should only be called by processStylers.

Parameters:
currLayer -
graphics -
drawMe - The feature to be rendered
symbolizers - An array of symbolizers which actually perform the rendering.
scaleRange - The scale range we are working on... provided in order to make the style factory happy
shape -
destinationCrs -
layerId -
Throws:
org.opengis.referencing.operation.TransformException
org.opengis.referencing.FactoryException

renderRaster

private void renderRaster(java.awt.Graphics2D graphics,
                          java.lang.Object drawMe,
                          org.geotools.styling.RasterSymbolizer symbolizer,
                          org.opengis.referencing.crs.CoordinateReferenceSystem destinationCRS,
                          org.geotools.util.Range scaleRange)
Renders a grid coverage on the device.

Parameters:
graphics - DOCUMENT ME!
drawMe - the feature that contains the GridCoverage. The grid coverage must be contained in the "grid" attribute
symbolizer - The raster symbolizer
scaleRange -
world2Grid -

findGeometry

private com.vividsolutions.jts.geom.Geometry findGeometry(java.lang.Object drawMe,
                                                          org.geotools.styling.Symbolizer s)
Finds the geometric attribute requested by the symbolizer

Parameters:
drawMe - The feature
s - /** Finds the geometric attribute requested by the symbolizer
drawMe - The feature
s - The symbolizer
Returns:
The geometry requested in the symbolizer, or the default geometry if none is specified

findGeometryCS

private org.opengis.referencing.crs.CoordinateReferenceSystem findGeometryCS(org.geotools.map.MapLayer currLayer,
                                                                             java.lang.Object drawMe,
                                                                             org.geotools.styling.Symbolizer s)
Finds the geometric attribute coordinate reference system.

Parameters:
drawMe2 -
f - The feature
s - The symbolizer
Returns:
The geometry requested in the symbolizer, or the default geometry if none is specified

getGeometryPropertyName

private org.opengis.filter.expression.PropertyName getGeometryPropertyName(org.geotools.styling.Symbolizer s)

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

isOptimizedDataLoadingEnabled

private boolean isOptimizedDataLoadingEnabled()

Returns true if the optimized data loading is enabled, false otherwise.

When optimized data loading is enabled, lite renderer will try to load only the needed feature attributes (according to styles) and to load only the features that are in (or overlaps with)the bounding box requested for painting


getRenderingBuffer

private int getRenderingBuffer()

Returns the rendering buffer, a measure in pixels used to expand the geometry search area enough to capture the geometries that do stay outside of the current rendering bounds but do affect them because of their large strokes (labels and graphic symbols are handled differently, see the label chache).


getScaleComputationMethod

private java.lang.String getScaleComputationMethod()

Returns scale computation algorithm to be used.


getTextRenderingMethod

private java.lang.String getTextRenderingMethod()
Returns the text rendering method


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

Parameters:
d -

setJava2DHints

public void setJava2DHints(java.awt.RenderingHints hints)
Specified by:
setJava2DHints in interface org.geotools.renderer.GTRenderer

getJava2DHints

public java.awt.RenderingHints getJava2DHints()
Specified by:
getJava2DHints in interface org.geotools.renderer.GTRenderer

setRendererHints

public void setRendererHints(java.util.Map hints)
Specified by:
setRendererHints in interface org.geotools.renderer.GTRenderer

getRendererHints

public java.util.Map getRendererHints()
Specified by:
getRendererHints in interface org.geotools.renderer.GTRenderer

setContext

public void setContext(org.geotools.map.MapContext context)
Specified by:
setContext in interface org.geotools.renderer.GTRenderer

getContext

public org.geotools.map.MapContext getContext()
Specified by:
getContext in interface org.geotools.renderer.GTRenderer

isCanTransform

public boolean isCanTransform()

getMathTransform

public static org.opengis.referencing.operation.MathTransform getMathTransform(org.opengis.referencing.crs.CoordinateReferenceSystem sourceCRS,
                                                                               org.opengis.referencing.crs.CoordinateReferenceSystem destCRS)