Example #1
0
        public static bool Translate(Dataset dataset, string outputFile, GDALTranslateOptions translateOptions,
                                     Gdal.GDALProgressFuncDelegate progressFuncDelegate)
        {
            bool result = false;

            Dataset newDs = null;

            try
            {
                Gdal.PushErrorHandler(new Gdal.GDALErrorHandlerDelegate(GdalHandlers.ErrorHandler));
                newDs = Gdal.wrapper_GDALTranslate(outputFile, dataset, translateOptions, progressFuncDelegate, null);
                Gdal.PopErrorHandler();
            }
            catch (Exception ex)
            {
                //LoggerManager.WriteErrorLog(ex.Message);
            }
            finally
            {
                if (newDs != null)
                {
                    newDs.FlushCache();
                    newDs.Dispose();

                    result = true;
                }
            }

            return(result);
        }
Example #2
0
        public static bool EcwToTiff(string inputFile, string outputFile, GDALTranslateOptions translateOptions,
                                     Gdal.GDALProgressFuncDelegate progressFuncDelegate)
        {
            bool    result  = false;
            Dataset dataset = null;

            try
            {
                Gdal.PushErrorHandler(new Gdal.GDALErrorHandlerDelegate(GdalHandlers.ErrorHandler));
                dataset = Gdal.Open(inputFile, Access.GA_ReadOnly);
                Gdal.PopErrorHandler();

                if (dataset != null)
                {
                    result = Translate(dataset, outputFile, translateOptions, progressFuncDelegate);
                }
            }
            catch (Exception ex)
            {
                //LoggerManager.WriteErrorLog(ex.Message);
            }
            finally
            {
                if (dataset != null)
                {
                    dataset.FlushCache();
                    dataset.Dispose();
                }
            }

            return(result);
        }
Example #3
0
        private bool SetMapConvertInfo()
        {
            _mapConvertInfo = new MapConvertInfo();

            PathInfo pathInfo = _mapConvertPathSettingControl.GetMapConvertPathInfo();

            if (pathInfo.InputPathList.Count < 1)
            {
                MessageBox.Show("변환 경로 정보를 확인해주세요.", "변환", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }

            if (pathInfo.OutputPathString.Length < 1)
            {
                MessageBox.Show("변환 경로 정보를 확인해주세요.", "변환", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }

            _mapConvertInfo.MapConvertPathInfo = pathInfo;

            List <string>        convertOptions   = _mapConvertOptionControl.GetMapConvertOptions();
            GDALTranslateOptions translateOptions = CreateGdalTransOptions(convertOptions.ToArray());

            if (translateOptions == null)
            {
                return(false);
            }

            _mapConvertInfo.ConvertOptions       = convertOptions;
            _mapConvertInfo.GdalTranslateOptions = translateOptions;

            LoggerManager.WriteMapConvertInfoLog(_mapConvertInfo);

            return(true);
        }
Example #4
0
        public void TranslateAction(List <string> files)
        {
            GDALTranslateOptions transOptions = new GDALTranslateOptions(new[] { "-of", "KMLSUPEROVERLAY", "-co", "format=png" });

            var vrtOptions = new GDALBuildVRTOptions(new[] { "-overwrite" });
            var vrtFile    = BuildVRT("tempVRT", files, vrtOptions);

            Gdal.wrapper_GDALTranslate(Path.Combine(OutputDirName, KMZFileName), vrtFile, transOptions, null, null);
        }
 /// <summary>
 /// Translation of raster format
 /// </summary>
 /// <param name="InputRaster"></param>
 /// <param name="OutputRaster"></param>
 /// <param name="OutputDriver">driver neme for the output file, from GDAL drivers list</param>
 public static void TranslateRasterFormat(string InputRaster, string OutputRaster, string OutputDriver)
 {
     try
     {
         var opts = new string[] { "-sds", "-of", OutputDriver };
         using (var ds = Gdal.Open(InputRaster, Access.GA_ReadOnly)) {
             var options = new GDALTranslateOptions(opts);
             using (var outputDS = Gdal.wrapper_GDALTranslate(OutputRaster, ds, options, (Gdal.GDALProgressFuncDelegate)GDalProgress, $"Translare {InputRaster} to {OutputRaster} ({OutputDriver})")) {
                 outputDS.FlushCache();
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("Application error: " + e.Message);
     }
 }
Example #6
0
        private GDALTranslateOptions CreateGdalTransOptions(string[] options)
        {
            GDALTranslateOptions transOptions = null;

            try
            {
                transOptions = new GDALTranslateOptions(options);
            }
            catch (Exception ex)
            {
                string errorMsg = "변환 옵션 정보를 확인해주세요.";
                errorMsg += Environment.NewLine;
                errorMsg += ex.Message;

                MessageBox.Show(errorMsg, "변환 옵션 설정", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            return(transOptions);
        }
Example #7
0
 //создаёт квиклук
 public void CreateImage()
 {
     if (format.Equals("tif"))
     {
         Dataset ds      = Gdal.Open(pathToPicture, Access.GA_ReadOnly);
         var     options =
             new GDALTranslateOptions(new[]
         {
             "-of", "GTiff",
             "-outsize", $"{percent}%", $"{percent}%",
             "-co", "WORLDFILE=YES",
         });
         try
         {
             Dataset newDs = Gdal.wrapper_GDALTranslate(outputFile, ds, options,
                                                        new Gdal.GDALProgressFuncDelegate(ProgressFunc), null);
             newDs.Dispose();
         }
         catch
         {
         }
     }
     else if (format.Equals("jpg"))
     {
         Dataset ds      = Gdal.Open(pathToPicture, Access.GA_ReadOnly);
         var     options =
             new GDALTranslateOptions(new[]
         {
             "-of", "JPEG",
             "-outsize", $"{percent}%", $"{percent}%",
             "-co", "WORLDFILE=YES",
         });
         try
         {
             Dataset newDs = Gdal.wrapper_GDALTranslate(outputFile, ds, options,
                                                        new Gdal.GDALProgressFuncDelegate(ProgressFunc), null);
             newDs.Dispose();
         }
         catch
         {
         }
     }
 }