private bool ValidEnvelope(IRasterDataProvider inputRaster, PrjEnvelopeItem[] validEnvelopes, out string msg) { bool hasValid = false; StringBuilder str = new StringBuilder(); PrjEnvelope fileEnv = ProjectionFactory.GetEnvelope(inputRaster); foreach (PrjEnvelopeItem validEnvelope in validEnvelopes) { hasValid = ProjectionFactory.HasInvildEnvelope(inputRaster, validEnvelope.PrjEnvelope); if (!hasValid) { str.AppendLine("数据不在范围内:" + validEnvelope.Name + validEnvelope.PrjEnvelope.ToString()); } } msg = str.ToString(); return(hasValid); }
private bool ValidEnvelope(IRasterDataProvider inputRaster, PrjEnvelopeItem[] validEnvelopes, out string msg) { bool hasValid = false; StringBuilder str = new StringBuilder(); foreach (PrjEnvelopeItem validEnvelope in validEnvelopes) { if (!ProjectionFactory.HasInvildEnvelope(inputRaster, validEnvelope.PrjEnvelope)) { str.AppendLine("数据不在范围内:" + validEnvelope.Name + validEnvelope.PrjEnvelope.ToString()); } else { hasValid = true;//只要这块数据在一个有效区域内,就返回true,执行整块数据投影。 } } msg = str.ToString(); return(hasValid); }
/// <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); } }
/// <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); } }