美文网首页gdal-java
GDAL-java读取tiff文件信息

GDAL-java读取tiff文件信息

作者: WebGiser | 来源:发表于2019-06-08 15:27 被阅读0次

    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]);
            }
        }
    }
    

    相关文章

      网友评论

        本文标题:GDAL-java读取tiff文件信息

        本文链接:https://www.haomeiwen.com/subject/bjezkqtx.html