1. bjartn
  2. GdalGoneWild

Source

GdalGoneWild / src / GdalGoneWild.Client / GdalEnvironment.cs

using System;
using System.IO;
using OSGeo.GDAL;

namespace GdalGoneWild.Client
{
    class GdalEnvironment
    {
        public static void SetupEnvironment(string binFolder)
        {
            SetEnvironmentVariables(binFolder);
            Gdal.AllRegister();
        }

        public static void SetEnvironmentVariables(string binPath)
        {
            Gdal.SetConfigOption("GDAL_DATA", Path.Combine(binPath, @"gdal-data"));
            setValueNewVariable("GEOTIFF_CSV", Path.Combine(binPath, @"gdal-data"));
            setValueNewVariable("GDAL_DRIVER_PATH", Path.Combine(binPath, @"gdal-plugins"));
            setValueNewVariable("PROJ_LIB", Path.Combine(binPath, @"proj\SHARE"));
        }

        private static void setValueNewVariable(string name, string value)
        {
            if (Environment.GetEnvironmentVariable(name) == null)
                Environment.SetEnvironmentVariable(name, value);
        }

    }
}