1

I would like to use gdal_polygonize and gdalinfo in java. This site says: "Note that OSGeo4W includes a gdal-java package and a Java runtime making it fairly easily to build local Java applications using GDAL." But how?

2

You can see the source code for a gdalinfo java implementation here - https://svn.osgeo.org/gdal/trunk/gdal/swig/java/apps/gdalinfo.java

The polygonize function should be available in the java bindings, you may look at the source of gdal_polygonize.py to see how it's used - http://svn.osgeo.org/gdal/trunk/gdal/swig/python/scripts/gdal_polygonize.py

  • thanks that looks promising. I included gdal-1.10.1.jar and created gdalinfo.java. I also configured eclipse according to this site but there is an error when i try to run it: Native library load failed. java.lang.UnsatisfiedLinkError: no gdaljni in java.library.path Exception in thread "main" java.lang.UnsatisfiedLinkError: org.gdal.gdal.gdalJNI.AllRegister()V – Selphiron Jan 29 '15 at 11:30
  • 1
    Have you set the appropriate environment variables? Add the dir containing the gdal dlls to PATH. You may also need to set GDAL_DATA, GEOTIFF_CSV, GDAL_DRIVER_PATH and PROJ_LIB env vars. – user2856 Jan 29 '15 at 22:05
  • Ok so you mean I have to put them in the environment variables in sytem properties and not eclipse right? "...dir containing the gdal dlls to PATH" wich dlls? I have some in gdal/swig/java (like gdaljni.dll and ogrjni.dll) and some in OSGeo4W64\bin\gdalplugins (like gdal_GEOR.dll). Tried both and still got the same error. For GDAL_DATA I have OSGeo4W64\share\gdal and for GDAL_DRIVER_PATH OSGeo4W64\bin\gdalplugins ..The gdal.jar file I included into the build path of my eclipse-project is the bin\gdal\java of a download from this site. – Selphiron Jan 29 '15 at 23:35
  • 1
    Java needs to be able to find the native binaries, not just the jar. Here are some linux instructions, replace references to "export LD_LIBRARY_PATH etc..." with "SET PATH=etc...;%PATH%" from the command line, or set via the Windows environment variables GUI. Not sure about Eclipse, I don't use it, but you should be able to set up a run configuration with the appropriate variables. – user2856 Jan 30 '15 at 7:12
  • thanks, I got it. Here are even more examples and I could use gdal_polygonize as gdalinfo. – Selphiron Feb 4 '15 at 12:00

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.