coverage.evaluate(coord, val);
/** * Returns a sequence of byte values for a given location (world coordinates). * * @param coord World coordinates of the location to evaluate. * @param dest An array in which to store values, or {@code null}. * @return An array containing values. * @throws CannotEvaluateException if the values can't be computed at the specified coordinate. * More specifically, {@link PointOutsideCoverageException} is thrown if the evaluation * failed because the input point has invalid coordinates. */ @Override public byte[] evaluate(final DirectPosition coord, byte[] dest) throws CannotEvaluateException { final int[] array = evaluate(coord, (int[]) null); if (dest == null) { dest = new byte[array.length]; } for (int i = 0; i < array.length; i++) { dest[i] = (byte) array[i]; } return dest; }
/** * Returns a sequence of float values for a given location (world coordinates). * * @param coord World coordinates of the location to evaluate. * @param dest An array in which to store values, or {@code null}. * @return An array containing values. * @throws CannotEvaluateException if the values can't be computed at the specified coordinate. * More specifically, {@link PointOutsideCoverageException} is thrown if the evaluation * failed because the input point has invalid coordinates. */ @Override public float[] evaluate(final DirectPosition coord, final float[] dest) throws CannotEvaluateException { return evaluate(gridGeometry.toPoint2D(coord), dest); }
/** * Returns a sequence of double values for a given location (world coordinates). * * @param coord World coordinates of the location to evaluate. * @param dest An array in which to store values, or {@code null}. * @return An array containing values. * @throws CannotEvaluateException if the values can't be computed at the specified coordinate. * More specifically, {@link PointOutsideCoverageException} is thrown if the evaluation * failed because the input point has invalid coordinates. */ @Override public double[] evaluate(final DirectPosition coord, final double[] dest) throws CannotEvaluateException { return evaluate(gridGeometry.toPoint2D(coord), dest); }
/** * Returns the value vector for a given location (world coordinates). A value for each sample * dimension is included in the vector. */ public Object evaluate(final DirectPosition point) throws CannotEvaluateException { final int dataType = image.getSampleModel().getDataType(); switch (dataType) { case DataBuffer.TYPE_BYTE: return evaluate(point, (byte[]) null); case DataBuffer.TYPE_SHORT: // Fall through case DataBuffer.TYPE_USHORT: // Fall through case DataBuffer.TYPE_INT: return evaluate(point, (int[]) null); case DataBuffer.TYPE_FLOAT: return evaluate(point, (float[]) null); case DataBuffer.TYPE_DOUBLE: return evaluate(point, (double[]) null); default: throw new CannotEvaluateException(); } }
/** * Returns a sequence of integer values for a given location (world coordinates). * * @param coord World coordinates of the location to evaluate. * @param dest An array in which to store values, or {@code null}. * @return An array containing values. * @throws CannotEvaluateException if the values can't be computed at the specified coordinate. * More specifically, {@link PointOutsideCoverageException} is thrown if the evaluation * failed because the input point has invalid coordinates. */ @Override public int[] evaluate(final DirectPosition coord, final int[] dest) throws CannotEvaluateException { return evaluate(gridGeometry.toPoint2D(coord), dest); }
/** * Returns a sequence of float values for a given two-dimensional point in the coverage. * * @param coord The coordinate point where to evaluate. * @param dest An array in which to store values, or {@code null}. * @return An array containing values. * @throws CannotEvaluateException if the values can't be computed at the specified coordinate. * More specifically, {@link PointOutsideCoverageException} is thrown if the evaluation * failed because the input point has invalid coordinates. */ @Override public float[] evaluate(final Point2D coord, float[] dest) throws CannotEvaluateException { if (fallback != null) { dest = super.evaluate(coord, dest); } try { final Point2D pixel = toGrid.transform(coord, null); final double x = pixel.getX(); final double y = pixel.getY(); if (!Double.isNaN(x) && !Double.isNaN(y)) { dest = interpolate(x, y, dest, 0, image.getNumBands()); if (dest != null) { return dest; } } } catch (TransformException exception) { throw new CannotEvaluateException(formatEvaluateError(coord, false), exception); } throw new PointOutsideCoverageException(formatEvaluateError(coord, true)); }
/** * Returns a sequence of integer values for a given two-dimensional point in the coverage. * * @param coord The coordinate point where to evaluate. * @param dest An array in which to store values, or {@code null}. * @return An array containing values. * @throws CannotEvaluateException if the values can't be computed at the specified coordinate. * More specifically, {@link PointOutsideCoverageException} is thrown if the evaluation * failed because the input point has invalid coordinates. */ @Override public int[] evaluate(final Point2D coord, int[] dest) throws CannotEvaluateException { if (fallback != null) { dest = super.evaluate(coord, dest); } try { final Point2D pixel = toGrid.transform(coord, null); final double x = pixel.getX(); final double y = pixel.getY(); if (!Double.isNaN(x) && !Double.isNaN(y)) { dest = interpolate(x, y, dest, 0, image.getNumBands()); if (dest != null) { return dest; } } } catch (TransformException exception) { throw new CannotEvaluateException(formatEvaluateError(coord, false), exception); } throw new PointOutsideCoverageException(formatEvaluateError(coord, true)); }
/** * Returns a sequence of double values for a given two-dimensional point in the coverage. * * @param coord The coordinate point where to evaluate. * @param dest An array in which to store values, or {@code null}. * @return An array containing values. * @throws CannotEvaluateException if the values can't be computed at the specified coordinate. * More specifically, {@link PointOutsideCoverageException} is thrown if the evaluation * failed because the input point has invalid coordinates. */ @Override public double[] evaluate(final Point2D coord, double[] dest) throws CannotEvaluateException { if (fallback != null) { dest = super.evaluate(coord, dest); } try { final Point2D pixel = toGrid.transform(coord, null); final double x = pixel.getX(); final double y = pixel.getY(); if (!Double.isNaN(x) && !Double.isNaN(y)) { dest = interpolate(x, y, dest, 0, image.getNumBands()); if (dest != null) { return dest; } } } catch (TransformException exception) { throw new CannotEvaluateException(formatEvaluateError(coord, false), exception); } throw new PointOutsideCoverageException(formatEvaluateError(coord, true)); }
@Override public InfoToolResult getInfo(DirectPosition2D pos) throws Exception { InfoToolResult result = new InfoToolResult(); if (isValid()) { GridCoverage2D source = ((GridCoverageLayer) getLayer()).getCoverage(); ReferencedEnvelope env = new ReferencedEnvelope(source.getEnvelope2D()); DirectPosition2D trPos = InfoToolHelperUtils.getTransformed(pos, getContentToLayerTransform()); if (env.contains(trPos)) { Object objArray = source.evaluate(trPos); Number[] bandValues = InfoToolHelperUtils.asNumberArray(objArray); if (bandValues != null) { result.newFeature("Raw values"); for (int i = 0; i < bandValues.length; i++) { result.setFeatureValue("Band " + i, bandValues[i]); } } } } return result; } }
@Override public InfoToolResult getInfo(DirectPosition2D pos) throws Exception { InfoToolResult result = new InfoToolResult(); if (isValid()) { DirectPosition trPos = InfoToolHelperUtils.getTransformed(pos, getContentToLayerTransform()); if (cachedCoverage == null || !cachedCoverage.getEnvelope2D().contains(trPos)) { if (!renewCachedCoverage(trPos)) { return result; } } try { Object objArray = cachedCoverage.evaluate(trPos); Number[] bandValues = InfoToolHelperUtils.asNumberArray(objArray); if (bandValues != null) { result.newFeature("Raw values"); for (int i = 0; i < bandValues.length; i++) { result.setFeatureValue("Band " + i, bandValues[i]); } } } catch (PointOutsideCoverageException e) { // The empty result will be returned } } return result; }
/** * Returns the value vector for a given point in the coverage. * A value for each sample dimension is included in the vector. */ public Object evaluate(final DirectPosition point) throws CannotEvaluateException { final int dataType = image.getSampleModel().getDataType(); switch (dataType) { case DataBuffer.TYPE_BYTE: return evaluate(point, (byte []) null); case DataBuffer.TYPE_SHORT: // Fall through case DataBuffer.TYPE_USHORT: // Fall through case DataBuffer.TYPE_INT: return evaluate(point, (int []) null); case DataBuffer.TYPE_FLOAT: return evaluate(point, (float []) null); case DataBuffer.TYPE_DOUBLE: return evaluate(point, (double[]) null); default: throw new CannotEvaluateException(); } }
/** * Returns the value vector for a given location (world coordinates). * A value for each sample dimension is included in the vector. */ public Object evaluate(final DirectPosition point) throws CannotEvaluateException { final int dataType = image.getSampleModel().getDataType(); switch (dataType) { case DataBuffer.TYPE_BYTE: return evaluate(point, (byte []) null); case DataBuffer.TYPE_SHORT: // Fall through case DataBuffer.TYPE_USHORT: // Fall through case DataBuffer.TYPE_INT: return evaluate(point, (int []) null); case DataBuffer.TYPE_FLOAT: return evaluate(point, (float []) null); case DataBuffer.TYPE_DOUBLE: return evaluate(point, (double[]) null); default: throw new CannotEvaluateException(); } }
/** * Returns a sequence of integer values for a given point in the coverage. * * @param coord The coordinate point where to evaluate. * @param dest An array in which to store values, or {@code null}. * @return An array containing values. * @throws CannotEvaluateException if the values can't be computed at the specified coordinate. * More specifically, {@link PointOutsideCoverageException} is thrown if the evaluation * failed because the input point has invalid coordinates. */ public int[] evaluate(final DirectPosition coord, final int[] dest) throws CannotEvaluateException { return evaluate(toPoint2D(coord), dest); }
/** * Returns a sequence of double values for a given point in the coverage. * * @param coord The coordinate point where to evaluate. * @param dest An array in which to store values, or {@code null}. * @return An array containing values. * @throws CannotEvaluateException if the values can't be computed at the specified coordinate. * More specifically, {@link PointOutsideCoverageException} is thrown if the evaluation * failed because the input point has invalid coordinates. */ public double[] evaluate(final DirectPosition coord, final double[] dest) throws CannotEvaluateException { return evaluate(toPoint2D(coord), dest); }
/** * Returns a sequence of inteeger values for a given location (world coordinates). * * @param coord World coordinates of the location to evaluate. * @param dest An array in which to store values, or {@code null}. * @return An array containing values. * @throws CannotEvaluateException if the values can't be computed at the specified coordinate. * More specifically, {@link PointOutsideCoverageException} is thrown if the evaluation * failed because the input point has invalid coordinates. */ @Override public int[] evaluate(final DirectPosition coord, final int[] dest) throws CannotEvaluateException { return evaluate(gridGeometry.toPoint2D(coord), dest); }
/** * Returns a sequence of float values for a given location (world coordinates). * * @param coord World coordinates of the location to evaluate. * @param dest An array in which to store values, or {@code null}. * @return An array containing values. * @throws CannotEvaluateException if the values can't be computed at the specified coordinate. * More specifically, {@link PointOutsideCoverageException} is thrown if the evaluation * failed because the input point has invalid coordinates. */ @Override public float[] evaluate(final DirectPosition coord, final float[] dest) throws CannotEvaluateException { return evaluate(gridGeometry.toPoint2D(coord), dest); }
/** * Returns a sequence of double values for a given location (world coordinates). * * @param coord World coordinates of the location to evaluate. * @param dest An array in which to store values, or {@code null}. * @return An array containing values. * @throws CannotEvaluateException if the values can't be computed at the specified coordinate. * More specifically, {@link PointOutsideCoverageException} is thrown if the evaluation * failed because the input point has invalid coordinates. */ @Override public double[] evaluate(final DirectPosition coord, final double[] dest) throws CannotEvaluateException { return evaluate(gridGeometry.toPoint2D(coord), dest); }
/** * Returns a sequence of float values for a given point in the coverage. * * @param coord The coordinate point where to evaluate. * @param dest An array in which to store values, or {@code null}. * @return An array containing values. * @throws CannotEvaluateException if the values can't be computed at the specified coordinate. * More specifically, {@link PointOutsideCoverageException} is thrown if the evaluation * failed because the input point has invalid coordinates. */ public float[] evaluate(final DirectPosition coord, final float[] dest) throws CannotEvaluateException { return evaluate(toPoint2D(coord), dest); }
public double getElevation(Coordinate coord) { double retVal = noData; double[] gridVals = new double[grid2D.getNumSampleDimensions()]; CoordinateReferenceSystem crs = grid2D.getCoordinateReferenceSystem(); DirectPosition gdPos = new DirectPosition2D(crs, coord.x, coord.y); try { grid2D.evaluate(gdPos, gridVals); retVal = gridVals[0]; } catch (Exception e) { retVal = noData; } return retVal; }