コード例 #1
0
        private void button5_Click(object sender, EventArgs e)
        {
            string            fileName = SelectFile("选择轨道数据");
            ISpatialReference prj      = SelectPrj("选择目标投影定义");
            ProjectionFactory quick    = new ProjectionFactory();

            string[] outFiles = null;
            string   errorMessage;

            try
            {
                PrjOutArg prjOutArg = new PrjOutArg(prj, null, 0, 0, Path.GetDirectoryName(fileName));
                outFiles = quick.Project(fileName, prjOutArg, _progressCallback, out errorMessage);
            }
            finally
            {
            }
        }
コード例 #2
0
        private void Project(string fileName, ISpatialReference proj)
        {
            string errorMsg;

            string[]             outFiles = null;
            Action <int, string> progress = new Action <int, string>(OnProgress);
            ProjectionFactory    quick    = new ProjectionFactory();

            try
            {
                _progressMonitor = _smartSession.ProgressMonitorManager.DefaultProgressMonitor;
                if (_progressMonitor != null)
                {
                    _progressMonitor.Reset("", 100);
                    _progressMonitor.Start(false);
                    _progressMonitor.Boost(0, "准备文件");
                }
                PrjOutArg prjOutArg = new PrjOutArg(proj, null, 0, 0, Path.GetDirectoryName(fileName));
                outFiles = quick.Project(fileName, prjOutArg, progress, out errorMsg);
            }
            finally
            {
                if (_progressMonitor != null)
                {
                    _progressMonitor.Finish();
                }
                progress = null;
            }
            if (outFiles != null && outFiles.Length != 0)
            {
                for (int i = 0; i < outFiles.Length; i++)
                {
                    if (!string.IsNullOrWhiteSpace(outFiles[i]))
                    {
                        OpenFileToWindows(outFiles[i]);
                    }
                }
            }
            if (errorMsg != null && errorMsg.Length != 0)
            {
                MsgBox.ShowInfo(errorMsg);
            }
        }
