Java GDAL environment configuration

1. Introduction

GDAL is a converter library for raster and vector geospatial data formats, released by the Open Source Geospatial Foundation under an X/MIT style open source license . As a library, it provides a single raster abstract data model and a single vector abstract data model in all supported formats for the calling application. It also comes with various useful command line utilities for data conversion and processing.

Two, placement

1. Download the compiled GDAL library https://www.gisinternals.com/release.php, or compile the source code yourself;

2. Copy all the dlls under the path \release-1911-x64-gdal-3-2-0-mapserver-7-6-1\bin to the jre directory, (the next one is C:\Program Files\Java\ jdk1.8.0_151\jre\bin);

3. Copy gdalalljni.dll under the path \release-1911-x64-gdal-3-2-0-mapserver-7-6-1\bin\gdal\java to the directory of step 2;

4. Add and reference the jar and dll under \release-1911-x64-gdal-3-2-0-mapserver-7-6-1\bin\gdal\java in the project;

5. Create a new java program to write code for debugging, and introduce gdal.

Three, the code

Copy code

import java.io.File;
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;

public class gdaltest {
  public void dog() {
    gdal.AllRegister();
    String rasterFilePath="F:\\Tilt photography\\Orthophoto\\01Visible light\\map\\result.tif";//Test file path
    Dataset dataset = gdal.Open(rasterFilePath,
      gdalconstConstants.GA_ReadOnly);
    if (dataset == null) {
      System.out.println(gdal.GetLastErrorMsg());
    }
    Driver driver = dataset.GetDriver();
    System.out.println("driver short name: " + driver.getShortName());
    System.out.println("driver long name: " + driver.getLongName());
    System.out.println("metadata list: " + driver.GetMetadata_List());

    String proj = dataset.GetProjection();
    Band band = dataset.GetRasterBand(1);
    System.out.println(proj);
    System.out.println(band);
  }
  public static void main(String[] args) {
    gdaltest test = new gdaltest();
    test.dog();
  }
}

Copy code

 

Fourth, the result

Guess you like

Origin blog.csdn.net/u014556081/article/details/113185713