GDAL工具下载
首先下载编译好的GDAL文件,下载地址(https://www.gisinternals.com/release.php)
这里下载的是mapserver, 编译后的二进制文件
配置
二进制文件文件解压,将 \bin 和 \bin\gdal\java 目录中的 dll 文件,复制到所使用JDK版本的
%JAVA_HOME%/jre/bin/ 目录下
Maven
<gdal.version>3.3.0</gdal.version>
<dependency>
<groupId>org.gdal</groupId>
<artifactId>gdal</artifactId>
<version>${gdal.version}</version>
</dependency>
样例
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;
/**
* @author doubily
* @createTime 2021/9/29 16:37
* @description
*/
public class RasterGdalTest {
private static final String FILE_PATH = "E:\\data\\tif\\org\\a_crp_medi.tif";
static {
gdal.AllRegister();
}
public static void main(String[] args) {
// 读取影像数据
Dataset dataset = gdal.Open(FILE_PATH, gdalconstConstants.GA_ReadOnly);
if (dataset == null) {
System.out.println("read fail!");
return;
}
// providing various methods for a format specific driver.
Driver driver = dataset.GetDriver();
System.out.println("driver name : " + driver.getLongName());
// 读取影像信息
int xSize = dataset.getRasterXSize();
int ySzie = dataset.getRasterYSize();
int rasterCount = dataset.getRasterCount();
System.out.println("dataset xSize:" + xSize + ", ySzie = " + ySzie + ", rasterCount = " + rasterCount);
Band band = dataset.GetRasterBand(1);
//the data type of the band.
int type = band.GetRasterDataType();
System.out.println("data type = " + type + ", " + (type == gdalconstConstants.GDT_Byte));
//Frees the native resource associated to a Dataset object and close the file.
dataset.delete();
gdal.GDALDestroyDriverManager();
}
}