コード例 #1
0
ファイル: Mosaic.cs プロジェクト: windygu/hispeed
 /// <summary>
 /// 镶嵌
 /// </summary>
 /// <returns></returns>
 private void MosaicToFile()
 {
     using (IRasterDataProvider inputRaster = RasterDataDriver.Open(inArg.InputFilename) as IRasterDataProvider)
     {
         StringBuilder     str      = new StringBuilder();
         List <OutFileArg> outFiles = new List <OutFileArg>();
         string            logLevel = "info";
         if (inArg.MosaicEnvelopes == null)
         {
             logLevel = "error";
             str.AppendLine("镶嵌(Mosaic)必须指定镶嵌输出范围");
             return;
         }
         else
         {
             for (int i = 0; i < inArg.MosaicEnvelopes.Length; i++)
             {
                 PrjEnvelopeItem envItem = inArg.MosaicEnvelopes[i];
                 try
                 {
                     if (envItem == null)
                     {
                         str.AppendLine("镶嵌(Mosaic)必须指定镶嵌输出范围");
                         continue;
                     }
                     if (!ProjectionFactory.HasInvildEnvelope(inputRaster, envItem.PrjEnvelope))
                     {
                         str.AppendLine("数据不在范围内:" + envItem.Name + envItem.PrjEnvelope.ToString());
                         continue;
                     }
                     string mosaicFilename = GetSpliceFilename(inputRaster, inArg, envItem.Name);
                     mosaicFilename = Path.Combine(inArg.OutputDir, mosaicFilename);
                     if (!Directory.Exists(inArg.OutputDir))
                     {
                         Directory.CreateDirectory(inArg.OutputDir);
                     }
                     //文件不存在,则需要先创建目标文件。
                     IRasterDataProvider mosaicRaster = null;
                     if (!File.Exists(mosaicFilename))
                     {
                         mosaicRaster = CreateMosaicFile(inputRaster, envItem.PrjEnvelope, mosaicFilename);
                     }
                     else
                     {
                         mosaicRaster = RasterDataDriver.Open(mosaicFilename, enumDataProviderAccess.Update, null) as IRasterDataProvider;
                     }
                     if (File.Exists(mosaicFilename))
                     {
                         OutFileArg fileArg = new OutFileArg();
                         try
                         {
                             Mosaic(inputRaster, mosaicRaster);
                             fileArg.Envelope       = new PrjEnvelopeItem(envItem.Name, envItem.PrjEnvelope);
                             fileArg.ResolutionX    = mosaicRaster.ResolutionX.ToString();
                             fileArg.ResolutionY    = mosaicRaster.ResolutionY.ToString();
                             fileArg.OutputFilename = mosaicFilename;
                             fileArg.Length         = new FileInfo(mosaicFilename).Length;
                         }
                         finally
                         {
                             if (mosaicRaster != null)
                             {
                                 mosaicRaster.Dispose();
                             }
                         }
                         try
                         {
                             string tHdrFilename      = FilenameIdentify.HdrFileName(mosaicFilename);
                             string tOverviewFilename = FilenameIdentify.OverviewFileName(mosaicFilename);
                             if (File.Exists(mosaicFilename))
                             {
                                 tOverviewFilename = OverViewHelper.OverView(mosaicFilename, _mosaicSize);
                                 fileArg.Thumbnail = Path.GetFileName(tOverviewFilename);
                             }
                             if (File.Exists(tHdrFilename))
                             {
                                 fileArg.ExtendFiles = Path.GetFileName(tHdrFilename);
                             }
                         }
                         catch (Exception ex)
                         {
                             str.AppendLine("拼接完成后,生成缩略图失败" + ex.Message);
                         }
                         outFiles.Add(fileArg);
                     }
                 }
                 catch (Exception ex)
                 {
                     logLevel = "error";
                     str.AppendLine("镶嵌区域失败:" + envItem.Name + envItem.PrjEnvelope.ToString());
                     str.AppendLine(" 输入文件:" + inArg.InputFilename);
                     str.AppendLine(" 详细信息:" + ex.Message);
                     GeoDo.Tools.LogFactory.WriteLine(ex);
                 }
                 finally
                 {
                 }
             }
         }
         //写输出参数。
         MosaicOutputArg outArg = new MosaicOutputArg();
         outArg.InputFilename = Path.GetFileName(inArg.InputFilename);
         outArg.OutputFiles   = outFiles.ToArray();
         outArg.LogLevel      = logLevel;
         outArg.LogInfo       = str.ToString();
         string outXml = FilenameIdentify.OutPutXmlFilename(inArg.OutputDir, inArg.InputFilename);
         outArg.ToXml(outXml);
     }
 }