コード例 #3
0
        public IRasterDataProvider[] DoProject(PrjOutArg prjArgs, MosaicType mosaicType, Action <int, string> progressCallback, out string msg)
        {
            ProjectionFactory proj = new ProjectionFactory();

            msg = "";
            TryCreateOutDir(prjArgs.OutDirOrFile);
            StringBuilder   str            = new StringBuilder();
            List <string[]> projectedFiles = new List <string[]>();

            for (int fileIndex = 0; fileIndex < _fileItems.Count; fileIndex++)
            {
                string            errMessage;
                MosaicProjectItem item = _fileItems[fileIndex];
                if (item == null || item.MainFile == null)
                {
                    continue;
                }
                string file        = item.MainFile.fileName;
                string outfilename = "";
                if (mosaicType != MosaicType.NoMosaic &&
                    !IsDir(prjArgs.OutDirOrFile) && _fileItems.Count > 1)
                {
                    outfilename          = prjArgs.OutDirOrFile;
                    prjArgs.OutDirOrFile = Path.GetDirectoryName(outfilename) + "\\" + Guid.NewGuid().ToString() + Path.GetExtension(outfilename);
                }
                string[] files = proj.Project(file, prjArgs, progressCallback, out errMessage);
                if (!string.IsNullOrWhiteSpace(outfilename))
                {
                    prjArgs.OutDirOrFile = outfilename;
                }
                if (!string.IsNullOrWhiteSpace(errMessage))
                {
                    str.AppendLine(Path.GetFileName(file) + errMessage);
                }
                if (files == null || files.Length == 0)
                {
                    continue;
                }
                if (files.Length == 1 && files[0] == null)
                {
                    continue;
                }
                projectedFiles.Add(files);
            }
            msg = str.ToString();
            if (projectedFiles.Count == 0)
            {
                return(null);
            }
            if (projectedFiles.Count == 1 && projectedFiles[0] == null)
            {
                return(null);
            }
            int envCount = prjArgs.Envelopes == null ? 1 : prjArgs.Envelopes.Length;

            IRasterDataProvider[]      retEnvFiles         = new IRasterDataProvider[envCount];
            List <IRasterDataProvider> retEnvFilesNoMosaic = new List <IRasterDataProvider>();

            for (int i = 0; i < envCount; i++)
            {
                List <string> envFiles = new List <string>();
                for (int j = 0; j < _fileItems.Count; j++)
                {
                    if (j >= projectedFiles.Count)
                    {
                        break;
                    }
                    if (projectedFiles[j] != null && projectedFiles[j].Length > i)
                    {
                        if (projectedFiles[j] == null || projectedFiles[j].Length == 0 || string.IsNullOrWhiteSpace(projectedFiles[j][i]))
                        {
                            continue;
                        }
                        envFiles.Add(projectedFiles[j][i]);
                    }
                }
                //by chennan 批量分幅投影
                if (mosaicType != MosaicType.NoMosaic)
                {
                    if (envFiles.Count > 1)
                    {
                        List <IRasterDataProvider> mosaicFiles = new List <IRasterDataProvider>();
                        try
                        {
                            foreach (string envfile in envFiles)
                            {
                                IRasterDataProvider file = FileHelper.Open(envfile);
                                mosaicFiles.Add(file);
                            }
                            string mosaicFile = null;
                            if (prjArgs == null || string.IsNullOrWhiteSpace(prjArgs.OutDirOrFile))
                            {
                                string outDir = Path.GetDirectoryName(mosaicFiles[0].fileName);
                                mosaicFile = Path.Combine(outDir, Path.GetFileNameWithoutExtension(mosaicFiles[0].fileName) + "_MOSAIC.ldf");
                            }
                            else
                            {
                                if (IsDir(prjArgs.OutDirOrFile))
                                {
                                    mosaicFile = Path.Combine(prjArgs.OutDirOrFile, Path.GetFileNameWithoutExtension(mosaicFiles[0].fileName) + "_MOSAIC.ldf");
                                }
                                else
                                {
                                    mosaicFile = prjArgs.OutDirOrFile;
                                }
                            }
                            RasterMoasicProcesser processer       = new RasterMoasicProcesser();
                            IRasterDataProvider   drcDataProvider = processer.Moasic(mosaicFiles.ToArray(), "LDF", mosaicFile, true, new string[] { "0" }, progressCallback);
                            //拼接角度文件
                            if (prjArgs.Args != null && prjArgs.Args.Length > 0)
                            {
                                foreach (object arg in prjArgs.Args)
                                {
                                    if (arg is string)
                                    {
                                        bool     isMoasic  = true;
                                        string[] extentStr = null;
                                        List <IRasterDataProvider> mosaicExtFile = new List <IRasterDataProvider>();
                                        List <string> extFileList = new List <string>();
                                        try
                                        {
                                            string extFileName;
                                            string extension;
                                            string argStr = arg as string;
                                            if (argStr.Contains("="))
                                            {
                                                argStr = argStr.Split('=')[1];
                                                if (argStr.Contains(";"))
                                                {
                                                    extentStr = argStr.Split(';');
                                                }
                                            }
                                            if (extentStr != null)
                                            {
                                                for (int extentIndex = 0; extentIndex < extentStr.Length; extentIndex++)
                                                {
                                                    argStr    = extentStr[extentIndex];
                                                    extension = "." + argStr + ".ldf";
                                                    for (int j = 0; j < envFiles.Count; j++)
                                                    {
                                                        extFileName = Path.ChangeExtension(envFiles[j], extension);
                                                        if (!File.Exists(extFileName))
                                                        {
                                                            isMoasic = false;
                                                            break;
                                                        }
                                                        else
                                                        {
                                                            isMoasic = true;
                                                        }
                                                        IRasterDataProvider file = FileHelper.Open(extFileName);
                                                        mosaicExtFile.Add(file);
                                                        extFileList.Add(extFileName);
                                                    }
                                                    if (isMoasic)
                                                    {
                                                        string outFileName = Path.ChangeExtension(mosaicFile, extension);
                                                        IRasterDataProvider drcExtDataProvider = processer.Moasic(mosaicExtFile.ToArray(), "LDF", outFileName, true, new string[] { "0" }, progressCallback);
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                extension = "." + argStr + ".ldf";
                                                for (int j = 0; j < envFiles.Count; j++)
                                                {
                                                    extFileName = Path.ChangeExtension(envFiles[j], extension);
                                                    if (!File.Exists(extFileName))
                                                    {
                                                        isMoasic = false;
                                                        break;
                                                    }
                                                    IRasterDataProvider file = FileHelper.Open(extFileName);
                                                    mosaicExtFile.Add(file);
                                                    extFileList.Add(extFileName);
                                                }
                                                if (isMoasic)
                                                {
                                                    string outFileName = Path.ChangeExtension(mosaicFile, extension);
                                                    IRasterDataProvider drcExtDataProvider = processer.Moasic(mosaicExtFile.ToArray(), "LDF", outFileName, true, new string[] { "0" }, progressCallback);
                                                }
                                            }
                                        }
                                        finally
                                        {
                                            if (mosaicExtFile.Count > 0)
                                            {
                                                foreach (IRasterDataProvider file in mosaicExtFile)
                                                {
                                                    if (file != null)
                                                    {
                                                        file.Dispose();
                                                    }
                                                }
                                                mosaicExtFile.Clear();
                                            }
                                            if (extFileList.Count > 0)
                                            {
                                                foreach (string envfile in extFileList)
                                                {
                                                    TryDeleteRasterFile(envfile);
                                                }
                                                extFileList.Clear();
                                            }
                                        }
                                    }
                                }
                            }
                            retEnvFiles[i] = drcDataProvider;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        finally
                        {
                            foreach (IRasterDataProvider envfile in mosaicFiles)
                            {
                                if (envfile != null)
                                {
                                    envfile.Dispose();
                                }
                            }
                            mosaicFiles.Clear();
                            foreach (string envfile in envFiles)
                            {
                                TryDeleteRasterFile(envfile);
                            }
                        }
                    }
                    else if (envFiles.Count == 1)
                    {
                        if (!IsDir(prjArgs.OutDirOrFile) && !string.IsNullOrWhiteSpace(prjArgs.OutDirOrFile) && envFiles[0] != prjArgs.OutDirOrFile)
                        {
                            if (!Directory.Exists(Path.GetDirectoryName(prjArgs.OutDirOrFile)))
                            {
                                Directory.CreateDirectory(Path.GetDirectoryName(prjArgs.OutDirOrFile));
                            }
                            File.Copy(envFiles[0], prjArgs.OutDirOrFile);
                            TryDeleteRasterFile(envFiles[0]);
                            retEnvFiles[i] = FileHelper.Open(prjArgs.OutDirOrFile);
                        }
                        else
                        {
                            retEnvFiles[i] = FileHelper.Open(envFiles[0]);
                        }
                    }
                    else
                    {
                        retEnvFiles[i] = null;
                    }
                    //
                }
                else if (envFiles.Count != 0)
                {
                    List <IRasterDataProvider> mosaicFiles = new List <IRasterDataProvider>();
                    foreach (string envfile in envFiles)
                    {
                        IRasterDataProvider file = FileHelper.Open(envfile);
                        mosaicFiles.Add(file);
                    }
                    retEnvFilesNoMosaic.AddRange(mosaicFiles);
                }
            }
            //
            return(retEnvFilesNoMosaic.Count == 0 ? retEnvFiles : retEnvFilesNoMosaic.ToArray());
        }
コード例 #4
0
        private void DoExecte()
        {
            List <string> retFiles = new List <string>();

            try
            {
                StartProgress();
                string            outDir = txtOutDir.Text;
                PrjEnvelopeItem[] prjEnvelopeItem;
                float             resolutionX, resolutionY;
                GetMapInfo(out prjEnvelopeItem, out resolutionX, out resolutionY);
                string        msg;
                List <object> argExs = new List <object>();
                if (!btnRadiation.Checked)
                {
                    argExs.Add("NotRadiation");
                }
                if (!btnSolarZenith.Checked)
                {
                    argExs.Add("NotSolarZenith");
                }
                if (chkSensorZenith.Checked)
                {
                    argExs.Add("IsSensorZenith");//执行临边变暗订正
                }
                if (btnOutAngle.Checked)
                {
                    argExs.Add("SensorAzimuth");
                    argExs.Add("SensorZenith");
                    argExs.Add("SolarAzimuth");
                    argExs.Add("SolarZenith");
                    //NOAA 特有
                    argExs.Add("SatelliteZenith");
                    argExs.Add("RelativeAzimuth");
                    //FY2  特有
                    argExs.Add("NOMSatelliteZenith");
                    argExs.Add("NOMSunGlintAngle");
                    argExs.Add("NOMSunZenith");
                }
                if (chkHeight.Checked)
                {
                    argExs.Add("ExtBands=Height;DEM");
                }
                PrjOutArg prjarg = new PrjOutArg(_dstSpatialRef, prjEnvelopeItem, resolutionX, resolutionY, outDir);
                prjarg.Args          = argExs.ToArray();
                prjarg.SelectedBands = prjArgsSelectBand1.SelectedBandIndexs();
                _retFiles            = _mosaicProjectionFileProvider.DoProject(prjarg, _mosaicType, _progress, out msg);
                if (_retFiles == null && !string.IsNullOrWhiteSpace(msg))
                {
                    UpdateMessage(msg);
                }
            }
            catch (Exception ex)
            {
                UpdateMessage(ex.Message);
            }
            finally
            {
                FinishProgerss();
                if (_retFiles != null)
                {
                    for (int i = 0; i < _retFiles.Length; i++)
                    {
                        if (_retFiles[i] != null)
                        {
                            string fileName = _retFiles[i].fileName;
                            retFiles.Add(fileName);
                            _retFiles[i].Dispose();
                            _retFiles[i] = null;
                        }
                    }
                    _retFiles = null;
                }
            }
            OpenFiles(retFiles.ToArray());
        }
コード例 #5
0
ファイル: CommandProjectAOI.cs プロジェクト: windygu/hispeed
 /// <summary>
 ///
 /// </summary>
 /// <param name="argument">格式"*#*"冒号前面部分表示文件名称,冒号后面部分表示所选投影坐标的Wkt格式字符串</param>
 public override void Execute(string argument)
 {
     try
     {
         string            fileName = "";
         ISpatialReference proj     = null;
         GeoDo.RSS.Core.DrawEngine.CoordEnvelope[] envelopes;
         fileName = TryCheckArgsEnvironment(out envelopes);
         proj     = SpatialReference.GetDefault();
         List <PrjEnvelopeItem> lstEnvelope = new List <PrjEnvelopeItem>();
         for (int i = 0; i < envelopes.Length; i++)
         {
             GeoDo.RSS.Core.DrawEngine.CoordEnvelope env = envelopes[i];
             if (env.IsEmpty())
             {
                 throw new Exception("获得的感兴趣区域是空值:" + env.ToString());
             }
             PrjEnvelope prjEnv = new PrjEnvelope(env.MinX, env.MaxX, env.MinY, env.MaxY);
             lstEnvelope.Add(new PrjEnvelopeItem("AOI", prjEnv));
         }
         if (string.IsNullOrWhiteSpace(fileName))
         {
             throw new Exception("无法从参数中解析出文件名:" + argument);
         }
         string               errorMsg;
         string[]             outFiles        = null;
         IProgressMonitor     progressMonitor = null;
         Action <int, string> progress        = null;
         try
         {
             progressMonitor = _smartSession.ProgressMonitorManager.DefaultProgressMonitor;
             progress        = new Action <int, string>(
                 (int progerss, string text) =>
             {
                 if (progressMonitor != null)
                 {
                     progressMonitor.Boost(progerss, text);
                 }
             });
             if (progressMonitor != null)
             {
                 progressMonitor.Reset("", 100);
                 progressMonitor.Start(false);
                 progressMonitor.Boost(0, "准备文件");
             }
             string    outdir    = GetOutDirFromConfig(fileName);
             PrjOutArg prjOutArg = new PrjOutArg(proj, lstEnvelope.ToArray(), 0, 0, outdir);
             //添加对自定义感兴趣区的支持。
             ProjectionFactory quick = new ProjectionFactory();
             outFiles = quick.Project(fileName, prjOutArg, progress, out errorMsg);
         }
         finally
         {
             if (progressMonitor != null)
             {
                 progressMonitor.Finish();
             }
             progress = null;
         }
         if (outFiles != null && outFiles.Length != 0)
         {
             for (int i = 0; i < outFiles.Length; i++)
             {
                 if (!string.IsNullOrWhiteSpace(outFiles[i]))
                 {
                     OpenFileToWindows(outFiles[i]);
                 }
             }
         }
         if (errorMsg != null && errorMsg.Length != 0)
         {
             MsgBox.ShowInfo(errorMsg);
         }
     }
     catch (Exception ex)
     {
         MsgBox.ShowInfo(ex.Message);
     }
 }
コード例 #6
0
 private void GetOverview(IRasterDataProvider file, ISpatialReference spatialRef, int[] bandNos, out Bitmap bmp, out string errorMessage)
 {
     try
     {
         errorMessage = "";
         if (bandNos == null)
         {
             bandNos = new int[] { 1 }
         }
         ;
         if (!File.Exists(_prjFilename))
         {
             float resolution = 0.05f;
             if (file.DataIdentify != null && file.DataIdentify.Sensor == "VISSR")
             {
                 resolution = 0.1f;
             }
             if (file.DataIdentify != null && (file.DataIdentify.Satellite == "FY1D"))
             {
                 resolution = 0.1f;
             }
             PrjOutArg arg = new PrjOutArg(spatialRef, null, resolution, resolution, _prjFilename);
             arg.SelectedBands = bandNos.OrderBy((i) => { return(i); }).ToArray();
             ProjectionFactory proj  = new ProjectionFactory();
             string[]          files = proj.Project(file, arg, null, out errorMessage);
             if (files == null || files.Length == 0 || files[0] == null)
             {
                 bmp = null;
                 if (string.IsNullOrWhiteSpace(errorMessage))
                 {
                     errorMessage = "投影缩略图文件失败";
                 }
                 return;
             }
             _prjFilename = files[0];
         }
         using (IRasterDataProvider prd = GeoDataDriver.Open(_prjFilename) as IRasterDataProvider)
         {
             if (bandNos == null || bandNos.Length == 0)
             {
                 bandNos = prd.GetDefaultBands();
             }
             if (bandNos == null || bandNos.Length == 0)
             {
                 bmp = null;
                 if (string.IsNullOrWhiteSpace(errorMessage))
                 {
                     errorMessage = "获取缩略图显示波段列表为空";
                 }
                 return;
             }
             //bandNos = new int[] { 1, 1, 1 };
             int[]     orderBandMaps;
             PrjBand[] prjBands = BandNoToBand(bandNos, out orderBandMaps);
             bmp = GenerateOverview(prd, orderBandMaps);
         }
     }
     catch
     {
         bmp = null;
         throw;
     }
 }
コード例 #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="argument">
 /// 格式"*#*"冒号前面部分表示文件名称,冒号后面部分表示所选投影坐标的Wkt格式字符串
 /// </param>
 public override void Execute(string argument)
 {
     try
     {
         string            fileName  = "";
         string            prjString = "";
         ISpatialReference proj      = null;
         if (string.IsNullOrWhiteSpace(argument))
         {
             fileName = TryGetFileFromActiveView();
             proj     = SpatialReference.GetDefault();
         }
         else
         {
             MatchCollection matches = Regex.Matches(argument, @"(?<file>[^#]*)#(?<proj>.*)");
             fileName  = matches[0].Groups["file"].Value;
             prjString = matches[0].Groups["proj"].Value;
             if (string.IsNullOrWhiteSpace(fileName) || fileName.ToLower() == "null")
             {
                 fileName = TryGetFileFromActiveView();
             }
             if (string.IsNullOrWhiteSpace(prjString) || prjString.ToLower() == "null")
             {
                 proj = SpatialReference.GetDefault();
             }
             else
             {
                 proj = SpatialReference.FromWkt(prjString, enumWKTSource.EsriPrjFile);
             }
         }
         if (string.IsNullOrWhiteSpace(fileName))
         {
             throw new Exception("无法从参数中解析出文件名:" + argument);
         }
         IProgressMonitor  progress = _smartSession.ProgressMonitorManager.DefaultProgressMonitor;
         ProjectionFactory quick    = new ProjectionFactory();
         string            errorMsg;
         string[]          outFiles = null;
         try
         {
             _progressMonitor = _smartSession.ProgressMonitorManager.DefaultProgressMonitor;
             if (_progressMonitor != null)
             {
                 _progressMonitor.Reset("", 100);
                 _progressMonitor.Start(false);
                 _progressMonitor.Boost(0, "准备文件");
             }
             PrjOutArg prjOutArg = new PrjOutArg(proj, null, 0, 0, Path.GetDirectoryName(fileName));
             outFiles = quick.Project(fileName, prjOutArg, new Action <int, string>(OnProgress), out errorMsg);
         }
         finally
         {
             if (_progressMonitor != null)
             {
                 _progressMonitor.Finish();
             }
         }
         if (outFiles != null && outFiles.Length != 0)
         {
             for (int i = 0; i < outFiles.Length; i++)
             {
                 if (!string.IsNullOrWhiteSpace(outFiles[i]))
                 {
                     OpenFileToWindows(outFiles[i]);
                 }
             }
         }
         if (errorMsg != null && errorMsg.Length != 0)
         {
             MsgBox.ShowInfo(errorMsg);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
コード例 #8
0
        public void Do(InputArg inArg)
        {
            CheckAtg(inArg);
            string    projectionIdentify = inArg.ProjectionIdentify;
            OutputArg outArg             = new OutputArg();

            try
            {
                using (AbstractWarpDataset inputRaster = WarpDataset.Open(inArg.InputFilename))
                {
                    RasterDatasetInfo dsInfo =
                        mRasterSourceManager.GetInstance().GetRasterDatasetInfo(inArg.InputFilename);
                    DateTime?    dateTime     = mRasterSourceManager.GetInstance().GetImageTime(inArg.InputFilename);
                    DataIdentify dataIdentify = new DataIdentify();
                    outArg.OrbitFilename      = Path.GetFileName(inArg.InputFilename);
                    outArg.Satellite          = dsInfo.SatelliteID;
                    outArg.Sensor             = dsInfo.SensorID;
                    outArg.Level              = "L1";
                    outArg.ProjectionIdentify = projectionIdentify;
                    outArg.ObservationDate    = dateTime.HasValue ? dateTime.Value.ToString("yyyyMMdd") : "";
                    outArg.ObservationTime    = dateTime.HasValue ? dateTime.Value.ToString("HHmm") : "";
                    outArg.Station            = ParseStation(Path.GetFileName(inArg.InputFilename));
                    outArg.DayOrNight         = DayOrNight(inputRaster);
                    if (dateTime.HasValue)
                    {
                        outArg.OrbitIdentify = CalcOrbitIdentify(dateTime.Value, inArg.PervObservationDate,
                                                                 inArg.PervObservationTime, inArg.OrbitIdentify);
                    }
                    outArg.Length = new FileInfo(inArg.InputFilename).Length;
                    string validEnvelopeMsg = "";

                    #region 日夜检查

                    if (!string.IsNullOrWhiteSpace(inArg.DayNight))
                    {
                        if (inArg.DayNight != "daynight" && outArg.DayOrNight == "X")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "未设定处理白天和晚上数据,白天晚上标记未知:X";
                        }
                        else if (inArg.DayNight == "day" && outArg.DayOrNight != "D")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为只处理白天数据,当前数据标记为晚上";
                        }
                        else if (inArg.DayNight == "night" && outArg.DayOrNight != "N")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为只处理晚上数据,当前数据标记为白天";
                        }
                        else if (inArg.DayNight == "notnight" && outArg.DayOrNight == "N")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为不处理晚上数据,当前数据标记为晚上";
                        }
                        else if (inArg.DayNight == "notday" && outArg.DayOrNight == "D")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为不处理白天数据,当前数据标记为白天";
                        }
                    }

                    #endregion 日夜检查

                    if (inArg.ValidEnvelopes == null || inArg.ValidEnvelopes.Length == 0)
                    {
                        outArg.LogLevel = "error";
                        outArg.LogInfo  = "参数错误:未正确设置ValidEnvelopes";
                    }
                    else if (!ValidEnvelope(inputRaster, inArg.ValidEnvelopes, out validEnvelopeMsg))
                    {
                        outArg.LogLevel = "info";
                        outArg.LogInfo  = validEnvelopeMsg;
                    }
                    else
                    {
                        PrjOutArg prjArg;
                        if (inArg.Envelopes == null || inArg.Envelopes.Length == 0)
                        {
                            prjArg = new PrjOutArg(projectionIdentify, null, inArg.ResolutionX, inArg.ResolutionY,
                                                   inArg.OutputDir);
                        }
                        else
                        {
                            prjArg = new PrjOutArg(projectionIdentify, inArg.Envelopes, inArg.ResolutionX,
                                                   inArg.ResolutionY, inArg.OutputDir);
                        }
                        //prjArg.Args = new string[] { "SolarZenith"};
                        if (inArg.Bands != null && inArg.Bands.Length != 0)
                        {
                            prjArg.SelectedBands = inArg.Bands;
                            Console.WriteLine("SelectedBands:" + string.Join(",", prjArg.SelectedBands));
                        }

                        //扩展参数
                        List <string> extArgs = new List <string>();
                        extArgs.Add("IsClearPrjCache");
                        if (inArg.ExtArgs != null)
                        {
                            extArgs.AddRange(inArg.ExtArgs);
                        }
                        prjArg.Args = extArgs.ToArray();
                        ProjectionFactory prjFactory = new ProjectionFactory();
                        string            retMessage = "";
                        string[]          files      = prjFactory.Project(inputRaster, prjArg, new Action <int, string>(OnProgress),
                                                                          out retMessage);
                        prjFactory = null;
                        //投影结束,执行拼接,如果有拼接节点
                        List <OutFileArg> fileArgs = new List <OutFileArg>();
                        for (int i = 0; i < files.Length; i++)
                        {
                            string file = files[i];
                            if (string.IsNullOrWhiteSpace(file) || !File.Exists(file))
                            {
                                continue;
                            }
                            OutFileArg fileArg = new OutFileArg();
                            Envelope   env     = null;
                            float      resolutionX;
                            float      resolutionY;
                            string     overViewFilename = "";
                            using (AbstractWarpDataset outfileRaster = WarpDataset.Open(file))
                            {
                                Console.WriteLine("生成缩略图开始");
                                overViewFilename = OverViewHelper.OverView(outfileRaster, _prjPngSize);
                                Console.WriteLine("生成缩略图结束");
                                env         = outfileRaster.GetEnvelope();
                                resolutionX = outfileRaster.ResolutionX;
                                resolutionY = outfileRaster.ResolutionY;
                                var dt = dateTime.HasValue ? dateTime.Value : DateTime.Now;
                                TryMosaicFile(inArg, outfileRaster, dsInfo, dt, outArg.DayOrNight);
                            }

                            fileArg.OutputFilename = Path.GetFileName(file);
                            fileArg.Thumbnail      =
                                (string.IsNullOrWhiteSpace(overViewFilename) && File.Exists(overViewFilename)
                                    ? ""
                                    : Path.GetFileName(overViewFilename));
                            string solarZenithFile = Path.Combine(Path.GetDirectoryName(file),
                                                                  Path.GetFileNameWithoutExtension(file) + ".SolarZenith.ldf");
                            string solarZenithHdrFile = Path.Combine(Path.GetDirectoryName(file),
                                                                     Path.GetFileNameWithoutExtension(file) + ".SolarZenith.hdr");
                            fileArg.ExtendFiles = Path.ChangeExtension(Path.GetFileName(file), "hdr") +
                                                  (string.IsNullOrWhiteSpace(solarZenithFile) &&
                                                   File.Exists(solarZenithFile)
                                                      ? ""
                                                      : "," + Path.GetFileName(solarZenithFile)) +
                                                  (string.IsNullOrWhiteSpace(solarZenithHdrFile) &&
                                                   File.Exists(solarZenithHdrFile)
                                                      ? ""
                                                      : "," + Path.GetFileName(solarZenithHdrFile));
                            fileArg.Envelope = new PrjEnvelopeItem("GBAL",
                                                                   env == null
                                    ? null
                                    : new RasterProject.PrjEnvelope(env.MinX, env.MaxX, env.MinY, env.MaxY,
                                                                    SpatialReferenceFactory.CreateSpatialReference(4326)));
                            fileArg.ResolutionX = resolutionX.ToString();
                            fileArg.ResolutionY = resolutionY.ToString();
                            fileArg.Length      = new FileInfo(file).Length;
                            fileArgs.Add(fileArg);
                            if (inArg.IsOnlySaveMosaicFile)
                            {
                                TryDeleteFile(file);
                            }
                        }

                        outArg.OutputFiles = fileArgs.ToArray();
                        outArg.LogLevel    = "info";
                        if (string.IsNullOrWhiteSpace(retMessage))
                        {
                            outArg.LogInfo = "投影成功";
                        }
                        else
                        {
                            outArg.LogInfo = retMessage;
                        }
                        if (string.IsNullOrWhiteSpace(validEnvelopeMsg))
                        {
                            outArg.LogInfo = outArg.LogInfo + validEnvelopeMsg;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                outArg.LogLevel = "error";
                Console.WriteLine(ex.StackTrace);
                outArg.LogInfo = ex.Message + ex.StackTrace;
                Console.WriteLine("PIE.Meteo.ProjectTool.Execute()", ex);
            }
            finally
            {
                //输出参数文件重新命名
                string inputFileName = Path.GetFileName(inArg.InputFilename);

                System.Text.RegularExpressions.Regex rex = new System.Text.RegularExpressions.Regex(@"_\d{4}M");
                if (rex.IsMatch(inputFileName))
                {
                    string oldResStr = rex.Match(inputFileName).Groups[0].Value;
                    if (inArg.ProjectionIdentify == "GLL")
                    {
                        inputFileName = inputFileName.Replace(oldResStr,
                                                              $"_{PrjFileName.GLLResolutionIdentify(inArg.ResolutionX)}");
                    }
                    else
                    {
                        inputFileName = inputFileName.Replace(oldResStr,
                                                              $"_{PrjFileName.ResolutionIdentify(inArg.ResolutionX)}");
                    }
                }

                string outXmlFilename = Path.Combine(inArg.OutputDir, inputFileName + ".xml");
                OutputArg.WriteXml(outArg, outXmlFilename);
            }
        }
コード例 #9
0
        public void Do(InputArg inArg)
        {
            CheckAtg(inArg);
            string    projectionIdentify = inArg.ProjectionIdentify;
            OutputArg outArg             = new OutputArg();

            try
            {
                using (IRasterDataProvider inputRaster = GeoDataDriver.Open(inArg.InputFilename) as IRasterDataProvider)
                {
                    DataIdentify dataIdentify = inputRaster.DataIdentify;
                    outArg.OrbitFilename      = Path.GetFileName(inArg.InputFilename);
                    outArg.Satellite          = dataIdentify.Satellite;
                    outArg.Sensor             = dataIdentify.Sensor;
                    outArg.Level              = "L1";
                    outArg.ProjectionIdentify = projectionIdentify;
                    outArg.ObservationDate    = dataIdentify.OrbitDateTime.ToString("yyyyMMdd");
                    outArg.ObservationTime    = dataIdentify.OrbitDateTime.ToString("HHmm");
                    outArg.Station            = ParseStation(Path.GetFileName(inArg.InputFilename));
                    outArg.DayOrNight         = DayOrNight(inputRaster);
                    outArg.OrbitIdentify      = CalcOrbitIdentify(dataIdentify.OrbitDateTime, inArg.PervObservationDate, inArg.PervObservationTime, inArg.OrbitIdentify);
                    outArg.Length             = new FileInfo(inArg.InputFilename).Length;
                    string validEnvelopeMsg = "";
                    if (!string.IsNullOrWhiteSpace(inArg.DayNight))
                    {
                        if (inArg.DayNight != "daynight" && outArg.DayOrNight == "X")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "未设定处理白天和晚上数据,白天晚上标记未知:X";
                        }
                        else if (inArg.DayNight == "day" && outArg.DayOrNight != "D")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为只处理白天数据,当前数据标记为晚上";
                        }
                        else if (inArg.DayNight == "night" && outArg.DayOrNight != "N")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为只处理晚上数据,当前数据标记为白天";
                        }
                        else if (inArg.DayNight == "notnight" && outArg.DayOrNight == "N")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为不处理晚上数据,当前数据标记为晚上";
                        }
                        else if (inArg.DayNight == "notday" && outArg.DayOrNight == "D")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为不处理白天数据,当前数据标记为白天";
                        }
                    }
                    if (inArg.ValidEnvelopes == null || inArg.ValidEnvelopes.Length == 0)
                    {
                        outArg.LogLevel = "error";
                        outArg.LogInfo  = "参数错误:未正确设置ValidEnvelopes";
                    }
                    else if (!ValidEnvelope(inputRaster, inArg.ValidEnvelopes, out validEnvelopeMsg))
                    {
                        outArg.LogLevel = "info";
                        outArg.LogInfo  = validEnvelopeMsg;
                    }
                    else
                    {
                        GenericFilename genFilenmae = new GenericFilename();
                        PrjOutArg       prjArg;
                        if (inArg.Envelopes == null || inArg.Envelopes.Length == 0)
                        {
                            prjArg = new PrjOutArg(projectionIdentify, null, inArg.ResolutionX, inArg.ResolutionY, inArg.OutputDir);
                        }
                        else
                        {
                            prjArg = new PrjOutArg(projectionIdentify, inArg.Envelopes, inArg.ResolutionX, inArg.ResolutionY, inArg.OutputDir);
                        }
                        //prjArg.Args = new string[] { "SolarZenith"};
                        if (inArg.Bands != null && inArg.Bands.Length != 0)
                        {
                            prjArg.SelectedBands = inArg.Bands;
                            Console.WriteLine("SelectedBands:" + string.Join(",", prjArg.SelectedBands));
                        }
                        //扩展参数
                        List <string> extArgs = new List <string>();
                        extArgs.Add("IsClearPrjCache");
                        if (inArg.ExtArgs != null)
                        {
                            extArgs.AddRange(inArg.ExtArgs);
                        }
                        prjArg.Args = extArgs.ToArray();
                        ProjectionFactory prjFactory = new ProjectionFactory();
                        string            retMessage = "";
                        string[]          files      = prjFactory.Project(inputRaster, prjArg, new Action <int, string>(OnProgress), out retMessage);
                        prjFactory = null;
                        //投影结束,执行拼接,如果有拼接节点
                        List <OutFileArg> fileArgs = new List <OutFileArg>();
                        for (int i = 0; i < files.Length; i++)
                        {
                            string file = files[i];
                            if (string.IsNullOrWhiteSpace(file) || !File.Exists(file))
                            {
                                continue;
                            }
                            OutFileArg    fileArg = new OutFileArg();
                            CoordEnvelope env     = null;
                            float         resolutionX;
                            float         resolutionY;
                            string        overViewFilename = "";
                            using (IRasterDataProvider outfileRaster = GeoDataDriver.Open(file) as IRasterDataProvider)
                            {
                                overViewFilename = OverViewHelper.OverView(outfileRaster, _prjPngSize);
                                env         = outfileRaster.CoordEnvelope;
                                resolutionX = outfileRaster.ResolutionX;
                                resolutionY = outfileRaster.ResolutionY;
                                TryMosaicFile(inArg, outfileRaster, dataIdentify, outArg.DayOrNight);
                            }
                            fileArg.OutputFilename = Path.GetFileName(file);
                            fileArg.Thumbnail      = (string.IsNullOrWhiteSpace(overViewFilename) && File.Exists(overViewFilename) ? "" : Path.GetFileName(overViewFilename));
                            string solarZenithFile    = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".SolarZenith.ldf");
                            string solarZenithHdrFile = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".SolarZenith.hdr");
                            fileArg.ExtendFiles = Path.ChangeExtension(Path.GetFileName(file), "hdr") +
                                                  (string.IsNullOrWhiteSpace(solarZenithFile) && File.Exists(solarZenithFile) ? "" : "," + Path.GetFileName(solarZenithFile)) +
                                                  (string.IsNullOrWhiteSpace(solarZenithHdrFile) && File.Exists(solarZenithHdrFile) ? "" : "," + Path.GetFileName(solarZenithHdrFile));
                            fileArg.Envelope    = new PrjEnvelopeItem("GBAL", env == null ? null : new RasterProject.PrjEnvelope(env.MinX, env.MaxX, env.MinY, env.MaxY));
                            fileArg.ResolutionX = resolutionX.ToString();
                            fileArg.ResolutionY = resolutionY.ToString();
                            fileArg.Length      = new FileInfo(file).Length;
                            fileArgs.Add(fileArg);
                            if (inArg.IsOnlySaveMosaicFile)
                            {
                                TryDeleteFile(file);
                            }
                        }
                        outArg.OutputFiles = fileArgs.ToArray();
                        outArg.LogLevel    = "info";
                        if (string.IsNullOrWhiteSpace(retMessage))
                        {
                            outArg.LogInfo = "投影成功";
                        }
                        else
                        {
                            outArg.LogInfo = retMessage;
                        }
                        if (string.IsNullOrWhiteSpace(validEnvelopeMsg))
                        {
                            outArg.LogInfo = outArg.LogInfo + validEnvelopeMsg;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                outArg.LogLevel = "error";
                outArg.LogInfo  = ex.Message;
                LogFactory.WriteLine(ex);
            }
            finally
            {
                string outXmlFilename = Path.Combine(inArg.OutputDir, Path.GetFileName(inArg.InputFilename) + ".xml");
                OutputArg.WriteXml(outArg, outXmlFilename);
            }
        }
