Package org.apache.sis.coverage.grid
Class GridEvaluator
Object
GridEvaluator
- All Implemented Interfaces:
Function<DirectPosition,,double[]> BandedCoverage.Evaluator
Computes or interpolates values of sample dimensions at given positions.
Values are computed by calls to
apply(DirectPosition) and are returned as double[].
Multi-threading
Evaluators are not thread-safe. An instance ofGridEvaluator should be created
for each thread that need to compute sample values.
Limitations
Current implementation performs nearest-neighbor sampling only. A future version will provide interpolations.- Since:
- 1.1
- See Also:
Defined in the sis-feature module
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedGridEvaluator(GridCoverage coverage) Creates a new evaluator for the given coverage. -
Method Summary
Modifier and TypeMethodDescriptiondouble[]apply(DirectPosition point) Returns a sequence of double values for a given point in the coverage.Returns the coverage from which this evaluator is fetching sample values.booleanReturns whether to returnnullinstead of throwing an exception if a point is outside coverage bounds.booleanReturnstrueif this evaluator is allowed to wraparound coordinates that are outside the grid.voidsetNullIfOutside(boolean flag) Sets whether to returnnullinstead of throwing an exception if a point is outside coverage bounds.voidsetWraparoundEnabled(boolean allow) Specifies whether this evaluator is allowed to wraparound coordinates that are outside the grid.Converts the specified geospatial position to grid coordinates.
-
Constructor Details
-
GridEvaluator
Creates a new evaluator for the given coverage. This constructor is protected for allowingGridCoveragesubclasses to provide their ownGridEvaluatorimplementations. For using an evaluator, invokeGridCoverage.evaluator()instead.- Parameters:
coverage- the coverage for which to create an evaluator.- See Also:
-
-
Method Details
-
getCoverage
Returns the coverage from which this evaluator is fetching sample values.- Specified by:
getCoveragein interfaceBandedCoverage.Evaluator- Returns:
- the source of sample values for this evaluator.
-
isWraparoundEnabled
public boolean isWraparoundEnabled()Returnstrueif this evaluator is allowed to wraparound coordinates that are outside the grid. The initial value isfalse. This method may continue to returnfalseeven after a call tosetWraparoundEnabled(true)if no wraparound axis has been found in the coverage CRS.- Returns:
trueif this evaluator may wraparound coordinates that are outside the grid.- Since:
- 1.2
-
setWraparoundEnabled
public void setWraparoundEnabled(boolean allow) Specifies whether this evaluator is allowed to wraparound coordinates that are outside the grid. Iftrueand if a given coordinate is outside the grid, then this evaluator may translate the point along a wraparound axis in an attempt to get the point inside the grid. For example if the coverage CRS has a longitude axis, then the evaluator may translate the longitude value by a multiple of 360°.- Parameters:
allow- whether to allow wraparound of coordinates that are outside the grid.- Since:
- 1.2
-
isNullIfOutside
public boolean isNullIfOutside()Returns whether to returnnullinstead of throwing an exception if a point is outside coverage bounds. The default value isfalse, which means that the defaultapply(DirectPosition)behavior is to throwPointOutsideCoverageExceptionfor points outside bounds.- Specified by:
isNullIfOutsidein interfaceBandedCoverage.Evaluator- Returns:
- whether
apply(DirectPosition)returnnullfor points outside coverage bounds.
-
setNullIfOutside
public void setNullIfOutside(boolean flag) Sets whether to returnnullinstead of throwing an exception if a point is outside coverage bounds. The default value isfalse. Setting this flag totruemay improve performances if the caller expects that many points will be outside coverage bounds, since it reduces the amount of exceptions to be created.- Specified by:
setNullIfOutsidein interfaceBandedCoverage.Evaluator- Parameters:
flag- whetherapply(DirectPosition)should usenullreturn value instead ofPointOutsideCoverageExceptionfor signaling that a point is outside coverage bounds.
-
apply
Returns a sequence of double values for a given point in the coverage. The CRS of the given point may be any coordinate reference system; coordinate conversions will be applied as needed. If the CRS of the point is undefined, then it is assumed to be the coverage CRS. The returned sequence includes a value for each sample dimension.The default interpolation type used when accessing grid values for points which fall between grid cells is nearest neighbor. This default interpolation method may change in future version.
The default implementation invokes
GridCoverage.render(GridExtent)for a small region around the point. Subclasses should override with more efficient implementation.- Specified by:
applyin interfaceBandedCoverage.Evaluator- Specified by:
applyin interfaceFunction<DirectPosition,double[]> - Parameters:
point- the coordinate point where to evaluate.- Returns:
- the sample values at the specified point, or
nullif the point is outside the coverage. For performance reason, this method may return the same array on every method call by overwriting previous values. Callers should not assume that the array content stay valid for a long time. - Throws:
PointOutsideCoverageException- if the evaluation failed because the input point has invalid coordinates and theisNullIfOutside()flag isfalse.CannotEvaluateException- if the values can not be computed at the specified coordinates for another reason. This exception may be thrown if the coverage data type can not be converted todoubleby an identity or widening conversion. Subclasses may relax this constraint if appropriate.
-
toGridCoordinates
Converts the specified geospatial position to grid coordinates. If the given position is associated to a non-null coordinate reference system (CRS) different than the coverage CRS, then this method automatically transforms that position to the coverage CRS before to compute grid coordinates.This method does not put any restriction on the grid coordinates result. The result may be outside the grid extent if the grid to CRS transform allows it.
- Parameters:
point- geospatial coordinates (in arbitrary CRS) to transform to grid coordinates.- Returns:
- the grid coordinates for the given geospatial coordinates.
- Throws:
IncompleteGridGeometryException- if the grid geometry does not define a "grid to CRS" transform, or if the given point has a non-null CRS but the coverage does not have a CRS.TransformException- if the given coordinates can not be transformed.- See Also:
-