コード例 #2
0
ファイル: Execute.cs プロジェクト: windygu/hispeed
        public void Do(string xmlArg)
        {
            BlockArg inArg = BlockArg.ParseXml(xmlArg);

            string outDir = inArg.OutputDir;
            IRasterDataProvider inRaster = null;
            OutputArg           outArg   = new OutputArg();

            try
            {
                CheckArg(inArg);
                BlockDef[] blocks = GenericBlock(inArg);
                inRaster = GeoDataDriver.Open(inArg.InputFilename) as IRasterDataProvider;
                DataIdentify dataIdentify = inRaster.DataIdentify;
                outArg.OrbitFilename      = Path.GetFileName(inArg.InputFilename);
                outArg.Satellite          = dataIdentify.Satellite;
                outArg.Sensor             = dataIdentify.Sensor;
                outArg.Level              = "L1";
                outArg.ProjectionIdentify = ParseProjectionIdentify(Path.GetFileName(inArg.InputFilename));
                outArg.ObservationDate    = dataIdentify.OrbitDateTime.ToString("yyyyMMdd");
                outArg.ObservationTime    = dataIdentify.OrbitDateTime.ToString("HHmm");
                outArg.Station            = ParseStation(Path.GetFileName(inArg.InputFilename));
                List <FileArg> fileArgs   = new List <FileArg>();
                string         retMessage = "";
                for (int blockIndex = 0; blockIndex < blocks.Length; blockIndex++)
                {
                    BlockDef blockDef = blocks[blockIndex];
                    if (blocks == null)
                    {
                        continue;
                    }
                    CoordEnvelope       oEnvelope       = inRaster.CoordEnvelope;
                    CoordEnvelope       tEnvelope       = blockDef.ToEnvelope();
                    IRasterDataProvider outBlockRasters = null;
                    try
                    {
                        if (!IsInteractived(oEnvelope, tEnvelope))
                        {
                            continue;
                        }
                        double validPercent = 0;
                        outBlockRasters = _rasterClipProcess.Clip(inRaster, blockDef, 100, "LDF", outDir, new Action <int, string>(OnProgress), out validPercent);
                        if (outBlockRasters == null)
                        {
                            continue;
                        }
                        if (validPercent == 0)
                        {
                            string filename = outBlockRasters.fileName;
                            outBlockRasters.Dispose();
                            outBlockRasters = null;
                            TryDeleteLdfFiles(filename);
                            continue;
                        }
                        IRasterDataProvider outfileRaster = outBlockRasters;
                        string        overViewFilename    = OverViewHelper.OverView(outfileRaster, _blockPngSize);
                        FileArg       fileArg             = new FileArg();
                        CoordEnvelope env = null;
                        float         resolutionX;
                        float         resolutionY;
                        env                    = outfileRaster.CoordEnvelope;
                        resolutionX            = outfileRaster.ResolutionX;
                        resolutionY            = outfileRaster.ResolutionY;
                        fileArg.OutputFilename = Path.GetFileName(outfileRaster.fileName);
                        fileArg.Thumbnail      = (string.IsNullOrWhiteSpace(overViewFilename) ? "" : Path.GetFileName(overViewFilename));
                        fileArg.ExtendFiles    = Path.ChangeExtension(Path.GetFileName(outfileRaster.fileName), "hdr");
                        fileArg.Envelope       = new PrjEnvelopeItem(blockDef.Name, 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(outfileRaster.fileName).Length;
                        fileArgs.Add(fileArg);
                    }
                    catch (Exception ex)
                    {
                        retMessage += (ex.Message + " Block:" + blockDef.Name + tEnvelope == null ? "" : tEnvelope.ToString());
                    }
                    finally
                    {
                        if (outBlockRasters != null)
                        {
                            if (outBlockRasters != null)
                            {
                                outBlockRasters.Dispose();
                            }
                        }
                    }
                }
                outArg.OutputFiles = fileArgs.ToArray();
                outArg.LogLevel    = "info";
                if (string.IsNullOrWhiteSpace(retMessage))
                {
                    outArg.LogInfo = "分幅成功";
                }
                else
                {
                    outArg.LogInfo = retMessage;
                }
            }
            catch (Exception ex)
            {
                LogFactory.WriteLine(ex);
                outArg.LogLevel = "error";
                outArg.LogInfo  = ex.Message;
                Console.WriteLine(ex.Message);
            }
            finally
            {
                string outXmlFilename = Path.Combine(inArg.OutputDir, Path.GetFileName(inArg.InputFilename) + ".xml");
                OutputArg.WriteXml(outArg, outXmlFilename);
                if (inRaster != null)
                {
                    inRaster.Dispose();
                }
            }
        }
コード例 #3
0
ファイル: Mosaic.cs プロジェクト: windygu/hispeed
 /// <summary>
 /// 拼接
 /// 需要保证tFilename不存在。
 /// </summary>
 private void SpliceToFile()
 {
     using (IRasterDataProvider inputRaster = RasterDataDriver.Open(inArg.InputFilename) as IRasterDataProvider)
     {
         StringBuilder     str      = new StringBuilder();
         List <OutFileArg> outFiles = new List <OutFileArg>();
         string            logLevel = "info";
         foreach (PrjEnvelopeItem envItem in inArg.MosaicEnvelopes)
         {
             try
             {
                 if (!ProjectionFactory.HasInvildEnvelope(inputRaster, envItem.PrjEnvelope))
                 {
                     str.AppendLine("数据不在范围内:" + envItem.Name + envItem.PrjEnvelope.ToString());
                     continue;
                 }
                 string tFilename = GetSpliceFilename(inputRaster, inArg, envItem.Name);
                 tFilename = Path.Combine(inArg.OutputDir, tFilename);
                 if (!Directory.Exists(inArg.OutputDir))
                 {
                     Directory.CreateDirectory(inArg.OutputDir);
                 }
                 //文件不存在,直接复制当前文件为目标文件
                 if (!File.Exists(tFilename))
                 {
                     File.Copy(inArg.InputFilename, tFilename);
                     OutFileArg fileArg           = new OutFileArg();
                     string     tHdrFilename      = FilenameIdentify.HdrFileName(tFilename);
                     string     tOverviewFilename = FilenameIdentify.OverviewFileName(tFilename);
                     fileArg.Envelope       = new PrjEnvelopeItem(envItem.Name, CoordToEnvelope(inputRaster.CoordEnvelope));
                     fileArg.ResolutionX    = inputRaster.ResolutionX.ToString();
                     fileArg.ResolutionY    = inputRaster.ResolutionY.ToString();
                     fileArg.OutputFilename = tFilename;
                     fileArg.Length         = new FileInfo(tFilename).Length;
                     if (File.Exists(FilenameIdentify.HdrFileName(inArg.InputFilename)))
                     {
                         File.Copy(FilenameIdentify.HdrFileName(inArg.InputFilename), tHdrFilename);
                         fileArg.ExtendFiles = Path.GetFileName(tHdrFilename);
                     }
                     if (File.Exists(FilenameIdentify.OverviewFileName(inArg.InputFilename)))
                     {
                         File.Copy(FilenameIdentify.OverviewFileName(inArg.InputFilename), tOverviewFilename);
                         fileArg.Thumbnail = Path.GetFileName(tOverviewFilename);
                     }
                     else if (File.Exists(tFilename))
                     {
                         OnProgress(0, "生成缩略图");
                         tOverviewFilename = OverViewHelper.OverView(tFilename, _mosaicSize);
                         OnProgress(100, "完成缩略图");
                         fileArg.Thumbnail = Path.GetFileName(tOverviewFilename);
                     }
                     outFiles.Add(fileArg);
                 }
                 else
                 {
                     OutFileArg fileArg = SpliceToExistFile(inputRaster, tFilename);
                     fileArg.Envelope.Name = envItem.Name;
                     outFiles.Add(fileArg);
                 }
             }
             catch (Exception ex)
             {
                 logLevel = "error";
                 str.AppendLine("拼接区域失败:" + envItem.Name + envItem.PrjEnvelope.ToString());
                 str.AppendLine(" 输入文件:" + inArg.InputFilename);
                 str.AppendLine(" 详细信息:" + ex.Message);
                 GeoDo.Tools.LogFactory.WriteLine(ex);
             }
         }
         //写输出参数。
         MosaicOutputArg outArg = new MosaicOutputArg();
         outArg.InputFilename = Path.GetFileName(inArg.InputFilename);
         outArg.OutputFiles   = outFiles.ToArray();
         outArg.LogLevel      = logLevel;
         outArg.LogInfo       = str.ToString();
         string outXml = FilenameIdentify.OutPutXmlFilename(inArg.OutputDir, inArg.InputFilename);
         outArg.ToXml(outXml);
     }
 }
コード例 #4
0
ファイル: Mosaic.cs プロジェクト: windygu/hispeed
        ///将inputRaster拼接到tFilename。
        private OutFileArg SpliceToExistFile(IRasterDataProvider inputRaster, string tFilename)
        {
            OutFileArg fileArg     = new OutFileArg();
            string     tmpDir      = Path.GetDirectoryName(tFilename);
            string     tmpFilename = CreateTempFilename(tmpDir);

            try
            {
                using (IRasterDataProvider tRaster = RasterDataDriver.Open(tFilename) as IRasterDataProvider)
                {
                    if (inputRaster.BandCount != tRaster.BandCount)
                    {
                        throw new ExceptionExt(2, "待拼接文件和目标文件的波段数不同,无法完成文件拼接[" + inputRaster.fileName + "]" + "[" + tFilename + "]");
                    }
                    CoordEnvelope tEnv      = inputRaster.CoordEnvelope.Union(tRaster.CoordEnvelope);
                    PrjEnvelope   tEnvelope = CoordToEnvelope(tEnv);
                    using (IRasterDataProvider tmpFileRaster = CreateMosaicFile(inputRaster, tEnvelope, tmpFilename))
                    {
                        RasterMoasicProcesser mo = new RasterMoasicProcesser();
                        mo.Moasic(new IRasterDataProvider[] { inputRaster, tRaster }, tmpFileRaster, true, new string[] { "0" }, action);
                        fileArg.Envelope    = new PrjEnvelopeItem("", tEnvelope);
                        fileArg.ResolutionX = tmpFileRaster.ResolutionX.ToString();
                        fileArg.ResolutionY = tmpFileRaster.ResolutionY.ToString();
                    }
                }
                if (File.Exists(tmpFilename))
                {
                    try
                    {
                        string tmpHdrFilename      = FilenameIdentify.HdrFileName(tmpFilename);
                        string tmpOverviewFilename = FilenameIdentify.OverviewFileName(tmpFilename);
                        string tHdrFilename        = FilenameIdentify.HdrFileName(tFilename);
                        string tOverviewFilename   = FilenameIdentify.OverviewFileName(tFilename);
                        File.Delete(tFilename);//删除原文件
                        if (File.Exists(tHdrFilename))
                        {
                            File.Delete(tHdrFilename);
                        }
                        if (File.Exists(tOverviewFilename))
                        {
                            File.Delete(tOverviewFilename);
                        }
                        //拼接后的文件重命名为目标文件
                        File.Move(tmpFilename, tFilename);
                        fileArg.OutputFilename = Path.GetFileName(tFilename);
                        fileArg.Length         = new FileInfo(tFilename).Length;
                        if (File.Exists(tmpHdrFilename))
                        {
                            File.Move(tmpHdrFilename, tHdrFilename);
                            fileArg.ExtendFiles = Path.GetFileName(tHdrFilename);
                        }
                        if (File.Exists(tmpOverviewFilename))
                        {
                            File.Move(tmpOverviewFilename, tOverviewFilename);
                            fileArg.Thumbnail = Path.GetFileName(tOverviewFilename);
                        }
                        else if (File.Exists(tFilename))
                        {
                            OnProgress(0, "生成缩略图");
                            tOverviewFilename = OverViewHelper.OverView(tFilename, _mosaicSize);
                            OnProgress(100, "完成缩略图");
                            fileArg.Thumbnail = Path.GetFileName(tOverviewFilename);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("拼接完成后,重命名新拼接文件失败。" + ex.Message, ex);
                    }
                }
                return(fileArg);
            }
            finally
            {
                TryDeleteLdfs(tmpFilename);
            }
        }
コード例 #5
0
        private void TryMosaicFile(InputArg inArg, AbstractWarpDataset fileRaster, RasterDatasetInfo dataIdentify,
                                   DateTime dateTime, string dayOrNight)
        {
            if (inArg.MosaicInputArg == null || string.IsNullOrWhiteSpace(inArg.MosaicInputArg.OutputDir) ||
                inArg.MosaicInputArg.Envelope == null)
            {
                return;
            }
            //if (!Day.Contains(dayOrNight))
            //{
            //    Console.WriteLine("非白天数据,不执行拼接");
            //    return;
            //}
            MosaicInputArg  mosaicInputArg     = inArg.MosaicInputArg;
            string          projectionIdentify = inArg.ProjectionIdentify;
            string          station            = ParseStation(inArg.InputFilename);
            MosaicOutputArg outArg             = new MosaicOutputArg();

            outArg.Satellite          = dataIdentify.SatelliteID;
            outArg.Sensor             = dataIdentify.SensorID;
            outArg.Level              = "L1";
            outArg.ProjectionIdentify = projectionIdentify;
            outArg.ObservationDate    = dateTime.ToString("yyyyMMdd");
            outArg.Station            = station;
            outArg.DayOrNight         = dayOrNight;
            AbstractWarpDataset mosaicFileRaster = null;

            try
            {
                string mosaicFilename = CreateMosaicFilename(inArg, dataIdentify, dateTime, projectionIdentify,
                                                             fileRaster.ResolutionX, station, dayOrNight);
                mosaicFilename = Path.Combine(mosaicInputArg.OutputDir, mosaicFilename);
                Mosaic mosaic = new Mosaic(inArg, fileRaster, new Action <int, string>(OnProgress));
                mosaicFileRaster = mosaic.MosaicToFile(mosaicFilename);
                OutFileArg fileArg = new OutFileArg();
                if (mosaicFileRaster != null)
                {
                    OnProgress(0, "生成缩略图");
                    string overViewFilename = OverViewHelper.OverView(mosaicFileRaster, 1024);
                    OnProgress(100, "完成缩略图");
                    fileArg.Envelope       = mosaicInputArg.Envelope;
                    fileArg.ResolutionX    = mosaicFileRaster.ResolutionX.ToString();
                    fileArg.ResolutionY    = mosaicFileRaster.ResolutionY.ToString();
                    fileArg.OutputFilename = Path.GetFileName(mosaicFileRaster.fileName);
                    fileArg.Thumbnail      = (string.IsNullOrWhiteSpace(overViewFilename)
                        ? ""
                        : Path.GetFileName(overViewFilename));
                    fileArg.ExtendFiles = Path.ChangeExtension(Path.GetFileName(mosaicFileRaster.fileName), "hdr");
                    fileArg.Length      = new FileInfo(mosaicFileRaster.fileName).Length;
                }

                outArg.OutputFiles = new OutFileArg[] { fileArg };
                outArg.LogLevel    = "info";
                outArg.LogInfo     = "拼接完成";
            }
            catch (Exception ex)
            {
                outArg.LogLevel = "error";
                outArg.LogInfo  = ex.Message;
            }
            finally
            {
                if (mosaicFileRaster != null)
                {
                    mosaicFileRaster.Dispose();
                }
                string outXmlFilename = Path.Combine(inArg.MosaicInputArg.OutputDir,
                                                     Path.GetFileName(inArg.InputFilename) + ".xml");
                MosaicOutputArg.WriteXml(outArg, outXmlFilename);
            }
        }
コード例 #6
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);
            }
        }
