/** * Sets the value as a <code>double</code>. <p>The method assumes that this value is a scalar and therefore simply * calls <code>setElemDoubleAt(0)</code>. * * @param value the value to be set * * @see #setElemDoubleAt(int index, double value) */ public void setElemDouble(double value) { setElemDoubleAt(0, value); }
@Override public void eval(RasterDataEvalEnv env, int pixelIndex) { double pixelValue = term.evalD(env); if (performInvalidCheck) { if ((validMaskTerm != null && validMaskTerm.evalD(env) == 0.0) || isInvalidValue(pixelValue)) { numInvalidPixels[0]++; if (noDataValueUsed) { pixelValue = noDataValue; } } } if (scaling != null) { targetRasterData.setElemDoubleAt(pixelIndex, scaling.scaleInverse(pixelValue)); } else { targetRasterData.setElemDoubleAt(pixelIndex, pixelValue); } } }, "Performing band math...");
/** * Sets the pixel value at the given pixel coordinate to the given pixel value. * * @param x The X co-ordinate of the pixel location * @param y The Y co-ordinate of the pixel location * @param pixelValue the new pixel value * @throws NullPointerException if this band has no raster data */ @Override public void setPixelDouble(int x, int y, double pixelValue) { if (isScalingApplied()) { getRasterData().setElemDoubleAt(getRasterWidth() * y + x, scaleInverse(pixelValue)); } else { getRasterData().setElemDoubleAt(getRasterWidth() * y + x, pixelValue); } fireProductNodeDataChanged(); setModified(true); }
@Override public void setSample(int x, int y, double sample) { if (scaled) { sample = toRaw(sample); } dataBuffer.setElemDoubleAt(index(x, y), sample); }
if (isScalingApplied()) { for (int i = 0; i < n; i++) { subRasterData.setElemDoubleAt(i, scaleInverse(pixels[i])); subRasterData.setElemDoubleAt(i, pixels[i]);
final int xOffs = y * getRasterWidth(); for (x = x1; x <= x2; x++) { rasterData.setElemDoubleAt(xOffs + x, scaleInverse(pixels[pos++])); final int xOffs = y * getRasterWidth(); for (x = x1; x <= x2; x++) { rasterData.setElemDoubleAt(xOffs + x, pixels[pos++]);
@Override protected void readBandRasterDataImpl(int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, int sourceStepX, int sourceStepY, Band destBand, int destOffsetX, int destOffsetY, int destWidth, int destHeight, ProductData destBuffer, ProgressMonitor pm) throws IOException { final double[] coefficients = getCoefficients(destBand); for (int i = 0; i < destBuffer.getNumElems(); i++) { destBuffer.setElemDoubleAt(i, coefficients[0] * i + coefficients[1]); } } }
private static void fillBandWithData(Band band) { final ProductData productData = band.createCompatibleRasterData(); final int n = productData.getNumElems(); for (int i = 0; i < n; i++) { productData.setElemDoubleAt(i, i * 2.4); } band.setData(productData); } }
for (int x = 0; x < width; x++) { iSrc = (offsetY + y) * width + (offsetX + x); rasterData.setElemDoubleAt(iDest, src.getElemDoubleAt(iSrc)); iDest++;
private static ProductData createProductDataForBand(final Band band, final double start) { final ProductData data = band.createCompatibleRasterData(); for (int i = 0; i < band.getSceneRasterWidth() * band.getSceneRasterHeight(); i++) { data.setElemDoubleAt(i, start + i); } band.setData(data); return data; }
if (isScalingApplied()) { for (int i = 0; i < n; i++) { subRasterData.setElemDoubleAt(i, scaleInverse(pixels[i]));
if (isScalingApplied()) { for (int i = 0; i < n; i++) { subRasterData.setElemDoubleAt(i, scaleInverse(pixels[i]));
/** * Sets the pixel at the given pixel coordinate to the given pixel value. * * @param x The X co-ordinate of the pixel location * @param y The Y co-ordinate of the pixel location * @param pixelValue the new pixel value * @throws NullPointerException if this band has no raster data */ @Override public void setPixelFloat(int x, int y, float pixelValue) { if (isScalingApplied()) { getRasterData().setElemDoubleAt(getRasterWidth() * y + x, scaleInverse(pixelValue)); } else { getRasterData().setElemFloatAt(getRasterWidth() * y + x, pixelValue); } fireProductNodeDataChanged(); setModified(true); }
private static Band _createIntegerBand(int type, int i0, double scalingFactor) { Product product = new Product("n", "t", W, H); Band band = product.addBand("x", type); band.setScalingFactor(scalingFactor); ProductData rasterData = band.createCompatibleRasterData(); for (int i = 0; i < N; i++) { rasterData.setElemDoubleAt(i, i0 + i); } band.setRasterData(rasterData); return band; } }
/** * Sets the pixel at the given pixel co-ordinate to the given pixel value. * * @param x The X co-ordinate of the pixel location * @param y The Y co-ordinate of the pixel location * @param pixelValue the new pixel value * @throws NullPointerException if this band has no raster data */ @Override public void setPixelInt(int x, int y, int pixelValue) { if (isScalingApplied()) { getRasterData().setElemDoubleAt(getRasterWidth() * y + x, scaleInverse(pixelValue)); } else { getRasterData().setElemIntAt(getRasterWidth() * y + x, pixelValue); } fireProductNodeDataChanged(); setModified(true); }
@Override protected void computeProductData(ProductData productData, Rectangle destRect) throws IOException { final int sourceWidth = getRasterDataNode().getSceneRasterWidth(); final int sourceHeight = getRasterDataNode().getSceneRasterHeight(); final int targetWidth = destRect.width; final int targetHeight = destRect.height; final int sourceX0 = getSourceX(destRect.x); final int sourceY0 = getSourceY(destRect.y); final int[] sourceXs = getSourceCoords(sourceWidth, targetWidth); final int[] sourceYs = getSourceCoords(sourceHeight, targetHeight); int elemIndex = 0; for (int j = 0; j < targetHeight; j++) { final int sourceY = sourceY0 + sourceYs[j]; for (int i = 0; i < targetWidth; i++) { productData.setElemDoubleAt(elemIndex, computeSample(sourceX0 + sourceXs[i], sourceY)); elemIndex++; } } }
@Override public void writeBandRasterData(Band sourceBand, int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, ProductData sourceBuffer, ProgressMonitor pm) throws IOException { final String variableName = ReaderUtils.getVariableName(sourceBand); if (shallWriteVariable(variableName)) { ProductData scaledBuffer; if (convertLogScaledBands && sourceBand.isLog10Scaled()) { scaledBuffer = ProductData.createInstance(ProductData.TYPE_FLOAT32, sourceBuffer.getNumElems()); for (int i = 0; i < sourceBuffer.getNumElems(); i++) { double elemDoubleAt = sourceBuffer.getElemDoubleAt(i); scaledBuffer.setElemDoubleAt(i, sourceBand.scale(elemDoubleAt)); } } else { scaledBuffer = sourceBuffer; } synchronized (writeable) { NVariable variable = getVariable(variableName); variable.write(sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight, isYFlipped, scaledBuffer); } } }
private void testDataType(int productDataType, double v1, double v2, String validMask) { Product p = new Product("p", "t", 1, 2); Band b = p.addBand("b", productDataType); ProductData pData = ProductData.createInstance(productDataType, 2); pData.setElemDoubleAt(0, v1); pData.setElemDoubleAt(1, v2); b.setData(pData); b.setNoDataValue(v2); b.setNoDataValueUsed(true); assertTrue(b.isPixelValid(0, 0)); assertFalse(b.isPixelValid(0, 1)); assertEquals(validMask, b.getValidMaskExpression()); }
final int xOffs = y * getRasterWidth(); for (x = x1; x <= x2; x++) { rasterData.setElemDoubleAt(xOffs + x, scaleInverse(pixels[pos++]));
private static Band _createFloatingPointBand(int type, double scalingFactor, boolean dataValueUsed, double noDataValue) { Product product = new Product("n", "t", W, H); Band band = product.addBand("x", type); band.setScalingFactor(scalingFactor); band.setGeophysicalNoDataValue(noDataValue); band.setNoDataValueUsed(dataValueUsed); ProductData rasterData = band.createCompatibleRasterData(); for (int i = 0; i < N; i++) { rasterData.setElemDoubleAt(i, (i + 1) + 0.1); } band.setRasterData(rasterData); return band; }