本文整理汇总了Java中org.gdal.gdal.Band类的典型用法代码示例。如果您正苦于以下问题:Java Band类的具体用法?Java Band怎么用?Java Band使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Band类属于org.gdal.gdal包,在下文中一共展示了Band类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadWithGdal
import org.gdal.gdal.Band; //导入依赖的package包/类
public void loadWithGdal() {
//gdal.SetConfigOption("GDAL_DATA", "E:/SUMO/workspace/Sumo/trunk/GeoImageViewer/lib/gdal_libl/");
/*SpatialReference sptRef=new SpatialReference(osr.SRS_WKT_WGS84);
SpatialReference layerProjection = new SpatialReference();
SpatialReference hLatLong = new SpatialReference(osr.SRS_WKT_WGS84);*/
File f=(File)image.get("HH");
Dataset dataset=gdal.Open(f.getAbsolutePath() , gdalconstConstants.GA_ReadOnly);
Band o=(Band)dataset.GetRasterBand(1);
long flen=o.getXSize()*o.getYSize();//fss.length();
byte[] raster=new byte[(o.getXSize()*o.getYSize())];
o.ReadRaster(0,0,o.getXSize(),o.getYSize(), raster);
byte[] preloadedDataSLC=raster;
}
示例2: readPixValues
import org.gdal.gdal.Band; //导入依赖的package包/类
/**
*
* @param x
* @param y
* @param offsetx
* @param offsety
* @return
*/
public synchronized int[] readPixValues(int x,int y,int offsetx,int offsety,int type,int band){
int pixels = offsetx * offsety;
Band b=data.GetRasterBand(band);
int buf_size = pixels;
int[] dd = new int[buf_size];
try {
b.ReadRaster(x, y, offsetx, offsety,type, dd);
} catch (Exception ex2) {
try {
Thread.sleep(1000);
} catch (Exception ex) {}
b.ReadRaster(x, y, offsetx, offsety,type, dd);
}
return dd;
}
示例3: getRasterBandCount
import org.gdal.gdal.Band; //导入依赖的package包/类
/**
* Get the number of raster {@link Band}s in a Dataset.
*
* @param dataset An input {@link Dataset} containing a number of bands
* @param alphaBand An alpha {@link Band}
* @return The number of {@link Band}s in the input {@link Dataset}
*/
public static int getRasterBandCount(final Dataset dataset,
final Band alphaBand)
{
if(dataset == null)
{
throw new IllegalArgumentException("Input dataset cannot be null.");
}
if(alphaBand == null)
{
throw new IllegalArgumentException("Alpha band cannot be null.");
}
// TODO: The bitwise calc functionality needs to be verified from the python functionality
final boolean bitwiseAlpha = (alphaBand.GetMaskFlags() & gdalconstConstants.GMF_ALPHA) != 0;
return bitwiseAlpha || dataset.GetRasterCount() == 4 || dataset.GetRasterCount() == 2 ?
dataset.GetRasterCount() - 1 : dataset.GetRasterCount();
}
示例4: constructorIllegalArgumentException6
import org.gdal.gdal.Band; //导入依赖的package包/类
/**
* Tests RawImageTileReader constructor
*/
@Test(expected = IllegalArgumentException.class)
public void constructorIllegalArgumentException6() throws TileStoreException
{
gdal.AllRegister();
final Dataset dataset = gdal.GetDriverByName("MEM").Create("test", 12, 23, 1);
final Band rasterBand = dataset.GetRasterBand(1);
rasterBand.SetRasterColorTable(new ColorTable(1));
final Dimensions<Integer> tileDimensions = new Dimensions<>(256, 256);
try(final RawImageTileReader ignored = new RawImageTileReader(this.rawData, dataset, tileDimensions, null, null))
{
fail("Expected RawImageTileReader to throw an IllegalArgumentException.");
}
finally
{
dataset.delete();
}
}
示例5: main
import org.gdal.gdal.Band; //导入依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
String file="E:\\SUMO\\workspace\\Sumo\\trunk\\GeoImage\\src\\main\\java\\org\\geoimage\\utils\\egm96-15.tif";
/*GDALtest test = new GDALtest();
if (args.length >= 1)
{
BufferedImage tmpImage = test.openFile(new File(args[0]));
test.setImage(tmpImage);
}*/
/*GeoTiffReader reader;
try {
reader = new GeoTiffReader(new File(file));
GridCoverage2D result = reader.read(null);
double[] vals = new double[1];
CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326");
Object o=result.evaluate(new DirectPosition2D(sourceCRS,10,10));
//result.getRenderedImage().getData().getPixel(10, 10, pixel);
reader.dispose();
} catch (DataSourceException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (NoSuchAuthorityCodeException e) {
e.printStackTrace();
} catch (FactoryException e) {
e.printStackTrace();
}*/
Dataset d=gdal.Open(file);
Band b=d.GetRasterBand(0);
// b.readraster_
List data = d.GetMetadata_List("NGSGEOID");//"GEOLOCATION" );
System.out.println("---");
}
示例6: readImageWithGDal
import org.gdal.gdal.Band; //导入依赖的package包/类
public void readImageWithGDal(String imagePath){
File f=new File(imagePath);
Dataset dataset=gdal.Open(f.getAbsolutePath() , gdalconstConstants.GA_ReadOnly);
Band o=(Band)dataset.GetRasterBand(1);
long flen=o.getXSize()*o.getYSize();
byte[] raster=new byte[(o.getXSize()*o.getYSize())];
o.ReadRaster(0,0,o.getXSize(),o.getYSize(), raster);
byte[] preloadedDataSLC=raster;
}
示例7: ImageReader
import org.gdal.gdal.Band; //导入依赖的package包/类
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;
}
}
示例8: verifyGetRasterBandCountException1
import org.gdal.gdal.Band; //导入依赖的package包/类
/**
* Tests getRasterBandCount(Dataset, Band) throws an
* IllegalArgumentException
*/
@Test(expected = IllegalArgumentException.class)
public void verifyGetRasterBandCountException1() throws TileStoreException
{
final Dataset dataset= null;
final Band alphaBand = this.dataset1.dataset.GetRasterBand(0);
GdalUtility.getRasterBandCount(dataset, alphaBand);
fail("Expected GdalUtility method getRasterBandCount(Dataset, Band) to throw an IllegalArgumentException when the Dataset is null");
}
示例9: verifyGetRasterBandCountException2
import org.gdal.gdal.Band; //导入依赖的package包/类
/**
* Tests getRasterBandCount(Dataset, Band) throws an
* IllegalArgumentException
*/
@Test(expected = IllegalArgumentException.class)
public void verifyGetRasterBandCountException2() throws TileStoreException
{
final Dataset dataset= this.dataset1.dataset;
final Band alphaBand = null;
GdalUtility.getRasterBandCount(dataset, alphaBand);
fail("Expected GdalUtility method getRasterBandCount(Dataset, Band) to throw an IllegalArgumentException when the Band is null");
}
示例10: verifyGetRasterBandCount1
import org.gdal.gdal.Band; //导入依赖的package包/类
/**
* Tests getRasterBandCount(Dataset, Band) correctly
* returns the rasterBand count
*/
@Test
public void verifyGetRasterBandCount1() throws TileStoreException
{
final Dataset dataset = this.dataset2.dataset;
final int index = GdalUtility.getAlphaBandIndex(dataset);
final Band alphaBand = dataset.GetRasterBand(index);
final int returnedCount = GdalUtility.getRasterBandCount(dataset, alphaBand);
final int expectedCount = 3;
assertEquals("GdalUtility method getRasterBandCount(Dataset, Band) did not return the correct number of bands",
expectedCount,
returnedCount);
}
示例11: fromDataset
import org.gdal.gdal.Band; //导入依赖的package包/类
public static MrGeoRaster fromDataset(Dataset dataset, int x, int y, int width,
int height)
throws MrGeoRasterException
{
int gdaltype = dataset.GetRasterBand(1).getDataType();
int bands = dataset.GetRasterCount();
int datasize = gdal.GetDataTypeSize(gdaltype) / 8;
MrGeoRaster raster = createEmptyRaster(width, height, bands, GDALUtils.toRasterDataBufferType(gdaltype));
for (int b = 0; b < bands; b++)
{
Band band = dataset.GetRasterBand(b + 1); // gdal bands are 1's based
byte[] data = new byte[datasize * width * height];
int success = band.ReadRaster(x, y, width, height, width, height, gdaltype, data);
if (success != gdalconstConstants.CE_None)
{
String lastErr = gdal.GetLastErrorMsg();
log.warn("Failed reading raster. gdal error: " + success + ": " + lastErr + " (This may be a result of the threading problem in GDAL)");
}
//GDALUtils.swapBytes(data, gdaltype);
System.arraycopy(data, 0, raster.data, raster.calculateByteOffset(0, 0, b), data.length);
}
return raster;
}
示例12: copyToDataset
import org.gdal.gdal.Band; //导入依赖的package包/类
public void copyToDataset(Dataset ds, int dsWidth, int dsHeight, Bounds fullBounds, Bounds bounds,
int tilesize, int zoomlevel, int gdaltype) throws IOException
{
Pixel ulPixelTile = TMSUtils
.latLonToPixelsUL(bounds.n, bounds.w, zoomlevel, tilesize);
Pixel ulPixelDS = TMSUtils
.latLonToPixelsUL(fullBounds.n, fullBounds.w, zoomlevel, tilesize);
Pixel lrPixelTile = TMSUtils
.latLonToPixelsUL(bounds.s, bounds.e, zoomlevel, tilesize);
Pixel lrPixelDS = TMSUtils
.latLonToPixelsUL(fullBounds.s, fullBounds.e, zoomlevel, tilesize);
long leftPixel = Math.max(ulPixelDS.px, ulPixelTile.px);
long rightPixel = Math.min(lrPixelDS.px, lrPixelTile.px);
long topPixel = Math.max(ulPixelDS.py, ulPixelTile.py);
long bottomPixel = Math.min(lrPixelDS.py, lrPixelTile.py);
int xoffset = (ulPixelTile.px < leftPixel) ? (int) (leftPixel - ulPixelTile.px) : 0;
int yoffset = (ulPixelTile.py < topPixel) ? (int) (topPixel - ulPixelTile.py) : 0;
int xoffsetWrite = (int)(leftPixel - ulPixelDS.px);
int yoffsetWrite = (int)(topPixel - ulPixelDS.py);
int outWidth = (int) (rightPixel - leftPixel);
int outHeight = (int) (bottomPixel - topPixel);
byte[] rowdata = new byte[bytesPerPixel() * outWidth];
for (int b = 0; b < ds.GetRasterCount(); b++) {
for (int y = 0; y < outHeight; y++) {
Band band = ds.GetRasterBand(b + 1); // gdal bands are 1's based
System.arraycopy(data, calculateByteOffset(xoffset, y + yoffset, b), rowdata, 0, rowdata.length);
int success = band.WriteRaster(xoffsetWrite, y + yoffsetWrite, outWidth, 1, outWidth, 1, gdaltype, rowdata);
if (success != gdalconstConstants.CE_None) {
throw new IOException("Failed writing raster. gdal error: " + success);
}
}
}
}
示例13: toDataset
import org.gdal.gdal.Band; //导入依赖的package包/类
private Dataset toDataset(Dataset ds, int gdaltype, Bounds bounds,
int xoffset, int yoffset,
int outWidth, int outHeight,
double[] nodatas)
{
double[] xform = new double[6];
if (bounds != null)
{
xform[0] = bounds.w;
xform[1] = bounds.width() / outWidth;
xform[2] = 0;
xform[3] = bounds.n;
xform[4] = 0;
xform[5] = -bounds.height() / outHeight;
ds.SetProjection(GDALUtils.EPSG4326());
}
else
{
xform[0] = 0;
xform[1] = outWidth;
xform[2] = 0;
xform[3] = 0;
xform[4] = 0;
xform[5] = -outHeight;
}
ds.SetGeoTransform(xform);
byte[] rowdata = new byte[bytesPerPixel() * outWidth];
for (int b = 0; b < bands; b++)
{
Band band = ds.GetRasterBand(b + 1); // gdal bands are 1's based
if (nodatas != null)
{
if (b < nodatas.length)
{
band.SetNoDataValue(nodatas[b]);
}
else
{
band.SetNoDataValue(nodatas[nodatas.length - 1]);
}
}
for (int y=0; y < outHeight; y++) {
System.arraycopy(data, calculateByteOffset(xoffset, y + yoffset, b), rowdata, 0, rowdata.length);
int success = band.WriteRaster(0, y, outWidth, 1, outWidth, 1, gdaltype, rowdata);
if (success != gdalconstConstants.CE_None)
{
System.out.println("Failed writing raster. gdal error: " + success);
break;
}
}
}
return ds;
}