[GIS] Error in using GDAL Java binding

coordinate systemgdaljava

I am using the Java binding of GDAL to project a set of coordinate points from UTM to lat/log using the CoordinateTransformation Class of GDAL. I have written the code as follows:

SpatialReference oUTM = new SpatialReference();
SpatialReference oLatLog = new SpatialReference();

oUTM.SetProjCS("UTM 44/ WGS84");
oUTM.SetWellKnownGeogCS("WGS84");
oUTM.SetUTM(44, 1);

oLatLog = oUTM.CloneGeogCS();

double[] arr = new double[2];
arr[0]=10;
arr[1]=10;

double x = arr[0] , y = arr[1];

CoordinateTransformation transform = new CoordinateTransformation(oUTM,oLatLog);

transform.TransformPoint(arr);

System.out.println("Before:"+x+" "+y+"\nAfter:"+arr[0]+" "+arr[1]);

But when I run this in my main function, I get the following error:
Exception in thread "main" java.lang.UnsatisfiedLinkError:

org.gdal.osr.osrJNI.new_SpatialReference__SWIG_1()J
at org.gdal.osr.osrJNI.new_SpatialReference__SWIG_1(Native Method)
at org.gdal.osr.SpatialReference.<init>(SpatialReference.java:117)
at controller.CrsConverterGDAL.main(CrsConverterGDAL.java:8)

Does anyone know how this can be fixed?

Best Answer

To overcome unsatisfiedlinkerror in gdal you need to check that your program is able to read the correct gdal environment variables and .dll files. Here is a brief procedure.

Now Follow the below mentioned Setup procedure.

Download and extract the gdal zip file from its site and save in some drive preferably C drive.

Now enter the follwing data in your PC Environmental Variables.

  1. SET variable name = GDAL_DATA and variable value = C:\gdal\bin\gdal-data

  2. SET variable name = GDAL_DRIVER_PATH and variable value = C:\gdal\bin\gdal\plugins

  3. APPEND in variable name = PATH and variable value = C:\gdal\bin

  4. APPEND in variable name = PATH and variable value = C:\gdal\bin\gdal\apps

  5. Then you need to paste four .dll files i.e, gdalconstjni.dll, gdaljni.dll, ogrjni.dll and osrjni.dll from C:\gdal\bin\gdal\java to your jdk bin folder.

The 4 step is required if you want to use the gdal tools from any location in your PC.

The step 5 is specifically for java.

You need to include gdal.jar in your project classpath which you have already done.

Just ensure x86 and x64 type of java and gdal used in your program.

For more information refer to java blogs