private void readBandRasterDataSubSampling( Band sourceBand, int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, int sourceStepX, int sourceStepY, ProductData destBuffer, int destWidth, ProgressMonitor pm) throws IOException { final int sourceMinY = sourceOffsetY; final int sourceMaxY = sourceOffsetY + sourceHeight - 1; ProductData lineBuffer = ProductData.createInstance(destBuffer.getType(), sourceWidth); int destPos = 0; try { pm.beginTask("Reading sub sampled raster data...", 2 * (sourceMaxY - sourceMinY)); for (int sourceY = sourceMinY; sourceY <= sourceMaxY; sourceY += sourceStepY) { sourceBand.readRasterData( sourceOffsetX, sourceY, sourceWidth, 1, lineBuffer, SubProgressMonitor.create(pm, 1)); if (sourceStepX == 1) { copyData(lineBuffer, 0, destBuffer, destPos, destWidth); } else { copyLine(lineBuffer, 0, sourceWidth, sourceStepX, destBuffer, destPos); } pm.worked(1); destPos += destWidth; } } finally { pm.done(); } }
public DataNode(String name, ProductData data, boolean readOnly) { super(name); Guardian.assertNotNull("data", data); this.dataType = data.getType(); this.numElems = data.getNumElems(); this.data = data; this.readOnly = readOnly; }
/** * Checks if the data that should be used to access the data is compatible with the data this node * can hold. * * @param data the data to be checked for compatibility * @throws IllegalArgumentException if data is invalid. */ protected void checkDataCompatibility(ProductData data) throws IllegalArgumentException { Debug.assertNotNull(data); if (data.getType() != getDataType()) { throw new IllegalArgumentException( "illegal data for data node '" + getName() + "', type " + ProductData.getTypeString(getDataType()) + " expected"); } if (data.getNumElems() != getNumDataElems()) { throw new IllegalArgumentException( "illegal number of data elements for data node '" + getName() + "', " + getNumDataElems() + " elements expected"); } }
/** {@inheritDoc} */ public void writeBandRasterData( Band sourceBand, int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, ProductData sourceBuffer, ProgressMonitor pm) throws IOException { checkBufferSize(sourceWidth, sourceHeight, sourceBuffer); final int sourceBandWidth = sourceBand.getSceneRasterWidth(); final int sourceBandHeight = sourceBand.getSceneRasterHeight(); checkSourceRegionInsideBandRegion( sourceWidth, sourceBandWidth, sourceHeight, sourceBandHeight, sourceOffsetX, sourceOffsetY); int memTypeID = -1; int memSpaceID = -1; pm.beginTask("Writing band '" + sourceBand.getName() + "'...", 1); try { final int datasetID = getOrCreateBandH5D(sourceBand); final int fileSpaceID = H5.H5Dget_space(datasetID); final long[] memDims = new long[] {sourceHeight, sourceWidth}; final long[] memStart = new long[2]; final long[] memCount = new long[2]; final long[] fileStart = new long[2]; final long[] fileCount = new long[2]; memTypeID = createH5TypeID(sourceBuffer.getType()); memSpaceID = H5.H5Screate_simple(2, memDims, null); memStart[0] = 0; memStart[1] = 0; memCount[0] = sourceHeight; memCount[1] = sourceWidth; H5.H5Sselect_hyperslab( memSpaceID, HDF5Constants.H5S_SELECT_SET, memStart, null, memCount, null); fileStart[0] = sourceOffsetY; fileStart[1] = sourceOffsetX; fileCount[0] = sourceHeight; fileCount[1] = sourceWidth; H5.H5Sselect_hyperslab( fileSpaceID, HDF5Constants.H5S_SELECT_SET, fileStart, null, fileCount, null); H5.H5Dwrite( datasetID, memTypeID, memSpaceID, fileSpaceID, HDF5Constants.H5P_DEFAULT, sourceBuffer.getElems()); pm.worked(1); } catch (IOException e) { throw e; } catch (HDF5Exception e) { throw new ProductIOException(createErrorMessage(e)); } finally { closeH5S(memSpaceID); closeH5T(memTypeID); pm.done(); } }