3

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?

2

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

0

Your configuration gdal/java binding doesn't work. If you are using Linux use the steps in https://github.com/VertNet/reproject/wiki/GDAL-Java-Bindings

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.