ReadTiff.java代码:
package Raster;
import org.gdal.gdal.Band;
import org.gdal.gdal.Dataset;
import org.gdal.gdal.Driver;
import org.gdal.gdal.gdal;
import org.gdal.gdalconst.gdalconstConstants;
public class ReadTiff {
public static void main(String[] args) {
gdal.AllRegister();
String rasterFilePath = "E:\\Test\\TestOpenLayers\\data\\GF1_PMS2_E121.7_N39.9_20170609_L1A0002429674_Fusion.tiff";
Dataset dataset = gdal.Open(rasterFilePath,
gdalconstConstants.GA_ReadOnly);
if (dataset == null) {
System.out.println("GDAL read error: " + gdal.GetLastErrorMsg());
}
Driver driver = dataset.GetDriver();
System.out.println("driver short name: " + driver.getShortName());
System.out.println("driver long name: " + driver.getLongName());
System.out.println("metadata list: " + driver.GetMetadata_List());
int xsize = dataset.getRasterXSize();
int ysize = dataset.getRasterYSize();
int count = dataset.getRasterCount();
String proj = dataset.GetProjection();
Band band = dataset.GetRasterBand(1);
// 左上角点坐标 lon lat: transform[0]、transform[3]
// 像素分辨率 x、y方向 : transform[1]、transform[5]
// 旋转角度: transform[2]、transform[4])
double[] transform = dataset.GetGeoTransform();
for(int i=0; i<transform.length; i++){
System.out.println("transform: " + transform[i]);
}
}
}
网友评论