コード例 #10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="argument">
 /// 格式"*#*"冒号前面部分表示文件名称,冒号后面部分表示所选投影坐标的Wkt格式字符串
 /// </param>
 public override void Execute(string argument)
 {
     try
     {
         string            fileName  = "";
         string            prjString = "";
         ISpatialReference proj      = null;
         if (string.IsNullOrWhiteSpace(argument))
         {
             fileName = TryGetFileFromActiveView();
             proj     = SpatialReference.GetDefault();
         }
         else
         {
             MatchCollection matches = Regex.Matches(argument, @"(?<file>[^#]*)#(?<proj>.*)");
             fileName  = matches[0].Groups["file"].Value;
             prjString = matches[0].Groups["proj"].Value;
             if (string.IsNullOrWhiteSpace(fileName) || fileName.ToLower() == "null")
             {
                 fileName = TryGetFileFromActiveView();
             }
             if (string.IsNullOrWhiteSpace(prjString) || prjString.ToLower() == "null")
             {
                 proj = SpatialReference.GetDefault();
             }
             else
             {
                 proj = SpatialReference.FromWkt(prjString, enumWKTSource.EsriPrjFile);
             }
         }
         if (string.IsNullOrWhiteSpace(fileName))
         {
             throw new Exception("无法从参数中解析出文件名:" + argument);
         }
         PrjEnvelope envelope  = TryGetFirstAOI();
         PrjOutArg   prjOutArg = ProjectionFactory.GetDefaultArg(fileName);
         if (prjOutArg == null)
         {
             throw new Exception("暂未提供该支持");
         }
         if (envelope == null || envelope.IsEmpty)
         {
             envelope = prjOutArg.Envelopes[0] == null ? null : prjOutArg.Envelopes[0].PrjEnvelope;
         }
         if (envelope == null)
         {
             envelope = PrjEnvelope.CreateByCenter(105, 30, 10, 10);
         }
         //根据投影配置文件修改输出文件目录
         string outDir = null;
         if (TryGetOutDirFormConfig(out outDir))
         {
             prjOutArg.OutDirOrFile = outDir;
         }
         using (frmPrjEnvelopeSet frmPrjSetArgs = new frmPrjEnvelopeSet())
         {
             using (IRasterDataProvider file = FileHelper.Open(fileName))
             {
                 frmPrjSetArgs.SetDefault(file);
             }
             frmPrjSetArgs.SetArgs(proj, envelope, prjOutArg.ResolutionX, prjOutArg.ResolutionY, prjOutArg.OutDirOrFile);
             if (frmPrjSetArgs.ShowDialog() != DialogResult.OK)
             {
                 return;
             }
             prjOutArg = frmPrjSetArgs.PrjOutArg;
         }
         Project(fileName, proj, prjOutArg);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }