Tuesday, June 22, 2010

Using GDAL with ArcGIS Explorer

ArcGIS Explorer has extremely limited functionality right out of the box. If you are looking to do anything other than simply viewing data, you may find it very difficult with the ArcGIS Explorer api and standard .NET libraries. Fortunately, there are many open source GIS libraries that can be used to fill the gaps where the api is lacking. One such library is GDAL / OGR. These libraries can be found in the FWTools software package and are used in various commercial applications.

Much of the ArcGIS Explorer functionality is provided by these exact libraries. Therein lies our problem. The fact that the libraries are used in the application is not a problem in itself. The problem typically surfaces when you download the latest version of the library and attempt to use with Explorer. You may run into all sorts of odd problems, with the most common being a "dll not found" error. This error can be very misleading. The first reaction might be to see if the dll actually exists. If you check, you will find that it DOES exist, and it is in a location where the application should be able to find it. So why does Explorer give a dll not found error? Welcome to dll hell. For many a COM developer, this is familiar territory, but not so for .NET developers. In .NET, dll hell has been all but eradicated.

For those unfamiliar with dll hell, the short explination goes something like this: windows has a specific order in which it looks for dll's. It typically starts with the directory containing the application, after which it will search through each of the directories in the path variable. During this sequence, it will load the very first dll it finds with a matching name. "So what happens when the dll it finds is not the one my application is expecting?" you ask. This, my friends, is dll hell. I cannot tell you specifically what will happen in your case, but chances are it will not be good.

So why are we experiencing it here? Well, GDAL is not a native .NET library. It is written in C/C++ with .NET wrappers built on top. To some degree, the "dll not found" error is accurate, because it did not find the version of the dll it was searching for. So how do we fix that? Well, the simple answer is to simply use the same version of GDAL that is used by the main application. What is good about this is that you will not even need to include the dlls with your deployment, since they already exist within the application. You will have to include any of the .NET wrappers you use, however.

One roadblock that you may run into is finding the right version of GDAL. In the case of ArcGIS Explorer 10, GDAL 1.6.1 is used. Tracking down the right files can prove troublesome, since the version you need may not exist in binary form, which means you may have to download the source and compile it yourself. Since GDAL is typically built using nMake files, this can be quite a chore for the inexperienced. Fortunately, I have already done this for you, and I'm providing the .NET dlls for your convenience here.

If the version of GDAL that is included with the version of the application you have is different than the one posted here, you can find the instructions on how to build from source here.

Using GDAL with ArcGIS Explorer, you can potentially add on a mountain of functionality that does not exist natively within the application. For those who need some additional functionality but cannot afford to pony up the dough for a full blown ArcGIS license, this may be the solution you are looking for.