GIS-Java安装GDAL

GDAL工具下载

首先下载编译好的GDAL文件,下载地址(https://www.gisinternals.com/release.php)
这里下载的是mapserver, 编译后的二进制文件

GIS-Java安装GDAL_第1张图片

配置

二进制文件文件解压,将 \bin\bin\gdal\java 目录中的 dll 文件,复制到所使用JDK版本的
%JAVA_HOME%/jre/bin/ 目录下

Maven

	<gdal.version>3.3.0gdal.version>
    <dependency>
    	<groupId>org.gdalgroupId>
        <artifactId>gdalartifactId>
       	<version>${gdal.version}version>
    dependency>

样例

GDAL Java API文档 地址

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();
    }
}

你可能感兴趣的:(地理,Java,TIF,java)