/// <summary> /// Construction of Gdal/Ogr /// </summary> static GdalConfiguration() { var executingAssemblyFile = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath; var executingDirectory = Path.GetDirectoryName(executingAssemblyFile); if (string.IsNullOrEmpty(executingDirectory)) { throw new InvalidOperationException("cannot get executing directory"); } var gdalPath = Path.Combine(executingDirectory, "gdal"); var nativePath = Path.Combine(gdalPath, GetPlatform()); // Prepend native path to environment path, to ensure the // right libs are being used. var path = Environment.GetEnvironmentVariable("PATH"); path = nativePath + ";" + Path.Combine(nativePath, "plugins") + ";" + path; Environment.SetEnvironmentVariable("PATH", path); // Set the additional GDAL environment variables. var gdalData = Path.Combine(gdalPath, "data"); Environment.SetEnvironmentVariable("GDAL_DATA", gdalData); Gdal.SetConfigOption("GDAL_DATA", gdalData); var driverPath = Path.Combine(nativePath, "plugins"); Environment.SetEnvironmentVariable("GDAL_DRIVER_PATH", driverPath); Gdal.SetConfigOption("GDAL_DRIVER_PATH", driverPath); Environment.SetEnvironmentVariable("GEOTIFF_CSV", gdalData); Gdal.SetConfigOption("GEOTIFF_CSV", gdalData); var projSharePath = Path.Combine(gdalPath, "share"); Environment.SetEnvironmentVariable("PROJ_LIB", projSharePath); Gdal.SetConfigOption("PROJ_LIB", projSharePath); }
/// <summary> /// Construction of Gdal/Ogr /// </summary> static GdalConfiguration() { var executingAssemblyFile = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath; var executingDirectory = Path.GetDirectoryName(executingAssemblyFile); if (string.IsNullOrEmpty(executingDirectory)) { throw new InvalidOperationException("cannot get executing directory"); } var path = Environment.GetEnvironmentVariable("PATH"); String gdalLib = Path.Combine(executingDirectory, "MVActiveX"); path = gdalLib + ";" + path; Environment.SetEnvironmentVariable("PATH", path); String gdalData = Path.Combine(executingDirectory, "gdal\\data"); Environment.SetEnvironmentVariable("GDAL_DATA", gdalData); Gdal.SetConfigOption("GDAL_DATA", gdalData); Environment.SetEnvironmentVariable("GEOTIFF_CSV", gdalData); Gdal.SetConfigOption("GEOTIFF_CSV", gdalData); }
/// <summary> /// Construction of Gdal/Ogr /// </summary> static GdalConfiguration() { string executingDirectory = null, gdalPath = null, nativePath = null; try { if (!IsWindows) { const string notSet = "_Not_set_"; string tmp = Gdal.GetConfigOption("GDAL_DATA", notSet); _usable = tmp != notSet; return; } string executingAssemblyFile = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath; executingDirectory = Path.GetDirectoryName(executingAssemblyFile); if (string.IsNullOrEmpty(executingDirectory)) { throw new InvalidOperationException("cannot get executing directory"); } // modify search place and order SetDefaultDllDirectories(DllSearchFlags); gdalPath = Path.Combine(executingDirectory, "gdal"); nativePath = Path.Combine(gdalPath, GetPlatform()); if (!Directory.Exists(nativePath)) { throw new DirectoryNotFoundException($"GDAL native directory not found at '{nativePath}'"); } if (!File.Exists(Path.Combine(nativePath, "gdal_wrap.dll"))) { throw new FileNotFoundException( $"GDAL native wrapper file not found at '{Path.Combine(nativePath, "gdal_wrap.dll")}'"); } // Add directories AddDllDirectory(nativePath); AddDllDirectory(Path.Combine(nativePath, "plugins")); // Set the additional GDAL environment variables. string gdalData = Path.Combine(gdalPath, "data"); Environment.SetEnvironmentVariable("GDAL_DATA", gdalData); Gdal.SetConfigOption("GDAL_DATA", gdalData); string driverPath = Path.Combine(nativePath, "plugins"); Environment.SetEnvironmentVariable("GDAL_DRIVER_PATH", driverPath); Gdal.SetConfigOption("GDAL_DRIVER_PATH", driverPath); Environment.SetEnvironmentVariable("GEOTIFF_CSV", gdalData); Gdal.SetConfigOption("GEOTIFF_CSV", gdalData); string projSharePath = Path.Combine(gdalPath, "share"); Environment.SetEnvironmentVariable("PROJ_LIB", projSharePath); Gdal.SetConfigOption("PROJ_LIB", projSharePath); _usable = true; } catch (Exception e) { _usable = false; Trace.WriteLine(e, "error"); Trace.WriteLine($"Executing directory: {executingDirectory}", "error"); Trace.WriteLine($"gdal directory: {gdalPath}", "error"); Trace.WriteLine($"native directory: {nativePath}", "error"); //throw; } }