Monday, April 11, 2011

Java wrapper of GDAL

This blog is about to become a tech blog in addition to everything else. This is for my benefit and the benefit of all the other intrepid voyagers journeying through the vastness of the techscape.

This post describes the setup of the Java bindings of GDAL. The basic idea was that I wanted access to other image formats, in particular ENVI, without writing a bunch of code to slice and dice the binary blobs in which ENVI stores image data. There are a lot of ways to wrap the GDAL binaries from scratch. For some examples, see here:

Call it laziness, but I just did not want to deal with SWIG and having to re-compile everything. I suspected there is an easier way and there is. Good tech samaritan Tamas Szekeres maintains this list of pre-compiled binaries, including wrappers:

So I downloaded this one, for my Windows XP 32-bit operating system: release-1600-gdal-1-8-mapserver-5-6 which is compiled with Microsoft Visual C++ 2010. In the install directory is a GDAL/java/gdal.jar file. I would like to make use of this from within the Eclipse IDE. So I add gdal.jar to the class path and try to gdal.AllRegister(); But I get an exception like:

Native library load failed. java.lang.UnsatisfiedLinkError: C:\Program Files\GDAL\gdaljni.dll: Can't find dependent libraries

So I add the following to the VM arguments:

-Djava.library.path="C:/Program Files/GDAL"

This got me a little further but still threw an UnsatisfiedLinkError. Tamas suggested that I download the Microsoft Visual C++ 2010 Redistributable Package:

Once this was installed, gdal.AllRegister() runs without an exception, even if I remove the virtual machine argument. The GDAL test code also runs (, no problem (given the data types that are checked in the code). I have now made a similar installation on a Windows 7 64-bit OS that works. However, I did discover that if GeoTools 2.7 is installed (with imageio-ext 1.0.6), GDAL and GeoTools will not play well together. As soon as I took GeoTools off the classpath, everything worked fine. Otherwise, I got an UnsatisfiedLinkError. Out of superstition, I also added the location of the GDAL binaries to the system "path" variable, just in case windows starts hunting around for something.

The other thing that I have experienced on both XP and Windows 7 is that the JNI wrapper broke, possibly after a recent update. After some gnashing of teeth, a reinstallation of either the VC++ redistributable or GDAL, everything started working again.

Wednesday, March 23, 2011

Chinese Bourgeoisie

From the Communist Manifesto:

"The bourgeoisie, by the rapid improvement of all instruments of production, by the immensely facilitated means of communication, draws all, even the most barbarian, nations into civilisation. The cheap prices of commodities are the heavy artillery with which it batters down all Chinese walls, with which it forces the barbarians’ intensely obstinate hatred of foreigners to capitulate. It compels all nations, on pain of extinction, to adopt the bourgeois mode of production; it compels them to introduce what it calls civilisation into their midst, i.e., to become bourgeois themselves. In one word, it creates a world after its own image. "

"The bourgeoisie has subjected the country to the rule of the towns. It has created enormous cities, has greatly increased the urban population as compared with the rural, and has thus rescued a considerable part of the population from the idiocy of rural life."

"The bourgeoisie keeps more and more doing away with the scattered state of the population, of the means of production, and of property. It has agglomerated population, centralised the means of production, and has concentrated property in a few hands. The necessary consequence of this was political centralisation."

"Subjection of Nature’s forces to man, machinery, application of chemistry to industry and agriculture, steam-navigation, railways, electric telegraphs, clearing of whole continents for cultivation, canalisation of rivers, whole populations conjured out of the ground..."

Sound familiar?