org.geotools.swing.tool
Class GridLayerHelper

Object
  extended by InfoToolHelper<List<Number>>
      extended by GridLayerHelper

public class GridLayerHelper
extends InfoToolHelper<List<Number>>

Helper class used by InfoTool to query MapLayers with raster feature data (GridCoverage2D or AbstractGridCoverage2DReader).

Since:
2.6
Author:
Michael Bedward
See Also:
InfoTool, VectorLayerHelper
Module:

Field Summary
protected  WeakReference<GridCoverage2D> covRef
           
 
Constructor Summary
GridLayerHelper(MapContext context, MapLayer layer)
          Create a new helper to work with the given raster data source.
 
Method Summary
 List<Number> getInfo(DirectPosition2D pos, Object... params)
          Get band values at the given position
 boolean isValid()
          Query if this helper has a reference to a MapContext and MapLayer.
 
Methods inherited from class InfoToolHelper
getMapContext, getTransform, isTransformRequired, setCRS
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

covRef

protected final WeakReference<GridCoverage2D> covRef
Constructor Detail

GridLayerHelper

public GridLayerHelper(MapContext context,
                       MapLayer layer)
Create a new helper to work with the given raster data source.

Parameters:
context - the MapContext associated with this helper
rasterSource - an instance of either GridCoverage2D or {@code AbstractGridCoverage2DReader
Method Detail

getInfo

public List<Number> getInfo(DirectPosition2D pos,
                            Object... params)
                     throws Exception
Get band values at the given position

Specified by:
getInfo in class InfoToolHelper<List<Number>>
Parameters:
pos - the location to query
params - not used at present
Returns:
a List of band values; will be empty if pos was outside the coverage bounds
Throws:
Exception - if the grid coverage could not be queried
See Also:
InfoToolHelper.isValid()

isValid

public boolean isValid()
Query if this helper has a reference to a MapContext and MapLayer.

Helpers only hold a WeakReference to the map context and layer with which they are working to avoid blocking garbage collection when layers are discarded. If this method returns false the helper should be re-created.


 //
 // Example using a VectorLayerHelper...
 //
 VectorLayerHelper helper = ...

 if (helper != null && helper.isValid()) {
     FeatureCollection coll = helper.getInfo(queryLocation, ...);
     // do something useful with results

 } else {
     // (Re-)create the helper
     // Note: example only; this obviously depends on your use case
     helper = new VectorLayerHelper(context, layer);
 }
 

Specified by:
isValid in class InfoToolHelper<List<Number>>
Returns:


Copyright © 1996-2010 Geotools. All Rights Reserved.