Index: src/Common/SharpMap.Extensions/GdalConfiguration.cs =================================================================== diff -u -r8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9 -r5fc71a385897af92ccb092f2f969b5709afab85a --- src/Common/SharpMap.Extensions/GdalConfiguration.cs (.../GdalConfiguration.cs) (revision 8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9) +++ src/Common/SharpMap.Extensions/GdalConfiguration.cs (.../GdalConfiguration.cs) (revision 5fc71a385897af92ccb092f2f969b5709afab85a) @@ -31,8 +31,8 @@ using System.IO; using System.Reflection; using DelftTools.Utils.Interop; -using Gdal = OSGeo.GDAL.Gdal; -using Ogr = OSGeo.OGR.Ogr; +using OSGeo.GDAL; +using OSGeo.OGR; namespace SharpMap.Extensions { @@ -42,14 +42,6 @@ private static bool _configuredGdal; /// - /// Function to determine which platform we're on - /// - private static string GetPlatform() - { - return Environment.Is64BitProcess ? "x64" : "x86"; - } - - /// /// Construction of Gdal/Ogr /// static GdalConfiguration() @@ -58,10 +50,12 @@ var executingDirectory = Path.GetDirectoryName(executingAssemblyFile); if (string.IsNullOrEmpty(executingDirectory)) + { throw new InvalidOperationException("cannot get executing directory"); - + } + var gdalPath = Path.Combine(executingDirectory, "gdal"); - + if (!Directory.Exists(gdalPath)) { // some code to handle tests: instead of adding gdal native to all test @@ -75,20 +69,26 @@ } } - if (!Directory.Exists(gdalPath)) throw new System.IO.DirectoryNotFoundException(String.Format("Directory '{0}' not found!", gdalPath)); + if (!Directory.Exists(gdalPath)) + { + throw new DirectoryNotFoundException(String.Format("Directory '{0}' not found!", gdalPath)); + } var nativePath = Path.Combine(gdalPath, GetPlatform()); - - if (!Directory.Exists(nativePath)) throw new System.IO.DirectoryNotFoundException(String.Format("Directory '{0}' not found!", nativePath)); + if (!Directory.Exists(nativePath)) + { + throw new DirectoryNotFoundException(String.Format("Directory '{0}' not found!", nativePath)); + } + using (NativeLibrary.SwitchDllSearchDirectory(nativePath)) { // Prepend native path to environment path, to ensure the // right libs are being used. var path = Environment.GetEnvironmentVariable("PATH"); path = nativePath + ";" + path; Environment.SetEnvironmentVariable("PATH", path); - + // disable plugins directory Gdal.SetConfigOption("GDAL_DRIVER_PATH", "disable"); @@ -112,7 +112,10 @@ /// Be sure to call this function before using Gdal/Ogr/Osr public static void ConfigureOgr() { - if (_configuredOgr) return; + if (_configuredOgr) + { + return; + } // Register drivers Ogr.RegisterAll(); @@ -127,7 +130,10 @@ /// Be sure to call this function before using Gdal/Ogr/Osr public static void ConfigureGdal() { - if (_configuredGdal) return; + if (_configuredGdal) + { + return; + } // Register drivers Gdal.AllRegister(); @@ -136,6 +142,14 @@ PrintDriversGdal(); } + /// + /// Function to determine which platform we're on + /// + private static string GetPlatform() + { + return Environment.Is64BitProcess ? "x64" : "x86"; + } + private static void PrintDriversOgr() { #if DEBUG