@Override public List<Band> bands() throws IOException { int nbands = dataset.GetRasterCount(); List<Band> bands = new ArrayList<Band>(nbands); for (int i = 1; i <= nbands; i++) { bands.add(new GDALBand(dataset.GetRasterBand(i))); } return bands; }
private byte[][] readRegion( Dataset dataset, int regionMinX, int regionMinY, int regionPixelsX, int regionPixelsY, int targetWidth, int targetHeight, int numBands ) throws IOException { byte[][] bands = new byte[numBands][targetWidth * targetHeight]; if ( targetWidth * targetHeight > 0 ) { for ( int i = 0; i < numBands; i++ ) { Band band = dataset.GetRasterBand( i + 1 ); byte[] bandBytes = bands[i]; if ( band.ReadRaster( regionMinX, regionMinY, regionPixelsX, regionPixelsY, targetWidth, targetHeight, GDT_Byte, bandBytes, 0, 0 ) != CE_None ) { LOG.error( "GDAL ReadRaster failed: " + regionMinX + "," + regionMinY + "," + regionPixelsX + "," + regionPixelsY + "," + targetWidth + "," + targetHeight + "," + bandBytes.length + "," + datasetPixelsX + "," + datasetPixelsY ); return bands; } } } return bands; }
private byte[][] readBands( Dataset dataset ) { int numBands = dataset.getRasterCount(); byte[][] bands = new byte[numBands][width * height]; for ( int i = 0; i < numBands; i++ ) { Band band = dataset.GetRasterBand( i + 1 ); byte[] bandBytes = bands[i]; band.ReadRaster( 0, 0, width, height, width, height, GDT_Byte, bandBytes, 0, 0 ); } return bands; }
private ImageReader(Path inputFile, int bandIndex, int offsetX, int offsetY, int dataBufferType, int level) { this.dataBufferType = dataBufferType; this.level = level; this.offsetX = offsetX; this.offsetY = offsetY; this.gdalDataset = gdal.Open(inputFile.toString(), gdalconst.GA_ReadOnly); // bands are not 0-base indexed, so we must add 1 Band rasterBand = gdalDataset.GetRasterBand(bandIndex + 1); if (level > 0 && rasterBand.GetOverviewCount() > 0) { this.band = rasterBand.GetOverview(this.level - 1); } else { this.band = rasterBand; } }
public Dataset extractRegionAsDataset( Envelope region, int pixelsX, int pixelsY, boolean withAlpha ) throws IOException { byte[][] buffer = extractRegionAsByteArray( region, pixelsX, pixelsY, withAlpha ); Driver vrtDriver = gdal.GetDriverByName( "MEM" ); Dataset ds = vrtDriver.Create( "/tmp/whatever", pixelsX, pixelsY, buffer.length ); ds.SetProjection( dataset.GetProjection() ); int i = 1; for ( byte[] bytes : buffer ) { Band band = ds.GetRasterBand( i ); if ( band.WriteRaster( 0, 0, pixelsX, pixelsY, pixelsX, pixelsY, GDT_Byte, bytes ) != CE_None ) { throw new RuntimeException( "Error writing raster band." ); } i++; } return ds; }
private Dataset createMemDataset( Envelope nativeBbox, String nativeProjection, byte[][] composedRegion ) { Driver vrtDriver = gdal.GetDriverByName( "MEM" ); Dataset dataset = vrtDriver.Create( "/tmp/whatever", width, height, composedRegion.length ); dataset.SetProjection( nativeProjection ); dataset.SetGeoTransform( getGeoTransform( nativeBbox, width, height ) ); for ( int i = 1; i <= dataset.getRasterCount(); i++ ) { Band band = dataset.GetRasterBand( i ); if ( band.WriteRaster( 0, 0, width, height, width, height, GDT_Byte, composedRegion[i - 1] ) != CE_None ) { throw new RuntimeException( "Error writing composed raster." ); } } return dataset; }
pBand = dataset.GetRasterBand(1); rBand = dataset.GetRasterBand(k + 1); returnVal = rBand.ReadRaster( srcRegionXOffset, srcRegionYOffset, srcRegionWidth,
WritableRaster raster = Raster.createWritableRaster( sampleModel, imgBuffer, null ); if ( numberOfBands == 1 ) { Band band = dataset.GetRasterBand( 1 ); int bufType = band.getDataType(); int dataType = detectDataType( band, bufType );
pBand = dataset.GetRasterBand(1); rBand = dataset.GetRasterBand(k + 1); returnVal = rBand.ReadRaster( srcRegionXOffset, srcRegionYOffset, srcRegionWidth,
try { SpatialMetadata envelopeAndCrs = getEnvelopeAndCrs( gdalDataset, cfg.getStorageCRS() ); Band band = gdalDataset.GetRasterBand( 1 ); Band overview = band; int overviewCount = band.GetOverviewCount();
final Band band = dataset.GetRasterBand(bandIndex + 1); try { Band overviewBand;
final Band band = dataset.GetRasterBand(i + 1); final int colorInterpretation = imageMetadata .getColorInterpretations(i);
final Band band = dataset.GetRasterBand(i + 1); final int colorInterpretation = imageMetadata .getColorInterpretations(i);
org.gdal.gdal.Band gdalBand = gdalDataset.GetRasterBand(bandIndex + 1); int gdalDataType = gdalBand.getDataType(); BufferTypeDescriptor dataBufferType = bufferTypes.get(gdalDataType); logger.fine("Optimizing read by building image pyramids"); if (gdalconst.CE_Failure != gdalDataset.BuildOverviews("NEAREST", new int[] { 2, 4, 8, 16 })) { gdalBand = gdalDataset.GetRasterBand(bandIndex + 1); } else { logger.fine("Multiple levels not supported");
if (gdalBand == null) { int bandIndex = sourceProduct.getBandIndex(sourceBand.getName()); gdalBand = this.gdalDataset.GetRasterBand(bandIndex + 1); if (gdalBand == null) { throw new NullPointerException("Failed creating the band with index " + bandIndex + " to export the product for driver '" + this.gdalDriver.getLongName() + "'.");
rband = dataset.GetRasterBand(1); rband.GetBlockSize(xBlockSize, yBlockSize); pBand = dataset.GetRasterBand(band + 1); buf_type = pBand.getDataType(); banks[band] = band;
rband = dataset.GetRasterBand(1); rband.GetBlockSize(xBlockSize, yBlockSize); pBand = dataset.GetRasterBand(band + 1); buf_type = pBand.getDataType(); banks[band] = band;
dataset.GetRasterBand(i + 1).WriteRaster_Direct(xOff, yOff, dstWidth, dstHeight, dstWidth, dstHeight, dataType, bandsBuffer[i]);
dataset.GetRasterBand(i + 1).WriteRaster_Direct(xOff, yOff, dstWidth, dstHeight, dstWidth, dstHeight, dataType, bandsBuffer[i]);
setImageResource(imageResource); final Dataset dataset = getDataset(); final Band band = dataset.GetRasterBand(1); for (int i = 0; i < band.GetOverviewCount(); i++) { final Band overview = band.GetOverview(i);