Example #1
0
        public void CyrillicSymbols_NO_Option()
        {
            Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "NO");

            var currentState = Gdal.GetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");

            _outputHelper.WriteLine($"Test 4 - GDAL_FILENAME_IS_UTF8 is set to {currentState} before the test");

            var outputFilePath = Path.Combine(dataDirectoryPath, "test4.vrt");

            var result = RunTest(cyrillicInputFilePath, dataDirectoryPath, outputFilePath);

            // this works like a charm on linux even without config flag
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                Assert.True(result);
            }

            // windows can't find a file though
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Assert.False(result);
            }
            else
            {
                throw new XunitException("This test was not created for current os platform");
            }
        }
Example #2
0
        public void LatinSymbols_NO_Option()
        {
            Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "NO");

            var currentState = Gdal.GetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");

            _outputHelper.WriteLine($"Test 3 - GDAL_FILENAME_IS_UTF8 is set to {currentState} before the test");

            var outputFilePath = Path.Combine(dataDirectoryPath, "test3.vrt");

            Assert.True(RunTest(englishInputFilePath, dataDirectoryPath, outputFilePath));
        }
Example #3
0
        public void CyrillicSymbols_YES_OptionDefault()
        {
            Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");

            string currentState = Gdal.GetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");

            _outputHelper.WriteLine($"Test 2 - GDAL_FILENAME_IS_UTF8 is set to {currentState} before the test");

            var outputFilePath = Path.Combine(dataDirectoryPath, "test2.vrt");

            Assert.True(RunTest(cyrillicInputFilePath, dataDirectoryPath, outputFilePath));
        }
Example #4
0
        public void LatinSymbols_YES_OptionDefault()
        {
            Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");

            string currentState = Gdal.GetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");

            _outputHelper.WriteLine($"Test 1 - GDAL_FILENAME_IS_UTF8 is set to {currentState} by default");

            var outputFilePath = Path.Combine(dataDirectoryPath, "test1.vrt");

            Assert.True(RunTest(englishInputFilePath, dataDirectoryPath, outputFilePath));
        }
Example #5
0
        /// <summary>
        /// Looks for Gdal's binaries and sets PATHs if needed.
        /// </summary>
        internal static void Initialize()
        {
            try
            {
                if (!IsWindows)
                {
                    const string notSet = "_Not_set_";
                    string       temp   = Gdal.GetConfigOption("GDAL_DATA", notSet);
                    Usable = temp != notSet;
                    throw new Exception(string.Format(Strings.DoesntSupportPlatform, "GDAL"));
                }

                string executingAssemblyFile = Assembly.GetExecutingAssembly().Location;
                string executingDirectory    = Path.GetDirectoryName(executingAssemblyFile);

                if (string.IsNullOrWhiteSpace(executingDirectory))
                {
                    throw new Exception(string.Format(Strings.StringIsEmpty, nameof(executingDirectory)));
                }

                // modify search place and order
                SetDefaultDllDirectories(DllSearchFlags);

                // ReSharper disable once AssignNullToNotNullAttribute
                string gdalPath   = Path.Combine(executingDirectory, "gdal");
                string nativePath = Path.Combine(gdalPath, GetPlatform());
                if (!Directory.Exists(nativePath))
                {
                    throw new Exception(string.Format(Strings.DoesntExist, "GDAL", nativePath));
                }
                if (!File.Exists(Path.Combine(nativePath, "gdal_wrap.dll")))
                {
                    throw new Exception(string.Format(Strings.DoesntExist, "gdal_warp.dll", nativePath));
                }

                // 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);

                //TODO: Fix bug with cyrillic paths
                //string gdalFileNameIsUtf8 = "NO";
                //Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", gdalFileNameIsUtf8);
            }
            catch (Exception exception)
            {
                Usable = false;
                throw new Exception(string.Format(Strings.UnableToConfigure, "GDAL"), exception);
            }

            Usable = true;
        }
Example #6
0
        private long ConvertMap(BackgroundWorker worker, DoWorkEventArgs e)
        {
            long result = 0;

            if (worker.CancellationPending)
            {
                e.Cancel = true;
                return(result);
            }

            int count      = 0;
            var pathInfo   = _mapConvertInfo.MapConvertPathInfo;
            var inputPaths = pathInfo.InputPathList;
            int listCount  = inputPaths.Count;

            _mapConvertResultInfo.InputFileCount  = listCount;
            _mapConvertResultInfo.OutputFileCount = listCount;

            LoggerManager.WriteInfoLog("변환 작업을 시작합니다.");
            LoggerManager.WriteDebugLog(LoggerManager.SubSeparatorString);

            _mapConvertResultInfo.StartTime = DateTime.Now;

            CommonUtil.SetLabelText(this, label4, string.Format("{0}/{1}", count, listCount));

            var size  = Gdal.GetConfigOption("GDAL_SWATH_SIZE", "");
            var size1 = Gdal.GetConfigOption("GDAL_CACHEMAX", "");

            foreach (string inputFilePath in inputPaths)
            {
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }

                string outputFilePath = "";

                if (pathInfo.SelectedPathType == PathType.FilePathType)
                {
                    outputFilePath = pathInfo.OutputPathString;
                }
                else
                {
                    string ext = Path.GetExtension(inputFilePath);
                    outputFilePath = inputFilePath.Replace(ext, ".tif").Replace(pathInfo.InputPathString, pathInfo.OutputPathString);
                }

                CommonUtil.CreateDirectoryByFilePath(outputFilePath);

                count++;

                DateTime startTime = DateTime.Now;

                string logString = string.Format(" [{0}/{1}]변환 시작", count, listCount);

                LoggerManager.WriteDebugLog(logString);
                LoggerManager.WriteFileInfoLog(inputFilePath, outputFilePath);

                bool isConverted = MapConverter.EcwToTiff(inputFilePath, outputFilePath, _mapConvertInfo.GdalTranslateOptions
                                                          , new Gdal.GDALProgressFuncDelegate(ProgressFunc));

                WriteResultLog(isConverted, count, startTime);

                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }

                CommonUtil.SetLabelText(this, label4, string.Format("{0}/{1}", count, listCount));
                CommonUtil.SetProgressBarValue(progressBar1, count);
            }

            return(result);
        }