[GIS] GDAL Java bindings GDAL 2.0.0 in Eclipse

gdaljava

Does anyone know a quick way to use GDAL Java Bindings in Java Eclipse?

It should be GDAL > 2.0.0 in order to support KEA datatypes. GDAL-Java from OSGEO4W seems to be obsolete.

I am working on Windows 10 on a 64Bit processor and Eclipse Mars.

Best Answer

Setting up GDAL for Java IDE (in Windows) requires the following two steps:

Setting GDAL in system/server using the following steps.

  • You can download the executable GDAL packages (stable releases) from GIS internals. Choose compiler (Microsoft Visual C) & architecture (32bit or 64bit) depending upon your PC and download the compiled binaries zip file (not the Compiled libraries and headers).

  • Extract the zip file and save in some drive preferably C drive.

  • Now create/append the following data in your PC Environmental Variables (Computer --> Properties -->Advance System Settings -->Environment variables):

    CREATE/APPEND        VARIABLE                   VALUE                              REQUIREMENT

       CREATE                         GDAL_DATA                  C:\gdal\bin\gdal-data          MANDATORY        CREATE                         GDAL_DRIVER_PATH  C:\gdal\bin\gdal\plugins      MANDATORY        APPEND                         PATH                             C:\gdal\bin                           MANDATORY        APPEND                         PATH                             C:\gdal\bin\gdal\apps          OPTIONAL

  • The last append option is required if you want to use the gdal tools from any location in your PC.
  • Now you test the GDAL tools. Open Command prompt in your PC and type gdalinfo --formats. This command will list out the typr of raster formats it supports. Alternatively ogrinfo --formats will display vector formats.

Setting GDAL for project in Netbeans/Eclipse IDE.

  • Copy and paste following four/one dll file(s) from C:\gdal\bin\gdal\java to your jdk bin folder.

    gdalconstjni.dll
    gdaljni.dll
    ogrjni.dll
    osrjni.dll
    

    OR

    gdalalljni.dll (in higher versions of gdal v2.3.0 and above)    
    
  • You need to add gdal.jar file (from C:\gdal\bin\gdal\java) in the JAVA BUILD PATH Library location.

  • Now your java project will work with GDAL. Just ensure the GDAL package and JDK architecture (x86/x64).

Note: If you forget to do this you get an exception while executing your code as Exception in thread "main" java.lang.UnsatisfiedLinkError.

Note: For more information on gdal java projects, visit GeoSpatial Blogs