コード例 #7
0
ファイル: PeriodicComputeAlg.cs プロジェクト: windygu/hispeed
        //计算统计结果
        private void StatisticNext(int statistic, string dirNext, string outnamePrefix, string[] filenames, RasterStatics sta, string flabel, Action <int, string> progressCallback = null)
        {
            try
            {
                StringBuilder outstaname = new StringBuilder();
                string        outname    = "";
                switch (statistic)
                {
                case 0:
                    outstaname.Append(dirNext).Append("\\").Append(outnamePrefix).Append("MAX").Append(flabel);
                    outname = outstaname.ToString();
                    break;

                case 1:
                    outstaname.Append(dirNext).Append("\\").Append(outnamePrefix).Append("MIN").Append(flabel);
                    outname = outstaname.ToString();
                    break;

                case 2:
                    outstaname.Append(dirNext).Append("\\").Append(outnamePrefix).Append("AVG").Append(flabel);
                    outname = outstaname.ToString();
                    break;
                }
                if (progressCallback != null)
                {
                    progressCallback(-1, "\t\t\t\t输出文件:" + outname);
                }
                if (File.Exists(outname))
                {
                    if (_overwritefiles == false && _con.IshasRecord(_tableName, "ImageName", Path.GetFileName(outname)))
                    {
                        if (!File.Exists(Path.Combine(Path.GetDirectoryName(outname), Path.ChangeExtension(outname, ".overview.png"))))
                        {
                            OverViewHelper.OverView(outname, 800);
                        }
                        if (progressCallback != null)
                        {
                            progressCallback(-1, "\t\t\t文件已存在,跳过合成处理!");// + Path.GetFileName(outname));
                        }
                        return;
                    }
                    else
                    {
                        File.Delete(outname);
                        if (progressCallback != null)
                        {
                            progressCallback(-1, "\t\t\t重新合成处理开始...");//+ Path.GetFileName(outname));
                        }
                    }
                }
                string outdir = Path.GetDirectoryName(outname);
                if (!Directory.Exists(outdir))
                {
                    Directory.CreateDirectory(outdir);
                }
                if ((statistic == 0 && !sta.PeriodicMaxStat(filenames, outname, progressCallback)) || (statistic == 1 && !sta.PeriodicMinStat(filenames, outname, progressCallback)) ||
                    (statistic == 2 && !sta.PeriodicAvgStat(filenames, outname, null, progressCallback)))
                {
                    if (progressCallback != null)
                    {
                        progressCallback(-1, "\t\t\t\t合成处理失败!");//+ Path.GetFileName(outname));
                    }
                    if (File.Exists(outname))
                    {
                        File.Delete(outname);
                        if (progressCallback != null)
                        {
                            progressCallback(-1, "\t\t\t\t删除合成失败文件!");// + outname);
                        }
                    }
                    return;
                }
                if (File.Exists(outname))
                {
                    //生成快视图
                    string filename = OverViewHelper.OverView(outname, 800);
                    if (progressCallback != null && File.Exists(filename))
                    {
                        progressCallback(-1, "\t\t\t\t生成快视图成功!");// + Path.GetFileName(outname));
                    }
                    if (!_con.IshasRecord(_tableName, "ImageName", Path.GetFileName(outname)))
                    {
                        TryCreatePeriodRecord(outname, progressCallback);
                        if (progressCallback != null && File.Exists(filename))
                        {
                            progressCallback(-1, "\t\t\t\t入库成功!");// + Path.GetFileName(outname));
                        }
                    }
                    else
                    {
                        if (progressCallback != null && File.Exists(filename))
                        {
                            progressCallback(-1, "\t\t\t\t数据库记录已存在,入库跳过!");// + Path.GetFileName(outname));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (progressCallback != null)
                {
                    progressCallback(-5, "合成" + dirNext + "的产品失败!" + e.Message);
                }
                throw e;
            }
        }
コード例 #8
0
ファイル: PeriodicComputeAlg.cs プロジェクト: windygu/hispeed
 private void StatisticTen(string dirXun, StringBuilder outnamePrefix, string[] filesSelect, RasterStatics sta, string resl, string label = "day", Action <int, string> progressCallback = null)
 {
     try
     {
         string        flabel         = string.Format("_{0}_{1}.LDF", label, resl);
         int           statistic      = -1;
         StringBuilder outnamebuilder = new StringBuilder();
         string        outname        = "";
         foreach (string stype in _statics)
         {
             outnamebuilder.Clear();
             if (_statics.Contains("MAX") || _statics.Contains("max"))
             {
                 statistic = 0;
                 outnamebuilder.Append(dirXun).Append("\\Max\\").Append(outnamePrefix.ToString()).Append("_MAX").Append(flabel);
                 outname = outnamebuilder.ToString();
             }
             else if (_statics.Contains("MIN") || _statics.Contains("min"))
             {
                 statistic = 1;
                 outnamebuilder.Append(dirXun).Append("\\Min\\").Append(outnamePrefix.ToString()).Append("_MIN").Append(flabel);
                 outname = outnamebuilder.ToString();
             }
             else if (_statics.Contains("AVG") || _statics.Contains("avg"))
             {
                 statistic = 2;
                 outnamebuilder.Append(dirXun).Append("\\Avg\\").Append(outnamePrefix.ToString()).Append("_AVG").Append(flabel);
                 outname = outnamebuilder.ToString();
             }
             if (progressCallback != null)
             {
                 progressCallback(-1, "\t\t\t\t开始合成" + stype + "旬产品,输出文件:" + outname);
             }
             if (File.Exists(outname))
             {
                 if (_overwritefiles == false && _con.IshasRecord(_tableName, "ImageName", Path.GetFileName(outname)))
                 {
                     if (!File.Exists(Path.Combine(Path.GetDirectoryName(outname), Path.ChangeExtension(outname, ".overview.png"))))
                     {
                         OverViewHelper.OverView(outname, 800);
                     }
                     if (progressCallback != null)
                     {
                         progressCallback(-1, "\t\t\t\t文件已存在,跳过合成处理!");//+ Path.GetFileName(outname)
                     }
                     continue;
                 }
                 else
                 {
                     File.Delete(outname);
                     if (progressCallback != null)
                     {
                         progressCallback(-1, "\t\t\t\t重新合成处理开始..."); //+ Path.GetFileName(outname)
                     }
                 }
             }
             if (!Directory.Exists(Path.GetDirectoryName(outname)))
             {
                 Directory.CreateDirectory(Path.GetDirectoryName(outname));
             }
             if ((statistic == 0 && !sta.PeriodicMaxStat(filesSelect, outname, progressCallback)) || (statistic == 1 && !sta.PeriodicMinStat(filesSelect, outname, progressCallback)) ||
                 (statistic == 2 && !sta.PeriodicAvgStat(filesSelect, outname, null, progressCallback)))
             {
                 if (progressCallback != null)
                 {
                     progressCallback(-1, "\t\t\t\t合成处理失败!");// + Path.GetFileName(outname));
                 }
                 if (File.Exists(outname))
                 {
                     File.Delete(outname);
                     if (progressCallback != null)
                     {
                         progressCallback(-1, "\t\t\t\t删除合成失败文件!");// + Path.GetFileName(outname));
                     }
                 }
                 continue;
             }
             if (File.Exists(outname))
             {
                 //生成快视图
                 string filename = OverViewHelper.OverView(outname, 800);
                 if (progressCallback != null && File.Exists(filename))
                 {
                     progressCallback(-1, "\t\t\t\t生成快视图成功!");// 文件:+ Path.GetFileName(outname));
                 }
                 if (!_con.IshasRecord(_tableName, "ImageName", Path.GetFileName(outname)))
                 {
                     TryCreatePeriodRecord(outname, progressCallback);
                     if (progressCallback != null && File.Exists(filename))
                     {
                         progressCallback(-1, "\t\t\t\t入库成功!");//文件:+ Path.GetFileName(outname));
                     }
                 }
                 else
                 {
                     if (progressCallback != null && File.Exists(filename))
                     {
                         progressCallback(-1, "\t\t\t\t数据库记录已存在,入库跳过!");//文件:+ Path.GetFileName(outname));
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         if (progressCallback != null)
         {
             progressCallback(-5, "合成" + dirXun + "的旬产品失败!" + e.Message);
         }
         throw e;
     }
 }
コード例 #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);
            }
        }