//裁切
    @Test
public void m2(){
    String srcFile="E:\\jinzita\\caiqie\\polygon11.tif";//原始数据
    String dstFile="E:\\jinzita\\caiqie\\clip2.tif";//裁切生成数据
    String shpFile="E:\\jinzita\\caiqie\\geojsonshp\\fhfh_3.shp";//shp文件
    String shpLayerName="fhfh_3";//shp文件名字
    gdal.AllRegister();
    // 读取要切的原图
    Dataset srcDs = gdal.Open(srcFile, gdalconstConstants.GA_ReadOnly);
    if (srcDs == null) {
        System.err.println("GDALOpen failed - " + gdal.GetLastErrorNo());
        System.err.println(gdal.GetLastErrorMsg());
        return;
    }
    // 构建warp参数
    Vector options = new Vector();
    options.add("-of");
    options.add("GTiff");
    options.add("-cutline");//按照矢量图像线裁剪
    options.add(shpFile);
    options.add("-cl");
    options.add(shpLayerName);
    options.add("-crop_to_cutline"); //裁剪后图层范围使用矢量图层大小
    options.add("-dstnodata");
    options.add("-10001.0"); //nulldata的值
    WarpOptions wo = new WarpOptions(options);
    Dataset warp = gdal.Warp(dstFile, new Dataset[]{srcDs}, wo,new buildOverViewCallBack());
    // 获取切图的原点坐标信息
    double[] warpTransform = warp.GetGeoTransform();
    System.out.println("warp原点坐标   = " + warpTransform[0] + "," + warpTransform[3]);
    System.out.println("warp像素坐标差 = " + warpTransform[1] + "," + warpTransform[5]);
    srcDs.delete();
}
    //进度回调
    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;
        }
    }

原文地址:http://www.cnblogs.com/zcxxcvbn/p/16898603.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性