Interface BandedCoverage.Evaluator
- All Superinterfaces:
Function<DirectPosition, double[]>
- All Known Subinterfaces:
GridCoverage.Evaluator
- Enclosing class:
BandedCoverage
apply(DirectPosition) and are returned as double[].
Multi-threading
Evaluators are not thread-safe. An instance ofEvaluator should be created
for each thread that need to compute sample values.- Since:
- 1.1
- See Also:
-
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 computing 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 coverage.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 coverage.default Stream<double[]> stream(Collection<? extends DirectPosition> points, boolean parallel) Returns a stream of sample values for each point of the given collection.
-
Method Details
-
getCoverage
BandedCoverage getCoverage()Returns the coverage from which this evaluator is computing sample values. This is usually the instance on which theBandedCoverage.evaluator()method has been invoked, but not necessarily. Evaluators are allowed to fetch values from a different source for better performances or accuracies.Example
If the values of the enclosing coverage are interpolated from the values of another coverage, then this evaluator may use directly the values of the latter coverage. Doing so avoid to add more interpolations on values that are already interpolated.- Returns:
- the source of sample values for this evaluator.
-
isNullIfOutside
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.- Returns:
- whether
apply(DirectPosition)returnnullfor points outside coverage bounds.
-
setNullIfOutside
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 number of exceptions to be thrown.- Parameters:
flag- whetherapply(DirectPosition)should usenullreturn value instead ofPointOutsideCoverageExceptionfor signaling that a point is outside coverage bounds.
-
isWraparoundEnabled
boolean isWraparoundEnabled()Returnstrueif this evaluator is allowed to wraparound coordinates that are outside the coverage. 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, or if automatic wraparound is not supported.- Returns:
trueif this evaluator may wraparound coordinates that are outside the coverage.- Since:
- 1.3
-
setWraparoundEnabled
void setWraparoundEnabled(boolean allow) Specifies whether this evaluator is allowed to wraparound coordinates that are outside the coverage. Iftrueand if a given coordinate is outside the coverage, then this evaluator may translate the point along a wraparound axis in an attempt to get the point inside the coverage. 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 coverage.- Since:
- 1.3
-
apply
Returns a sequence of double values for a given point in the coverage. If the CRS of the point is undefined (i.e.,null), then it is assumed to be the CRS of the coverage. If the CRS of the point is defined but different than the coverage CRS, then coordinate conversions or transformations will be applied automatically by this method.The returned sequence includes a value for each sample dimension. For performance reason, this method may return the same array on every method call by overwriting previous values. Therefore, callers can assume that the array content is stable only until the next call to an
Evaluatormethod or traversal of more elements in the stream.- Specified by:
applyin interfaceFunction<DirectPosition, double[]>- Parameters:
point- the position where to evaluate.- Returns:
- the sample values at the specified point, or
nullif the point is outside the coverage. This is not guaranteed to be a new array on each method call. - Throws:
PointOutsideCoverageException- if the evaluation failed because the input point has invalid coordinates and theisNullIfOutside()flag isfalse.CannotEvaluateException- if the values cannot be computed at the specified coordinates for another reason. For example, this exception may be thrown if the coverage data type cannot be converted todoubleby an identity or widening conversion.
-
stream
Returns a stream of sample values for each point of the given collection. The values in the returned stream are traversed in the iteration order of the given collection. The returned stream behave as ifapply(DirectPosition)was invoked for each point.This method is equivalent to
points.stream().map(this::apply), but potentially more efficient. Therefore, the notes documented inapply(DirectPosition)apply also to each elements traversed by the stream: the CRS of each point is handled as documented inapply(DirectPosition), consumers should not assume that the content of thedouble[]arrays are stable after execution of the consumer body, and some elements provided by the stream may benullif a point is outside the coverage and theisNullIfOutside()flag istrue.Parallel streams
WhileEvaluatoris not thread-safe, parallel streams may be supported provided that the state of thisEvaluatoris not modified during stream execution. A parallel stream can be requested by invoking this method with theparallelargument set totrue. TheBaseStream.parallel()method should not by invoked.Implementations may ignore the
parallelargument if they do not support parallel streams. It is more difficult for implementations to ignore a call toBaseStream.parallel(), which is whyparallel()should not be invoked on streams returned by this method.Exceptions
CannotEvaluateExceptionmay be thrown either when this method is invoked, or later during the traversal, at implementation choice.- Parameters:
points- the positions where to evaluate.parallel-truefor a parallel stream, orfalsefor a sequential stream.- Returns:
- a sequential or parallel stream of sample values at the specified positions.
- Since:
- 1.6
-