org.geotools.swt.tool
Class InfoToolHelper<T>

Object
  extended by InfoToolHelper<T>
Direct Known Subclasses:
GridLayerHelper, VectorLayerHelper

public abstract class InfoToolHelper<T>
extends Object

Abstract base class for helper classes used by InfoTool to query MapLayers.

The primary reason for having this class is to avoid loading grid coverage classes unless they are really needed, and thus avoid the need for users to have JAI in the classpath when working with vector data.

The type parameter <T> defines the return type of the getInfo(org.geotools.geometry.DirectPosition2D, java.lang.Object...) method.

Since:
2.6
Author:
Michael Bedward
See Also:
InfoTool

Constructor Summary
protected InfoToolHelper(MapContent content, CoordinateReferenceSystem dataCRS)
          Protected constructor.
 
Method Summary
abstract  T getInfo(DirectPosition2D pos, Object... params)
          Get feature data at the given position.
 MapContent getMapContent()
          Get the MapContent associated with this helper.
 MathTransform getTransform()
          Get the MathTransform to reproject data from the coordinate system of the MapContext's to that of the MapLayer.
protected  boolean isTransformRequired()
          Check if queries with this helper involve transforming between coordinate systems.
abstract  boolean isValid()
          Query if this helper has a reference to a MapContext and MapLayer.
protected  void setCRS(CoordinateReferenceSystem crs)
          Set the coordinate reference system that pertains to the feature data that will be queried by this helper.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InfoToolHelper

protected InfoToolHelper(MapContent content,
                         CoordinateReferenceSystem dataCRS)
Protected constructor.

Parameters:
content - the map context
dataCRS - the coordinate reference system of the feature data that will be queried by this helper
Method Detail

getInfo

public abstract T getInfo(DirectPosition2D pos,
                          Object... params)
                   throws Exception
Get feature data at the given position.

Parameters:
pos - the location to query
params - additional parameters as optionally defined by the sub-class
Returns:
data of type T as defined by the sub-class
Throws:
Exception
See Also:
isValid()

isValid

public abstract 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);
 }
 

Returns:

getMapContent

public MapContent getMapContent()
Get the MapContent associated with this helper. The helper maintains only a WeakReference to the context.

Returns:
the map context or null if it is no longer current.

isTransformRequired

protected boolean isTransformRequired()
Check if queries with this helper involve transforming between coordinate systems.

Returns:
true if coordinte transformation is required; false otherwise

getTransform

public MathTransform getTransform()
Get the MathTransform to reproject data from the coordinate system of the MapContext's to that of the MapLayer.

Returns:
the transform or null if either the layer's coordinate system is the same as that of the map context, or either has a null CRS.

setCRS

protected void setCRS(CoordinateReferenceSystem crs)
Set the coordinate reference system that pertains to the feature data that will be queried by this helper.

Parameters:
crs - data coordinate reference system


Copyright © 1996-2014 Geotools. All Rights Reserved.