配置环境变量
找到解压后gdal目录下的proj.db文件,并增设环境变量PROJ_LIB: proj.db 所在文件夹,然后重启计算机,不然会出 ERROR 1: PROJ: createGeodeticReferenceFrame: Cannot find proj.db 异常
程序代码
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();