GIS-TIF投影格式转换

配置环境变量

找到解压后gdal目录下的proj.db文件,并增设环境变量PROJ_LIB: proj.db 所在文件夹,然后重启计算机,不然会出 ERROR 1: PROJ: createGeodeticReferenceFrame: Cannot find proj.db 异常

GIS-TIF投影格式转换_第1张图片

程序代码

 	gdal.AllRegister();
   	Dataset dataset = gdal.Open(converPojectionStyle.getSouceFile());
        String projection = dataset.GetProjection();
        SpatialReference spatialReference = new SpatialReference(projection);
        String attrValue = spatialReference.GetAttrValue("AUTHORITY" , 1);

        System.out.println(attrValue);
        attrValue = "EPSG:" + attrValue;

        if (attrValue.equals(converPojectionStyle.getTargetType())) {
            return;
        }
        Vector<String> options = new Vector<>();
        options.add("t_srs EPSG:3857");
        System.out.println("进行转换");
        WarpOptions warpOptions = new WarpOptions(options);
        gdal.Warp(converPojectionStyle.getTargetFile(),new Dataset[] {dataset}, warpOptions);

        dataset.delete();
        gdal.GDALDestroyDriverManager();

你可能感兴趣的:(地理,intellij-idea)