java使用gdal创建金字塔

package com.by;

import org.gdal.gdal.Dataset;
import org.gdal.gdal.ProgressCallback;
import org.gdal.gdal.gdal;
import org.gdal.gdalconst.gdalconstConstants;
import org.junit.platform.commons.util.StringUtils;

/**
 * @Author:zcx
 * @DATE:2022/11/14 13:19
 * @Description:
 * @Version 1.0
 */
public class JZT {
    private static final String FILE_PATH_1 = "E:\\jinzita\\polygon3.tif";
    public static void main(String[] args) {
        buildOverview(FILE_PATH_1);
    }
    private static void buildOverview(String file){
        gdal.AllRegister();
        Dataset dataset = gdal.Open(file, gdalconstConstants.GA_ReadOnly);
        //调用构建金字塔接口
        dataset.BuildOverviews("nearest",new int[]{2,4,6,8,16},new buildOverViewCallBack());
    }

    //进度回调
    static class buildOverViewCallBack extends ProgressCallback {
        @Override
        public int run(double dfComplete, String pszMessage) {
            if (StringUtils.isNotBlank(pszMessage)){
                System.out.println(pszMessage);
            }
            System.out.printf("%.2f%n",dfComplete*100);
            return 1;
        }
    }

}

 

posted @ 2022-11-14 14:58  一份人间烟火  阅读(503)  评论(0编辑  收藏  举报