Using the GDAL/OGR CSharp interface
Adding reference to the GDAL/OGR assemblies
TODO
Using the interface classes
TODO
Q & A
Modifying Local Search Path
Can I set a system path from C# that will be searched and that will not interfere with possible other processes search path?
If you want to add FWTools bin folder to PATH during run-time, so you don't have to pollute system PATH permanently, you can do it this way, in C#
using System.Runtime.InteropServices;
...
[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool
SetEnvironmentVariable(string lpName, string lpValue);
...
string GDAL_HOME = @";C:\Program Files\FWTools\bin"; // for example
string path = Environment.GetEnvironmentVariable("PATH");
path += ";" + GDAL_HOME;
SetEnvironmentVariable("PATH", path);
Now, for current process, all DLLs from FWTools package are accessible.
MSDN documentation:
- http://msdn2.microsoft.com/en-us/library/ms686206.aspx
- http://msdn2.microsoft.com/en-us/library/system.environment.setenvironmentvariable.aspx
Instead of the P/Invoke call to SetEnvironmentVariable, you can use C# native method Environment.SetEnvironmentVariable (AFAIR, available from .NET >= 2.0). Read the doc carefully, because there are two versions of this method. Unlike the Win32 API call accessed through P/Invoke, the method Environment.SetEnvironmentVariable has overloaded version that *may* change environment permanently, across processes.
adapted from http://lists.maptools.org/pipermail/gdal-dev/2007-August/013823.html
