GDAL success at last!

posted Jun 26, 2014, 11:08 AM by Lesley Bross
I was able to instantiate a RasterFactory! As usual with these types of errors there were multiple factors conspiring against me. The following actions seem to have gotten me over this hurdle:
1. Add a project reference to C:\Program Files\LANDIS-II\v6\bin\6.0\gdal_csharp.dll. This is the c_sharp wrapper for the GDAL libraries. Although the compiler did not require this reference, my application threw a run-time error indicating that it could not load this .dll. I also had to add a binding redirect element to the app.config file for this particular version of gdal_csharp.dll. This syntax is specified in one of my earlier posts.

2. Set the build platform target to AnyCpu in VS 2010. The default is x86. Not sure why this is needed or why it works, but it is/does

3. Add code on the form to prepend the LANDIS-II GDAL directory to the system path. A batch script does this in the current command-line version so I missed it because it wasn't anywhere in the c-sharp code:

    string newPath = "C:\\Program Files\\LANDIS-II\\GDAL\\1.9;" + path;
    Environment.SetEnvironmentVariable("PATH", newPath);