private static void DisplayFileResult(IMonitoringSubProduct subProduct, ISmartSession session, IExtractResult restult) { string filename = (restult as IFileExtractResult).FileName; RecordFileForAfterProcess(filename); IFileExtractResult fileResult = restult as IFileExtractResult; if (fileResult.Add2Workspace) { TrySaveFileToWorkspace(subProduct, session, filename, restult, null); } if (!(restult as IExtractResultBase).Display) { return; } if (NeedOpenFile()) { object obj = subProduct.ArgumentProvider.GetArg("fileOpenArgs"); string[] args = null; if (obj != null && !string.IsNullOrEmpty(obj.ToString())) { args = new string[] { obj.ToString() } } ; ICommand cmd = session.CommandEnvironment.Get(2000); if (cmd != null) { cmd.Execute(filename, args); } } }
private IExtractResultArray CalcGFRF(string[] files) { string datFname = GetDatFilename(files); string GFInfoList = GenGFILfname(files); using (StreamWriter sw = new StreamWriter(GFInfoList, false, Encoding.Default)) { sw.WriteLine("NO.\t" + "Latitude\t" + "Longitude\t" + "Size/ha\t" + "Temperature/K\t" + "Fire_Intensity\t" + "Reliability"); } int[,] fireCountArray = InitValueArray(); int[] firPositionArray = null; for (int i = 0; i < files.Length; i++) { firPositionArray = ProcessVectorToArray(files[i], GFInfoList); int col, row; foreach (int cr in firPositionArray) { row = cr / _datwidth; col = (cr % _datwidth); fireCountArray[row, col] += 1; } } _firePointsCount = 0; ProcessArrayToRaster(datFname, fireCountArray); _argumentProvider.SetArg("SelectedPrimaryFiles", datFname); IFileExtractResult GFRF = GFRFAlgorithm() as IFileExtractResult; IExtractResultArray array = new ExtractResultArray("全球火点累计"); IFileExtractResult GFIL = new FileExtractResult("GFIL", GFInfoList, true); GFIL.SetDispaly(false); array.Add(GFRF); array.Add(GFIL); return(array); }
private IFileExtractResult[] GreateFLODFile(string[] dblvFiles, Action <int, string> progressTracker) { if (dblvFiles == null || dblvFiles.Length < 2) { return(null); } string[] sortedFiles = SortFileName(dblvFiles); IFileExtractResult flodFile = null; List <IFileExtractResult> flodFiles = new List <IFileExtractResult>(); for (int i = 1; i < sortedFiles.Length; i++) { flodFile = CompareDATFile(sortedFiles[i - 1], sortedFiles[i]); if (flodFile != null && !string.IsNullOrEmpty(flodFile.FileName)) { flodFiles.Add(flodFile); } } return(flodFiles.Count == 0 ? null : flodFiles.ToArray()); }
private IExtractResult TauL55Algorithm() { IFileExtractResult U5TTResult = null; string instanceIdentify = _argumentProvider.GetArg("OutFileIdentify") as string; if (string.IsNullOrWhiteSpace(instanceIdentify)) { return(null); } SubProductInstanceDef instance = FindSubProductInstanceDefs(instanceIdentify); if (instance != null) { U5TTResult = ThemeGraphyResult(null) as IFileExtractResult; IExtractResultArray array = new ExtractResultArray("气溶胶产品"); IFileExtractResult U5TIResult = new FileExtractResult("U5TI", _055TauFname, true); U5TIResult.SetDispaly(false); array.Add(U5TTResult); array.Add(U5TIResult); return(array); } return(null); }
private IExtractResult SnowDepthAlgorithm() { if (_argumentProvider.DataProvider == null) { return(null); } string currentFile = _argumentProvider.DataProvider.fileName; string dblvFile = _argumentProvider.GetArg("SelectedPrimaryFiles").ToString(); if (string.IsNullOrEmpty(dblvFile)) { return(null); } IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster; int shortInfraredCH = TryGetBandNo(bandNameRaster, "ShortInfrared"); int visibleCH = TryGetBandNo(bandNameRaster, "Visible"); if (shortInfraredCH == -1 || visibleCH == -1) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } //china_dem_500m.raw string systemDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemData\\ProductArgs\\SNW\\SnowArgFile"); string roughnessFile = Path.Combine(systemDir, "china_roughness_500m.dat"); string demFile = Path.Combine(systemDir, "china_dem_500m.raw"); if (!File.Exists(roughnessFile)) { if (!File.Exists(demFile)) { PrintInfo("积雪深度所用参数文件不存在!"); return(null); } //计算粗糙度文件; else { ComputeRoughnessFile(demFile, roughnessFile); } } if (_argumentProvider.GetArg("DepthArgs") == null) { PrintInfo("积雪深度参数获取失败!"); return(null); } string[] depthArgs = _argumentProvider.GetArg("DepthArgs") as string[]; if (depthArgs == null || depthArgs.Length < 9) { PrintInfo("积雪深度参数获取失败!"); return(null); } bool isCorrectAngle = (bool)_argumentProvider.GetArg("isCorrectAngle"); string angleFile = depthArgs[0]; if (!isCorrectAngle || string.IsNullOrEmpty(angleFile) || !File.Exists(angleFile)) { angleFile = null; } //计算雪深 IFileExtractResult depthResult = ComputeDepthRaster(currentFile, dblvFile, roughnessFile, angleFile, visibleCH, shortInfraredCH, depthArgs); return(depthResult); }
private IExtractResult SnowPrdAlgorithm() { string inputFileName = _argumentProvider.DataProvider.fileName; if (string.IsNullOrEmpty(inputFileName) || !File.Exists(inputFileName)) { return(null); } int[] bandNos = CheckBandNos(); if (bandNos == null || bandNos.Length < 10) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } double[] sdParas = GetSDPara(); if (sdParas == null) { PrintInfo("雪深计算参数为空。"); return(null); } //查找参数数据 string argFileDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemData\\ProductArgs\\SNW\\SnowArgFile"); string fileNameBare = Path.Combine(argFileDir, "china_bares.dat"); string filenameGrass = Path.Combine(argFileDir, "china_grass.dat"); string filenameForest = Path.Combine(argFileDir, "china_forest.dat"); string filenameFarmhand = Path.Combine(argFileDir, "china_farmhand.dat"); string filenameDensity = Path.Combine(argFileDir, "china_snow_density.dat"); if (!File.Exists(filenameDensity)) { return(null); } //1、查找是否存在各土地类型百分比文件(4个),不存在则生成 string bareFracFile = Path.ChangeExtension(fileNameBare, "_frac.dat"); string grassFracFile = Path.ChangeExtension(filenameGrass, "_frac.dat"); string forestFracFile = Path.ChangeExtension(filenameForest, "_frac.dat"); string farmhandFracFile = Path.ChangeExtension(filenameFarmhand, "_frac.dat"); string[] argFiles = new string[] { bareFracFile, grassFracFile, forestFracFile, farmhandFracFile }; foreach (string file in argFiles) { string sumFile = null; if (!File.Exists(file)) { //计算 //1)生成SummaryFile(不存在) sumFile = GetArgSummaryFile(fileNameBare, filenameGrass, filenameForest, filenameFarmhand); //2)计算某个百分比文件 ComputeFracFile(sumFile, file); } } //2、计算雪深、雪水当量 //雪深 IExtractResultArray array = new ExtractResultArray("雪深当量"); IFileExtractResult depthResult = ComputeSnowDepth(inputFileName, bandNos, argFiles, sdParas); //雪水当量 if (!File.Exists(filenameDensity)) { return(null); } string depthFileName = (depthResult as FileExtractResult).FileName; if (!File.Exists(depthFileName)) { return(null); } IFileExtractResult sweResult = ComputeSnowSWE(filenameDensity, depthFileName); array.Add(depthResult); array.Add(sweResult); return(array); }
private IExtractResult HistoryDataStatAlgorithm(Action <int, string> progressTracker) { //1、获取数据 List <string> list = ExportManager.GetInstance().List; string[] fname = list.ToArray(); //再加一上基于 同期统计数据 StatisticResultManager manager = StatisticResultManager.GetInstance(); List <string> list2 = manager.GetFilePathFromList(); //得到的是基于数据查询的数据又做的统计数据 if (list2.Count != 0) { fname = list2.ToArray(); period = "yes"; Match m = DataReg2.Match(fname[0]); if (m.Success) { Iswinter = "yes"; } } //这里要对文件进行一下裁切//处理后的数据存储路径 string savePath = _argumentProvider.GetArg("HistoryDataSave") as string; regionNames = _argumentProvider.GetArg("regionNames") as string; string orbitType = _argumentProvider.GetArg("OrbitType") as string; string Str = null; if (orbitType == "Ascend") { Str = "_A_"; } if (orbitType == "Descend") { Str = "_D_"; } //同期统计计算传出来的文件没有分升降轨,这里进行区分 List <string> fnamelist = new List <string>(); foreach (string file in fname) { if (Path.GetFileName(file).Contains(Str)) { fnamelist.Add(file); } } fname = fnamelist.ToArray(); //2.确定选择区域,没有选或者中国区域不要用裁,如果是其地区首先裁切,并且放到指定文件夹下 aoiContainer = new GeoDo.RSS.Core.VectorDrawing.AOIContainerLayer(); MulRegionsClip muticlip = new MulRegionsClip(); //裁切 string regionsname = ""; IStatResult fresult = null; using (frmStatSubRegionTemplates frm = new frmStatSubRegionTemplates()) { frm.listView1.MultiSelect = true; if (frm.ShowDialog() == DialogResult.OK) { Feature[] fets = frm.GetSelectedFeatures(); if (fets == null) { #region 没选中任何矢量 regionsname = "全国"; resultList.Clear(); //体积文件SVOL存放路径 string svolPath = savePath + "\\" + regionsname + "\\" + "体积文件"; if (!System.IO.Directory.Exists(svolPath)) { System.IO.Directory.CreateDirectory(svolPath); } //统计出的各个文件夹的数据放在txt文本里 string statxt = savePath + "\\" + regionsname + "\\" + regionsname + ".txt"; FileStream fauto = new FileStream(statxt, FileMode.Create, FileAccess.Write); StreamWriter rauto = new StreamWriter(fauto); //直接对当前中国区域数据做统计 //提取年至avg之间的字符 string filetime = ""; string startDate = ""; string endDate = ""; foreach (string infile in fname) { //解析文件名确定时间 string filename = Path.GetFileNameWithoutExtension(infile); Regex DataReg = new Regex(@"(?<year>\d{4})", RegexOptions.Compiled); Match m = DataReg.Match(filename); string year = ""; if (m.Success) { year = m.Value; } //提取年至avg之间的字符 filetime = filename.Substring(filename.IndexOf(year), filename.Length - 3 - filename.IndexOf(year)); string[] mxchars = filetime.Split(new char[] { '_' }); string mx = ""; //月+旬 if (mxchars.Length == 5 && !filename.Contains("Xun")) //手动统计叫 MWS_MWSD_China_Month_0SD_D_1987_11_1988_2_avg.dat 冬季 { mx = year; } else if (mxchars.Length == 4)// MWS_MWSD_China_Month_0SD_D_1987_1988_2_avg.dat { //mx = year + "_" + mx[0] + "年" + mx[2] + "月"; mx = mx[2] + "月"; } else if (mxchars.Length == 5 && filename.Contains("Xun"))// MWS_MWSD_China_Month_0SD_D_1987_1988_2_1_avg.dat { if (mxchars[3] == "1") { mx = mxchars[2] + "月" + "上旬"; } if (mxchars[3] == "2") { mx = mxchars[2] + "月" + "中旬"; } if (mxchars[3] == "3") { mx = mxchars[2] + "月" + "下旬"; } } else { if (filename.Contains("Xun")) { if (mxchars[2] == "1") { mx = mxchars[1] + "月" + "上旬"; } if (mxchars[2] == "2") { mx = mxchars[1] + "月" + "中旬"; } if (mxchars[2] == "3") { mx = mxchars[1] + "月" + "下旬"; } } if (filename.Contains("Month")) { mx = mxchars[1] + "月"; } } #region 获得excel文件名上时间标识 if (infile == fname[0]) { startDate = year + mx; } if (infile == fname[fname.Length - 1]) { endDate = year + mx; } #endregion string sweVolFile = svolPath + "\\" + Path.GetFileName(infile).Replace("MSWE", "SVOL"); if (!File.Exists(sweVolFile)) { IFileExtractResult sweVolResult = ComputeSnowSWEVOL(infile, sweVolFile); sweVolFile = sweVolResult.FileName; } //只返回一个体积和 double pixelSum; using (IRasterDataProvider inRaster = RasterDataDriver.Open(sweVolFile) as IRasterDataProvider) { pixelSum = CompuCurPixel(sweVolFile); } resultList.Add(new string[] { mx, (pixelSum / 100000000).ToString() }); rauto.WriteLine(mx + " " + (pixelSum / 100000000).ToString()); } rauto.Close(); fauto.Close(); string coluString = regionsname; string sentitle = "统计日期:" + DateTime.Now.ToShortDateString(); string[] columns = new string[] { coluString, "累计雪水当量体积(亿立方米)" }; fresult = new StatResult(sentitle, columns, resultList.ToArray()); string outputIdentify = regionsname;// _argumentProvider.GetArg("OutFileIdentify").ToString(); string title = coluString + "时间序列雪水当量体积统计" + startDate + "_" + endDate; string fileexcel = StatResultToFile(new string[] { fname[0] }, fresult, "MWS", outputIdentify, title, null, 1, true, 1); string newexcelfile = Path.Combine(svolPath, Path.GetFileNameWithoutExtension(fname[0]).Replace(filetime, startDate + "_" + endDate) + ".XLSX"); FileInfo fi = new FileInfo(fileexcel); fi.MoveTo(newexcelfile); IFileExtractResult res = new FileExtractResult(_subProductDef.Identify, newexcelfile, false); return(new FileExtractResult(outputIdentify, newexcelfile)); } #endregion else { string fieldName; string shapeFilename; int fieldIndex = -1; List <string> fieldValues = new List <string>(); fets = frm.GetStatFeatures(out fieldName, out shapeFilename, out fieldIndex); string chinafieldValue = fets[0].GetFieldValue(fieldIndex); //提取年至avg之间的字符 string filetime = ""; string startDate = ""; string endDate = ""; if (chinafieldValue == "中国") { #region 中中国矢量 //直接对当前中国区域数据做统计 regionsname = "全国"; resultList.Clear(); //体积文件SVOL存放路径 string svolPath = savePath + "\\" + regionsname + "\\" + "体积文件"; if (!System.IO.Directory.Exists(svolPath)) { System.IO.Directory.CreateDirectory(svolPath); } //统计出的各个文件夹的数据放在txt文本里 string statxt = savePath + "\\" + regionsname + "\\" + regionsname + ".txt"; FileStream fauto = new FileStream(statxt, FileMode.Create, FileAccess.Write); StreamWriter rauto = new StreamWriter(fauto); //直接对当前中国区域数据做统计 foreach (string infile in fname) { //解析文件名确定时间 string filename = Path.GetFileNameWithoutExtension(infile); Regex DataReg = new Regex(@"(?<year>\d{4})", RegexOptions.Compiled); Match m = DataReg.Match(filename); string year = ""; if (m.Success) { year = m.Value; } //提取年至avg之间的字符 filetime = filename.Substring(filename.IndexOf(year), filename.Length - 3 - filename.IndexOf(year)); string[] mxchars = filetime.Split(new char[] { '_' }); string mx = ""; //月+旬 if (mxchars.Length == 5 && !filename.Contains("Xun")) //手动统计叫 MWS_MWSD_China_Month_0SD_D_1987_11_1988_2_avg.dat 冬季 { mx = year; } else if (mxchars.Length == 4)// MWS_MWSD_China_Month_0SD_D_1987_1988_2_avg.dat { //mx = year + "_" + mx[0] + "年" + mx[2] + "月"; mx = mx[2] + "月"; } else if (mxchars.Length == 5 && filename.Contains("Xun"))// MWS_MWSD_China_Month_0SD_D_1987_1988_2_1_avg.dat { if (mxchars[3] == "1") { mx = mxchars[2] + "月" + "上旬"; } if (mxchars[3] == "2") { mx = mxchars[2] + "月" + "中旬"; } if (mxchars[3] == "3") { mx = mxchars[2] + "月" + "下旬"; } } else { if (filename.Contains("Xun")) { if (mxchars[2] == "1") { mx = mxchars[1] + "月" + "上旬"; } if (mxchars[2] == "2") { mx = mxchars[1] + "月" + "中旬"; } if (mxchars[2] == "3") { mx = mxchars[1] + "月" + "下旬"; } } if (filename.Contains("Month")) { mx = mxchars[1] + "月"; } } //获得excel文件名上的时间标识 #region if (infile == fname[0]) { startDate = year + mx; } if (infile == fname[fname.Length - 1]) { endDate = year + mx; } #endregion string sweVolFile = svolPath + "\\" + Path.GetFileName(infile).Replace("MSWE", "SVOL"); if (!File.Exists(sweVolFile)) { IFileExtractResult sweVolResult = ComputeSnowSWEVOL(infile, sweVolFile); sweVolFile = sweVolResult.FileName; } //只返回一个体积和 double pixelSum; using (IRasterDataProvider inRaster = RasterDataDriver.Open(sweVolFile) as IRasterDataProvider) { pixelSum = CompuCurPixel(sweVolFile); } resultList.Add(new string[] { mx, (pixelSum / 100000000).ToString() }); rauto.WriteLine(mx + " " + (pixelSum / 100000000).ToString()); } rauto.Close(); fauto.Close(); string coluString = regionsname; string sentitle = "统计日期:" + DateTime.Now.ToShortDateString(); string[] columns = new string[] { coluString, "累计雪水当量体积(亿立方米)" }; fresult = new StatResult(sentitle, columns, resultList.ToArray()); string outputIdentify = regionsname;// _argumentProvider.GetArg("OutFileIdentify").ToString(); string title = coluString + "时间序列雪水当量体积统计"; string fileexcel = StatResultToFile(new string[] { fname[0] }, fresult, "MWS", outputIdentify, title, null, 1, true, 1); string newexcelfile = Path.Combine(svolPath, Path.GetFileNameWithoutExtension(fname[0]).Replace(filetime, startDate + "_" + endDate) + ".XLSX"); FileInfo fi = new FileInfo(fileexcel); fi.MoveTo(newexcelfile); IFileExtractResult res = new FileExtractResult(_subProductDef.Identify, newexcelfile, false); return(new FileExtractResult(outputIdentify, newexcelfile)); } #endregion else { #region 中非中国矢量 resultList.Clear(); foreach (Feature fet in fets) { fieldValues.Add(fet.GetFieldValue(fieldIndex)); //获得选择区域名称 aoiContainer.AddAOI(fet); } foreach (string region in fieldValues) { regionsname += region; } if (regionsname.Contains("西藏") && regionsname.Contains("青海")) { regionsname = "青藏地区"; } if (!string.IsNullOrEmpty(regionNames)) { regionsname = regionNames.Trim(); } //创建裁切路径 string clipsave = savePath + "\\" + regionsname + "\\" + "裁切"; if (!System.IO.Directory.Exists(clipsave))//如果不存在这个路径 { System.IO.Directory.CreateDirectory(clipsave); } //体积文件SVOL存放路径 string svolPath = savePath + "\\" + regionsname + "\\" + "体积文件"; if (!System.IO.Directory.Exists(svolPath)) { System.IO.Directory.CreateDirectory(svolPath); } //统计出的各个文件夹的数据放在txt文本里 string statxt = savePath + "\\" + regionsname + "\\" + regionsname + ".txt"; FileStream fauto = new FileStream(statxt, FileMode.Create, FileAccess.Write); StreamWriter rauto = new StreamWriter(fauto); string excelYear = ""; string file1Time = ""; foreach (string infile in fname) { //解析文件名确定时间 string filename = Path.GetFileNameWithoutExtension(infile); Regex DataReg = new Regex(@"(?<year>\d{4})", RegexOptions.Compiled); Match m = DataReg.Match(filename); string year = ""; if (m.Success) { year = m.Value; } //提取年至avg之间的字符 filetime = filename.Substring(filename.IndexOf(year), filename.Length - 3 - filename.IndexOf(year)); string[] mxchars = filetime.Split(new char[] { '_' }); string mx = ""; //月+旬 if (mxchars.Length == 5 && !filename.Contains("Xun")) // MWS_MWSD_China_Month_0SD_D_1987_11_1988_2_avg.dat 冬季 { mx = year; excelYear = year + "年-" + mxchars[2] + "年冬季"; } else if (mxchars.Length == 4 && !filename.Contains("Xun"))// MWS_MWSD_China_Month_0SD_D_1987_1988_2_avg.dat { mx = mxchars[2] + "月"; excelYear = year + "年-" + mxchars[1] + "年"; } else if (mxchars.Length == 5 && filename.Contains("Xun"))// MWS_MWSD_China_Xun_0SD_D_1987_1988_2_1_avg.dat { if (mxchars[3] == "1") { mx = mxchars[2] + "月" + "上旬"; } if (mxchars[3] == "2") { mx = mxchars[2] + "月" + "中旬"; } if (mxchars[3] == "3") { mx = mxchars[2] + "月" + "下旬"; } excelYear = year + "年-" + mxchars[1] + "年"; } else { if (filename.Contains("Xun")) //旬MWS_MSWE_China_Xun_SWE_A_2011_1_1_avg.dat { if (mxchars[2] == "1") { mx = mxchars[1] + "月" + "上旬"; } if (mxchars[2] == "2") { mx = mxchars[1] + "月" + "中旬"; } if (mxchars[2] == "3") { mx = mxchars[1] + "月" + "下旬"; } excelYear = year + "年"; } if (filename.Contains("Month"))//月MWS_MSWE_China_Month_SWE_A_2011_1_avg.dat { mx = mxchars[1] + "月"; excelYear = year + "年"; } } #region 获得excel文件名上的时间标识 if (infile == fname[0]) { startDate = year; file1Time = filetime; } if (infile == fname[fname.Length - 1]) { endDate = year; } #endregion string newclipfile = Path.Combine(clipsave, Path.GetFileName(infile).Replace("China", regionsname)); if (!File.Exists(newclipfile)) { string clipfile = muticlip.MutiRegionsClip(infile, aoiContainer, clipsave); string hdrfile = Path.GetDirectoryName(clipfile) + "\\" + Path.GetFileNameWithoutExtension(clipfile) + ".hdr"; //重命名 //string newclipfile = Path.Combine(Path.GetDirectoryName(clipfile), Path.GetFileName(infile).Replace("China", regionsname)); string newhdrfile = Path.Combine(Path.GetDirectoryName(clipfile), Path.GetFileNameWithoutExtension(infile).Replace("China", regionsname) + ".hdr"); FileInfo fi = new FileInfo(clipfile); fi.MoveTo(newclipfile); FileInfo fihdr = new FileInfo(hdrfile); fihdr.MoveTo(newhdrfile); } string sweVolFile = svolPath + "\\" + Path.GetFileName(newclipfile).Replace("MSWE", "SVOL"); if (!File.Exists(sweVolFile)) { IFileExtractResult sweVolResult = ComputeSnowSWEVOL(newclipfile, sweVolFile); sweVolFile = sweVolResult.FileName; } //只返回一个体积和 double pixelSum; using (IRasterDataProvider inRaster = RasterDataDriver.Open(sweVolFile) as IRasterDataProvider) { pixelSum = CompuCurPixel(sweVolFile); } resultList.Add(new string[] { mx, (pixelSum / 100000000).ToString() }); rauto.WriteLine(mx + " " + (pixelSum / 100000000).ToString()); } rauto.Close(); fauto.Close(); string coluString = regionsname; string sentitle = "统计日期:" + DateTime.Now.ToShortDateString(); string[] columns = new string[] { coluString, "累计雪水当量体积(亿立方米)" }; fresult = new StatResult(sentitle, columns, resultList.ToArray()); string outputIdentify = regionsname;// _argumentProvider.GetArg("OutFileIdentify").ToString(); //string title = coluString + excelYear+ "雪水当量体积统计"; string title = coluString + startDate + "-" + endDate + "雪水当量体积统计"; string fileexcel = StatResultToFile(new string[] { fname[0] }, fresult, "MWS", outputIdentify, title, null, 1, true, 1); string newexcelfile = Path.Combine(svolPath, Path.GetFileNameWithoutExtension(fname[0]).Replace(file1Time, startDate + "_" + endDate) + ".XLSX"); FileInfo fi1 = new FileInfo(fileexcel); fi1.MoveTo(newexcelfile); IFileExtractResult res = new FileExtractResult(_subProductDef.Identify, newexcelfile, false); return(new FileExtractResult(outputIdentify, newexcelfile)); #endregion } } } //没有点确定 else { return(null); } } }
private IExtractResult JPAnaStatAlgorithm(Action <int, string> progressTracker) { string[] inputCurrentFiles = null; //= ExportManager.GetInstance().List.ToArray();//GetStringArray("RasterCurrentFile"); 由查询那里获得 string[] inputHistoryFiles = null; List <string> list1 = ExportManager.GetInstance().List; //得到的是从数据库里查询出来的周期数据 StatisticResultManager manager = StatisticResultManager.GetInstance(); List <StatisticResult> list = manager.List; List <string> list2 = manager.GetFilePathFromList(); //得到的是基于数据查询的数据又做的统计数; #region 获得目标区域 regionNames = _argumentProvider.GetArg("regionNames") as string; aoiContainer = new GeoDo.RSS.Core.VectorDrawing.AOIContainerLayer(); string fieldName; string shapeFilename; int fieldIndex = -1; List <string> fieldValues = new List <string>(); string regionsname = ""; using (frmStatSubRegionTemplates frm = new frmStatSubRegionTemplates()) { frm.listView1.MultiSelect = true; if (frm.ShowDialog() == DialogResult.OK) { Feature[] fets = frm.GetSelectedFeatures(); fets = frm.GetStatFeatures(out fieldName, out shapeFilename, out fieldIndex); if (fets == null) { aoiContainer = null; regionsname = "全国"; } else { string chinafieldValue = fets[0].GetFieldValue(fieldIndex); if (chinafieldValue == "中国") { aoiContainer = null; regionsname = "全国"; } else { foreach (Feature fet in fets) { fieldValues.Add(fet.GetFieldValue(fieldIndex)); //获得选择区域名称 aoiContainer.AddAOI(fet); } foreach (string region in fieldValues) { regionsname += region; } if (regionsname.Contains("西藏") && regionsname.Contains("青海")) { regionsname = "青藏地区"; } if (!string.IsNullOrEmpty(regionNames)) { regionsname = regionNames.Trim(); } } } } else { return(null); } } #endregion Regex DataReg = new Regex(@"(?<year>\d{4})", RegexOptions.Compiled); //处理后的数据存储路径 string savePath = _argumentProvider.GetArg("HistoryDataSave") as string; string jpsavepath = savePath + "\\" + "距平分析"; if (!System.IO.Directory.Exists(jpsavepath))//如果不存在这个路径 { System.IO.Directory.CreateDirectory(jpsavepath); } //参数设置 List <string> paraset = _argumentProvider.GetArg("paraSet") as List <string>; string[] paras = paraset.ToArray(); //先裁切分别算每个文件的雪水当量体积后再相减 string Nostr = ""; //排除非选择的轨道数据 if (paras[0] == "Ascend") { Nostr = "_D_"; } if (paras[0] == "Descend") { Nostr = "_A_"; } if (paras[1] == "winter") // inputCurrentFiles = manager.GetFilePathFromList() 冬季的数所是统计出来的。 { // inputHistoryFiles 需要再重新计算一次 *** 这是多对一计算距平 //比如说要算2000-2013年冬季的距平,需要先分别算出每年冬季的值,用这些值算总的均值。再分别用每年冬季减去总冬季值。 List <string> files = new List <string>(); foreach (string file in list2) { if (!Path.GetFileName(file).Contains(Nostr)) { files.Add(file); } if (file.Contains("MWSE")) { prdType = "SWE"; } else { prdType = "SD"; } } inputCurrentFiles = files.ToArray(); string outHistoryFile = jpsavepath + "\\" + Path.GetFileNameWithoutExtension(inputCurrentFiles[0]).Substring(0, 14) + "_" + paras[2] + ".dat"; SNWParaStat snwStat = new SNWParaStat(); snwStat.SNWParaAvgStat(inputCurrentFiles, 0.1f, outHistoryFile); List <string> temphistory = new List <string>(); temphistory.Add(outHistoryFile); inputHistoryFiles = temphistory.ToArray(); if (inputCurrentFiles == null || inputCurrentFiles.Length < 0 || inputHistoryFiles == null || inputHistoryFiles.Length < 0) { PrintInfo("缺少分析文件"); return(null); } } else { inputCurrentFiles = list1.ToArray(); inputHistoryFiles = list2.ToArray(); if (inputCurrentFiles[0].Contains("MWSE")) { prdType = "SWE"; } else { prdType = "SD"; } if (inputCurrentFiles == null || inputCurrentFiles.Length < 0 || inputHistoryFiles == null || inputHistoryFiles.Length < 0) { PrintInfo("缺少分析文件"); return(null); } if ((inputCurrentFiles.Length) * 2 != inputHistoryFiles.Length) { MessageBox.Show("当年数据与同期数据不对应"); return(null); } } #region 裁切文件 string clipsave = jpsavepath + "\\" + regionsname + "\\" + "裁切"; if (!System.IO.Directory.Exists(clipsave))//如果不存在这个路径 { System.IO.Directory.CreateDirectory(clipsave); } //体积文件SVOL存放路径 string svolPath = jpsavepath + "\\" + regionsname + "\\" + "体积文件"; if (!System.IO.Directory.Exists(svolPath)) { System.IO.Directory.CreateDirectory(svolPath); } //统计出的各个文件夹的数据放在txt文本里 string statxt = jpsavepath + "\\" + regionsname + "\\" + regionsname + ".txt"; FileStream fauto = new FileStream(statxt, FileMode.Create, FileAccess.Write); StreamWriter rauto = new StreamWriter(fauto); if (aoiContainer == null) { //不用裁切 直接计算 resultList.Clear(); if (paras[1] == "winter") { #region 冬季 //只返回一个体积和 double pixelSumWinter; // 总冬季雪水当量的体积和,是被减数 if (prdType == "SWE") { title = regionsname + "冬季雪水当量距平" + "(" + paras[2] + "年)"; string sumsweVolFile = svolPath + "\\" + Path.GetFileName(inputHistoryFiles[0]).Replace("MSWE", "SVOL"); if (!File.Exists(sumsweVolFile)) { IFileExtractResult sweVolResult = ComputeSnowSWEVOL(inputHistoryFiles[0], sumsweVolFile); sumsweVolFile = sweVolResult.FileName; } using (IRasterDataProvider inRaster = RasterDataDriver.Open(sumsweVolFile) as IRasterDataProvider) { pixelSumWinter = CompuCurPixel(sumsweVolFile); } foreach (string infile in inputCurrentFiles) { //MWS_JPEA_MSWE_China_Month_SWE_D_2011_2013_1_avg.dat Regex DataReg2 = new Regex(@"(?<year>\d{4})_(?<month>\d{2})_(?<year>\d{4})_(?<month>\d{1})", RegexOptions.Compiled); Match m = DataReg2.Match(infile); //提取每年冬季的时间 string year = ""; if (m.Success) { year = m.Value; } string mx = ""; //横轴时间 mx = year.Substring(0, 4) + "年"; string sweVolFile = svolPath + "\\" + Path.GetFileName(infile).Replace("MSWE", "SVOL"); if (!File.Exists(sweVolFile)) { IFileExtractResult sweVolResult = ComputeSnowSWEVOL(infile, sweVolFile); sweVolFile = sweVolResult.FileName; } double pixelSum;//只返回一个体积和 using (IRasterDataProvider inRaster = RasterDataDriver.Open(sweVolFile) as IRasterDataProvider) { pixelSum = CompuCurPixel(sweVolFile); } resultList.Add(new string[] { mx, ((pixelSum - pixelSumWinter) / pixelSumWinter * 100).ToString() + "%" }); rauto.WriteLine(mx + " " + ((pixelSum - pixelSumWinter) / pixelSumWinter * 100).ToString() + "%"); } } if (prdType == "SD") { title = regionsname + "冬季雪水当量距平" + "(" + paras[2] + "年)"; using (IRasterDataProvider inRaster = RasterDataDriver.Open(inputHistoryFiles[0]) as IRasterDataProvider) { pixelSumWinter = CompuCurPixel(inputHistoryFiles[0]); } foreach (string infile in inputCurrentFiles) { //MWS_JPEA_MSWE_China_Month_SD_D_2011_2013_1_avg.dat Regex DataReg2 = new Regex(@"(?<year>\d{4})_(?<month>\d{2})_(?<year>\d{4})_(?<month>\d{1})", RegexOptions.Compiled); Match m = DataReg2.Match(infile); //提取每年冬季的时间 string year = ""; if (m.Success) { year = m.Value; } string mx = ""; //横轴时间 mx = year.Substring(0, 4) + "年"; string sweVolFile = svolPath + "\\" + Path.GetFileName(infile).Replace("MSWE", "SVOL"); //只返回一个体积和 double pixelSum; using (IRasterDataProvider inRaster = RasterDataDriver.Open(infile) as IRasterDataProvider) { pixelSum = CompuCurPixel(infile); } resultList.Add(new string[] { mx, ((pixelSum - pixelSumWinter) / pixelSumWinter * 100).ToString() + "%" }); rauto.WriteLine(mx + " " + ((pixelSum - pixelSumWinter) / pixelSumWinter * 100).ToString() + "%"); } } } #endregion else { #region dang nian旬月 resultList.Clear(); foreach (string infile in inputCurrentFiles) { //先假设选择的是旬数据 MWS_MWSD_China_Xun_0SD_A_2011_1_avg.dat // 则同期旬数据 MWS_MWSD_China_Xun_0SD_A_1989_2011_1_avg.dat string cfile = Path.GetFileNameWithoutExtension(infile); Match m = DataReg.Match(cfile); string date = ""; if (m.Success) { date = m.Value; //根据年4个数字来拆分字符串 } string bhalf = cfile.Substring(0, cfile.IndexOf(date)); string ahalf = cfile.Substring(cfile.IndexOf(date) + 4, cfile.Length - 4 - cfile.IndexOf(date)); foreach (string inputHistoryFile in inputHistoryFiles) { string aa = Path.GetFileNameWithoutExtension(inputHistoryFile); double infilepixelSum = 0; //只返回一个体积和 double hisfilepixelSum; //只返回一个体积和 if (aa.Contains(bhalf) && aa.Contains(ahalf) && aa.Contains(date) && !aa.Contains(Nostr)) { #region 当前文件体积计算,并相减 if (prdType == "SWE") { string sweVolFile = svolPath + "\\" + Path.GetFileName(infile).Replace("MSWE", "SVOL"); if (!File.Exists(sweVolFile)) { IFileExtractResult sweVolResult = ComputeSnowSWEVOL(infile, sweVolFile); sweVolFile = sweVolResult.FileName; } using (IRasterDataProvider inRaster = RasterDataDriver.Open(sweVolFile) as IRasterDataProvider) { infilepixelSum = CompuCurPixel(sweVolFile); } #region 历史文件做裁切,体积计算,并相减 string hissweVolFile = svolPath + "\\" + Path.GetFileName(inputHistoryFile).Replace("MSWE", "SVOL"); if (!File.Exists(hissweVolFile)) { IFileExtractResult sweVolResult = ComputeSnowSWEVOL(inputHistoryFile, hissweVolFile); hissweVolFile = sweVolResult.FileName; } using (IRasterDataProvider inRaster = RasterDataDriver.Open(hissweVolFile) as IRasterDataProvider) { hisfilepixelSum = CompuCurPixel(hissweVolFile); } #endregion } else { using (IRasterDataProvider inRaster = RasterDataDriver.Open(infile) as IRasterDataProvider) { infilepixelSum = CompuCurPixel(infile); } using (IRasterDataProvider inRaster = RasterDataDriver.Open(inputHistoryFile) as IRasterDataProvider) { hisfilepixelSum = CompuCurPixel(inputHistoryFile); } } #endregion //提取年至avg之间的字符 string filetime = cfile.Substring(cfile.IndexOf(date), cfile.Length - 3 - cfile.IndexOf(date)); string[] mxchars = filetime.Split(new char[] { '_' }); string mx = "";//月+旬 if (cfile.Contains("Xun")) { title = regionsname + date + "年冬季雪水当量旬距平" + "(" + paras[2] + "年)"; if (mxchars[2] == "1") { mx = mxchars[1] + "月" + "上旬"; } if (mxchars[2] == "2") { mx = mxchars[1] + "月" + "中旬"; } if (mxchars[2] == "3") { mx = mxchars[1] + "月" + "下旬"; } } else if (cfile.Contains("Month")) { title = regionsname + date + "年冬季雪水当量月距平" + "(" + paras[2] + "年)"; mx = mxchars[1] + "月"; } else { mx = filetime; } resultList.Add(new string[] { mx, ((infilepixelSum - hisfilepixelSum) / hisfilepixelSum * 100).ToString() + "%" }); rauto.WriteLine(mx + " " + ((infilepixelSum - hisfilepixelSum) / hisfilepixelSum * 100).ToString() + "%"); } } } #endregion } } else //选择了aois { MulRegionsClip muticlip = new MulRegionsClip(); //裁切 if (paras[1] == "winter") { resultList.Clear(); double pixelSumWinter = 0d; // 总冬季雪水当量的体积和,是被减数 #region title = regionsname + "冬季雪水当量距平" + "(" + paras[2] + "年)"; //先把总的冬季给裁了 string newsumWinter = Path.Combine(clipsave, Path.GetFileName(inputHistoryFiles[0]).Replace("China", regionsname)); if (!File.Exists(newsumWinter)) { string sumWinter = muticlip.MutiRegionsClip(inputHistoryFiles[0], aoiContainer, clipsave); string hdrfile = Path.GetDirectoryName(sumWinter) + "\\" + Path.GetFileNameWithoutExtension(sumWinter) + ".hdr"; //重命名 string newhdrfile = Path.Combine(Path.GetDirectoryName(sumWinter), Path.GetFileNameWithoutExtension(inputHistoryFiles[0]).Replace("China", regionsname) + ".hdr"); FileInfo fi = new FileInfo(sumWinter); fi.MoveTo(newsumWinter); FileInfo fihdr = new FileInfo(hdrfile); fihdr.MoveTo(newhdrfile); } if (prdType == "SWE") { string sumsweVolFile = svolPath + "\\" + Path.GetFileName(newsumWinter).Replace("MSWE", "SVOL"); if (!File.Exists(sumsweVolFile)) { IFileExtractResult sweVolResult = ComputeSnowSWEVOL(newsumWinter, sumsweVolFile); sumsweVolFile = sweVolResult.FileName; } using (IRasterDataProvider inRaster = RasterDataDriver.Open(sumsweVolFile) as IRasterDataProvider) { pixelSumWinter = CompuCurPixel(sumsweVolFile); } } if (prdType == "SD") { using (IRasterDataProvider inRaster = RasterDataDriver.Open(inputHistoryFiles[0]) as IRasterDataProvider) { pixelSumWinter = CompuCurPixel(inputHistoryFiles[0]); } } foreach (string infile in inputCurrentFiles) { //MWS_JPEA_MSWE_China_Month_SWE_D_2011_2013_1_avg.dat Regex DataReg2 = new Regex(@"(?<year>\d{4})_(?<month>\d{2})_(?<year>\d{4})_(?<month>\d{1})", RegexOptions.Compiled); Match m = DataReg2.Match(infile); //提取每年冬季的时间 string year = ""; if (m.Success) { year = m.Value; } string mx = ""; //横轴时间 mx = year.Substring(0, 4) + "年"; string newclipfile = Path.Combine(clipsave, Path.GetFileName(infile).Replace("China", regionsname)); if (!File.Exists(newclipfile)) { string clipfile = muticlip.MutiRegionsClip(infile, aoiContainer, clipsave); string hdrfile = Path.GetDirectoryName(clipfile) + "\\" + Path.GetFileNameWithoutExtension(clipfile) + ".hdr"; //重命名 string newhdrfile = Path.Combine(Path.GetDirectoryName(clipfile), Path.GetFileNameWithoutExtension(infile).Replace("China", regionsname) + ".hdr"); FileInfo fi = new FileInfo(clipfile); fi.MoveTo(newclipfile); FileInfo fihdr = new FileInfo(hdrfile); fihdr.MoveTo(newhdrfile); } //只返回一个体积和 double pixelSum = 0d; if (prdType == "SWE") { string sweVolFile = svolPath + "\\" + Path.GetFileName(newclipfile).Replace("MSWE", "SVOL"); if (!File.Exists(sweVolFile)) { IFileExtractResult sweVolResult = ComputeSnowSWEVOL(newclipfile, sweVolFile); sweVolFile = sweVolResult.FileName; } using (IRasterDataProvider inRaster = RasterDataDriver.Open(sweVolFile) as IRasterDataProvider) { pixelSum = CompuCurPixel(sweVolFile); } } if (prdType == "SD") { using (IRasterDataProvider inRaster = RasterDataDriver.Open(infile) as IRasterDataProvider) { pixelSum = CompuCurPixel(infile); } } resultList.Add(new string[] { mx, ((pixelSum - pixelSumWinter) / pixelSumWinter * 100).ToString() + "%" }); rauto.WriteLine(mx + " " + ((pixelSum - pixelSumWinter) / pixelSumWinter).ToString()); } } #endregion else //选择的是旬、月 { #region resultList.Clear(); foreach (string infile in inputCurrentFiles) { //先假设选择的是旬数据 MWS_MWSD_China_Xun_0SD_A_2011_1_avg.dat // 则同期旬数据 MWS_MWSD_China_Xun_0SD_A_1989_2011_1_avg.dat string cfile = Path.GetFileNameWithoutExtension(infile); Match m = DataReg.Match(cfile); string date = ""; if (m.Success) { date = m.Value; //根据年4个数字来拆分字符串 } string bhalf = cfile.Substring(0, cfile.IndexOf(date)); string ahalf = cfile.Substring(cfile.IndexOf(date) + 4, cfile.Length - 4 - cfile.IndexOf(date)); foreach (string inputHistoryFile in inputHistoryFiles) { string aa = Path.GetFileNameWithoutExtension(inputHistoryFile); if (aa.Contains(bhalf) && aa.Contains(ahalf) && aa.Contains(date) && !aa.Contains(Nostr)) { //只返回一个体积和 double infilepixelSum; //当前文件做裁切,体积计算,并相减 #region string newclipfile = Path.Combine(clipsave, Path.GetFileName(infile).Replace("China", regionsname)); if (!File.Exists(newclipfile)) { string clipfile = muticlip.MutiRegionsClip(infile, aoiContainer, clipsave); string hdrfile = Path.GetDirectoryName(clipfile) + "\\" + Path.GetFileNameWithoutExtension(clipfile) + ".hdr"; //重命名 string newhdrfile = Path.Combine(Path.GetDirectoryName(clipfile), Path.GetFileNameWithoutExtension(infile).Replace("China", regionsname) + ".hdr"); FileInfo fi = new FileInfo(clipfile); fi.MoveTo(newclipfile); FileInfo fihdr = new FileInfo(hdrfile); fihdr.MoveTo(newhdrfile); } if (prdType == "SWE") { string sweVolFile = svolPath + "\\" + Path.GetFileName(newclipfile).Replace("MSWE", "SVOL"); if (!File.Exists(sweVolFile)) { IFileExtractResult sweVolResult = ComputeSnowSWEVOL(newclipfile, sweVolFile); sweVolFile = sweVolResult.FileName; } using (IRasterDataProvider inRaster = RasterDataDriver.Open(sweVolFile) as IRasterDataProvider) { infilepixelSum = CompuCurPixel(sweVolFile); } } else { using (IRasterDataProvider inRaster = RasterDataDriver.Open(newclipfile) as IRasterDataProvider) { infilepixelSum = CompuCurPixel(newclipfile); } } #endregion //历史文件做裁切,体积计算,并相减 #region //只返回一个体积和 double hisfilepixelSum; string newhisclipfile = Path.Combine(clipsave, Path.GetFileName(inputHistoryFile).Replace("China", regionsname)); if (!File.Exists(newhisclipfile)) { string clipfile = muticlip.MutiRegionsClip(inputHistoryFile, aoiContainer, clipsave); string hdrfile = Path.GetDirectoryName(clipfile) + "\\" + Path.GetFileNameWithoutExtension(clipfile) + ".hdr"; //重命名 string newhdrfile = Path.Combine(Path.GetDirectoryName(clipfile), Path.GetFileNameWithoutExtension(inputHistoryFile).Replace("China", regionsname) + ".hdr"); FileInfo fi = new FileInfo(clipfile); fi.MoveTo(newhisclipfile); FileInfo fihdr = new FileInfo(hdrfile); fihdr.MoveTo(newhdrfile); } if (prdType == "SWE") { string hissweVolFile = svolPath + "\\" + Path.GetFileName(newhisclipfile).Replace("MSWE", "SVOL"); if (!File.Exists(hissweVolFile)) { IFileExtractResult sweVolResult = ComputeSnowSWEVOL(newhisclipfile, hissweVolFile); hissweVolFile = sweVolResult.FileName; } using (IRasterDataProvider inRaster = RasterDataDriver.Open(hissweVolFile) as IRasterDataProvider) { hisfilepixelSum = CompuCurPixel(hissweVolFile); } } else { using (IRasterDataProvider inRaster = RasterDataDriver.Open(newhisclipfile) as IRasterDataProvider) { hisfilepixelSum = CompuCurPixel(newhisclipfile); } } #endregion //提取年至avg之间的字符 string filetime = cfile.Substring(cfile.IndexOf(date), cfile.Length - 3 - cfile.IndexOf(date)); string[] mxchars = filetime.Split(new char[] { '_' }); string mx = "";//月+旬 if (cfile.Contains("Xun")) { title = regionsname + date + "年冬季雪水当量旬距平" + "(" + paras[2] + "年)"; if (mxchars[2] == "1") { mx = mxchars[1] + "月" + "上旬"; } if (mxchars[2] == "2") { mx = mxchars[1] + "月" + "中旬"; } if (mxchars[2] == "3") { mx = mxchars[1] + "月" + "下旬"; } } else if (cfile.Contains("Month")) { title = regionsname + date + "年冬季雪水当量月距平" + "(" + paras[2] + "年)"; mx = mxchars[1] + "月"; } else { mx = filetime; } resultList.Add(new string[] { mx, ((infilepixelSum - hisfilepixelSum) / hisfilepixelSum * 100).ToString() + "%" }); rauto.WriteLine(mx + " " + ((infilepixelSum - hisfilepixelSum) / hisfilepixelSum).ToString()); } } } #endregion } } rauto.Close(); fauto.Close(); string coluString = regionsname; string sentitle = "统计日期:" + DateTime.Now.ToShortDateString(); string[] columns = new string[] { coluString, "距平" }; fresult = new StatResult(sentitle, columns, resultList.ToArray()); string outputIdentify = regionsname; string fileexcel = StatResultToFile(new string[] { inputCurrentFiles[0] }, fresult, "MWS", outputIdentify, title, null, 1, true, 1); string newexcelfile = Path.Combine(svolPath, title + ".XLSX");//inputCurrentFiles[0].Substring(0,9) + "_"+ regionsname + paras[2]+ ".XLSX"); FileInfo fi1 = new FileInfo(fileexcel); fi1.MoveTo(newexcelfile); IFileExtractResult res = new FileExtractResult(_subProductDef.Identify, newexcelfile, false); return(new FileExtractResult(outputIdentify, newexcelfile)); #endregion }
private IExtractResult ComputeByCurrentRaster(IRasterDataProvider currPrd, Action <int, string> progressTracker) { float curNDVI = 0f; currPrd = currPrd != null ? currPrd : _argumentProvider.DataProvider; if (currPrd == null) { return(null); } IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster;// int VisibleCH = TryGetBandNo(bandNameRaster, "RedBand"); int NearInfraredCH = TryGetBandNo(bandNameRaster, "NirBand"); int FarInfrared11CH = TryGetBandNo(bandNameRaster, "FarBand"); double VisibleZoom = (double)_argumentProvider.GetArg("RedBand_Zoom"); double NearInfraredZoom = (double)_argumentProvider.GetArg("NirBand_Zoom"); double FarInfrared11Zoom = (double)_argumentProvider.GetArg("FarBand_Zoom"); bool isAutoCloud = (bool)_argumentProvider.GetArg("isAutoCloud"); bool isAppCloud = (bool)_argumentProvider.GetArg("isAppCloud"); if (VisibleCH == -1 || NearInfraredCH == -1 || (isAutoCloud && FarInfrared11CH == -1)) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } string normalizationFile = string.Empty; AngleParModel angleArg = _argumentProvider.GetArg("Angle") as AngleParModel; if (angleArg != null && angleArg.ApplyN) { if (string.IsNullOrEmpty(angleArg.FileAsatA) || !File.Exists(angleArg.FileAsatA) || string.IsNullOrEmpty(angleArg.FileAsatZ) || !File.Exists(angleArg.FileAsatZ) || string.IsNullOrEmpty(angleArg.FileAsunA) || !File.Exists(angleArg.FileAsunA) || string.IsNullOrEmpty(angleArg.FileAsunZ) || !File.Exists(angleArg.FileAsunZ) || string.IsNullOrEmpty(angleArg.FileLandConvery) || !File.Exists(angleArg.FileLandConvery)) { PrintInfo("归一化处理所需的角度信息、土地覆盖信息填写不正确或不存在,请检查..."); return(null); } normalizationFile = NormalizationProcess(currPrd, progressTracker); if (string.IsNullOrEmpty(normalizationFile) || !File.Exists(normalizationFile)) { PrintInfo("归一化处理失败"); return(null); } } bool normalizationSuccess = angleArg != null && angleArg.ApplyN && !string.IsNullOrEmpty(normalizationFile) && File.Exists(normalizationFile) ? true : false; float NearInfraredCLMMin = float.Parse(_argumentProvider.GetArg("NearInfraredCLMMin").ToString()); float FarInfrared11CLMMax = float.Parse(_argumentProvider.GetArg("FarInfrared11CLMMax").ToString()); float FarInfrared11WaterMin = float.Parse(_argumentProvider.GetArg("FarInfrared11WaterMin").ToString()); float NDVIWaterMax = float.Parse(_argumentProvider.GetArg("NDVIWaterMax").ToString()); Int16 defCloudy = (Int16)_argumentProvider.GetArg("defCloudy"); Int16 defWater = (Int16)_argumentProvider.GetArg("defWater"); Int16 InvaildValue = (Int16)_argumentProvider.GetArg("InvaildValue"); int cloudCH = (int)_argumentProvider.GetArg("CLMBand"); string clmFile = GetClmFile(currPrd); bool isSetMinMax = (bool)_argumentProvider.GetArg("isSetMinMax"); float ndviMax = (float)_argumentProvider.GetArg("NDVIMax"); float ndviMin = (float)_argumentProvider.GetArg("NDVIMin"); float ndviCalcMax = float.MinValue; float ndviCalcMin = float.MaxValue; float PNVIZoom = (float)_argumentProvider.GetArg("PNVIZoom"); //输入文件准备 List <RasterMaper> rms = new List <RasterMaper>(); IRasterDataProvider currRaster = null; IRasterDataProvider clmPrd = null; IRasterDataProvider ndviPrd = null; IFileExtractResult pviFile = null; IExtractResultArray array = new ExtractResultArray("DRT"); if (progressTracker != null) { progressTracker.Invoke(normalizationSuccess ? 77 : 0, "计算改进型垂直干旱指数"); } try { currRaster = normalizationSuccess ? GeoDataDriver.Open(normalizationFile) as IRasterDataProvider : currPrd; if (!normalizationSuccess && (currRaster.BandCount < VisibleCH || currRaster.BandCount < NearInfraredCH || (isAutoCloud && currRaster.BandCount < FarInfrared11CH))) { PrintInfo("请选择正确的数据进行垂直干旱指数计算。"); return(null); } RasterMaper rmCurr = normalizationSuccess ? new RasterMaper(currRaster, new int[] { 1, 2, 3 }) : new RasterMaper(currRaster, new int[] { VisibleCH, NearInfraredCH, FarInfrared11CH }); rms.Add(rmCurr); bool isContainClm = false; if (isAppCloud && !string.IsNullOrEmpty(clmFile) && File.Exists(clmFile)) { clmPrd = GeoDataDriver.Open(clmFile) as IRasterDataProvider; if (clmPrd.BandCount < cloudCH) { PrintInfo("请选择正确的云数据通道进行计算。"); return(null); } RasterMaper clmRm = new RasterMaper(clmPrd, new int[] { cloudCH }); rms.Add(clmRm); isContainClm = true; } bool isContainNDVI = false; string ndviFile = string.Empty; string[] ndviFiles = GetStringArray("SelectedPrimaryFiles"); if (ndviFiles == null || ndviFiles.Length == 0 || string.IsNullOrEmpty(ndviFiles[0]) || !File.Exists(ndviFiles[0])) { isContainNDVI = false; } else { isContainNDVI = true; ndviFile = ndviFiles[0]; } int ndviCH = (int)_argumentProvider.GetArg("NDVIBand"); double ndviZoom = (double)_argumentProvider.GetArg("NDVIBand_Zoom"); if (isContainNDVI && !string.IsNullOrEmpty(ndviFile)) { ndviPrd = GeoDataDriver.Open(ndviFile) as IRasterDataProvider; if (ndviPrd.BandCount < ndviCH) { PrintInfo("请选择正确的植被指数数据通道进行计算。"); return(null); } RasterMaper ndviRm = new RasterMaper(ndviPrd, new int[] { ndviCH }); rms.Add(ndviRm); isContainNDVI = true; } //输出文件准备(作为输入栅格并集处理) string outFileName = GetFileName(new string[] { currRaster.fileName }, _subProductDef.ProductDef.Identify, "PNVI", ".dat", null); using (IRasterDataProvider outRaster = CreateOutRaster(outFileName, rms.ToArray())) { //栅格数据映射 RasterMaper[] fileIns = rms.ToArray(); RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) }; //创建处理模型 RasterProcessModel <Int16, Int16> rfr = null; rfr = new RasterProcessModel <Int16, Int16>(progressTracker); rfr.SetRaster(fileIns, fileOuts); rfr.RegisterCalcModel(new RasterCalcHandler <Int16, Int16>((rvInVistor, rvOutVistor, aoi) => { int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX; for (int index = 0; index < dataLength; index++) { Int16 visiableValue = rvInVistor[0].RasterBandsData[0][index]; Int16 nearInfraredValue = rvInVistor[0].RasterBandsData[1][index]; Int16 farInfraredVale = rvInVistor[0].RasterBandsData[2][index]; curNDVI = isContainNDVI ? (float)(rvInVistor[2 - (isContainClm ? 0 : 1)].RasterBandsData[0][index] / ndviZoom) : GetNDVI(nearInfraredValue, visiableValue); if (visiableValue == 0 && nearInfraredValue == 0) { rvOutVistor[0].RasterBandsData[0][index] = InvaildValue; } else if (isContainClm && rvInVistor[1].RasterBandsData[0][index] != 0) { rvOutVistor[0].RasterBandsData[0][index] = defCloudy; } else if (isAutoCloud && (nearInfraredValue / NearInfraredZoom > NearInfraredCLMMin && farInfraredVale / FarInfrared11Zoom < FarInfrared11CLMMax)) { rvOutVistor[0].RasterBandsData[0][index] = defCloudy; } else { if (farInfraredVale / FarInfrared11Zoom > FarInfrared11WaterMin && curNDVI < NDVIWaterMax) { rvOutVistor[0].RasterBandsData[0][index] = defWater; } else { rvOutVistor[0].RasterBandsData[0][index] = (Int16)(curNDVI * PNVIZoom); if (curNDVI > ndviCalcMax) { ndviCalcMax = curNDVI; } else if (curNDVI < ndviCalcMin) { ndviCalcMin = curNDVI; } } } } })); //执行 rfr.Excute(); pviFile = new FileExtractResult(_subProductDef.Identify, outFileName, true); pviFile.SetDispaly(false); if (normalizationSuccess) { FileExtractResult nrsb = new FileExtractResult(_subProductDef.Identify, normalizationFile, true); nrsb.SetDispaly(false); array.Add(nrsb); } _argumentProvider.SetArg("CursorInfo:Image-NDVIMax", ndviCalcMax); _argumentProvider.SetArg("CursorInfo:Image-NDVIMin", ndviCalcMin); array.Add(pviFile); } } finally { if (clmPrd != null) { clmPrd.Dispose(); } if (ndviPrd != null) { ndviPrd.Dispose(); } } FileExtractResult mpdiFile = null; if (File.Exists(pviFile.FileName)) { mpdiFile = CalcMPDI(pviFile.FileName, ndviCalcMin, ndviCalcMax, currRaster, normalizationSuccess, progressTracker); if (mpdiFile != null) { array.Add(mpdiFile); } } return(array); }
private IExtractResult MicroVisSNWSDAlgorithm(Action <int, string> progressTracker) { string inputSDFileName = _argumentProvider.GetArg("RasterSDFile").ToString(); if (string.IsNullOrEmpty(inputSDFileName) || !File.Exists(inputSDFileName)) { PrintInfo("缺少微波雪深文件"); return(null); } string inputCLDSNWFileName = ""; string inputVISNWFileName = ""; string identify = ""; string[] snowfname = GetStringArray("RasterVISNWFiles"); if (progressTracker != null) { progressTracker(1, "开始计算"); } if (snowfname == null || snowfname.Length <= 0) { PrintInfo("请选可见光雪判识文件!"); return(null); } if (snowfname.Length == 1) { inputVISNWFileName = snowfname[0]; } else { identify = "SNDB"; IFileExtractResult vissnowFilename = ComposeVISSNW(snowfname, identify); inputVISNWFileName = vissnowFilename.FileName; } progressTracker(20, "计算完成20%"); string[] cloudfname = GetStringArray("RasterCLDSNWFiles"); if (cloudfname == null || cloudfname.Length <= 0) { PrintInfo("请选可见光云判识文件!"); return(null); } if (cloudfname.Length == 1) { inputCLDSNWFileName = cloudfname[0]; } else { identify = "0CLM"; IFileExtractResult viscldFilename = ComposeVISSNW(cloudfname, identify); inputCLDSNWFileName = viscldFilename.FileName; } progressTracker(50, "计算完成50%"); if (string.IsNullOrEmpty(inputVISNWFileName) || !File.Exists(inputVISNWFileName) || string.IsNullOrEmpty(inputCLDSNWFileName) || !File.Exists(inputCLDSNWFileName)) { PrintInfo("缺少可见光雪或者云判识文件"); return(null); } else { IExtractResultArray array = new ExtractResultArray("融合雪深"); IFileExtractResult visFilename = ComputeVIS(inputVISNWFileName, inputCLDSNWFileName); array.Add(visFilename); progressTracker(70, "计算完成70%"); string visSNWfilename = visFilename.FileName; IFileExtractResult microvisfilename = ComputeSD(inputSDFileName, visSNWfilename); array.Add(microvisfilename); //中值滤波 Int16 smoothwindow = 5; string microvisName = microvisfilename.FileName; IFileExtractResult midSDFilterResult = ComputerMid(microvisName, smoothwindow);//滤波 array.Add(midSDFilterResult); progressTracker(100, "计算完成"); return(array); } }
public static IExtractResult GetExtractResult(IArgumentProvider argProvider, Dictionary <int, PixelFeature> features, IPixelIndexMapper candidateFirPixels, IContextMessage contextMessage, Action <int, string> progressTracker) { if (features == null || features.Count == 0) { PrintInfo(contextMessage, "当前影像无火点信息!"); return(null); } IExtractResultArray array = new ExtractResultArray("火点判识"); if (progressTracker != null) { progressTracker.Invoke(75, "正在生成强度文件,请稍候..."); } //强度栅格文件 IFileExtractResult intensityFile = (new IntensityRasterGenerator()).Generate(argProvider, features); if (intensityFile != null) { array.Add(intensityFile); intensityFile.SetDispaly(false); intensityFile.SetOutIdentify("0FPG"); } //内存判识二值图 //array.Add(candidateFirPixels); if (progressTracker != null) { progressTracker.Invoke(80, "正在生成火区列表,请稍候..."); } //计算火区 using (FireAreaInfoListGenerator fireArea = new FireAreaInfoListGenerator()) { Dictionary <int, FireAreaFeature> fireAFeatures = fireArea.GetFireArea(argProvider, candidateFirPixels, features); IFileExtractResult fALTFile = fireArea.Generator(argProvider, fireAFeatures); //fireArea.ExportILSTToExcel(fALTFile.FileName); if (fALTFile != null) { array.Add(fALTFile); } //环保部信息列表 IFileExtractResult fALHFile = fireArea.GeneratorHB(argProvider, fireAFeatures); if (fALHFile != null) { array.Add(fALHFile); } //火情信息快报 IFileExtractResult fALKFile = fireArea.GeneratorKB(argProvider, fireAFeatures); if (fALKFile != null) { array.Add(fALKFile); } if (progressTracker != null) { progressTracker.Invoke(95, "正在生成火点列表,请稍候..."); } //火点信息列表 using (FirePixelInfoListGenerator p = new FirePixelInfoListGenerator()) { IFileExtractResult pLSTFile = p.Generator(argProvider, features); if (pLSTFile != null) { array.Add(pLSTFile); } //return array; } //环保部火点信息列表 using (FirePixelInfoListGenerator p = new FirePixelInfoListGenerator()) { IFileExtractResult pLSTFile = p.GeneratorHB(argProvider, features); if (pLSTFile != null) { array.Add(pLSTFile); } return(array); } } }
public override IExtractResult Make(Action <int, string> progressTracker, IContextMessage contextMessage) { if (_argumentProvider == null) { return(null); } if (_argumentProvider.GetArg("AlgorithmName") == null) { return(null); } if (_argumentProvider.GetArg("AlgorithmName").ToString() == "VSTATAlgorithm") { string[] fname = GetStringArray("SelectedPrimaryFiles"); //按照Instance执行统计操作 string instanceIdentify = _argumentProvider.GetArg("OutFileIdentify") as string; string fieldName; string shapeFilename; int fieldIndex = -1; if (instanceIdentify != null) { SubProductInstanceDef instance = FindSubProductInstanceDefs(instanceIdentify); if (instance.OutFileIdentify == "VCBP") { using (frmStatProvinceRegionTemplates frm = new frmStatProvinceRegionTemplates()) { if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Feature[] fets = frm.GetSelectedFeatures(); fets = frm.GetStatFeatures(out fieldName, out shapeFilename, out fieldIndex); fieldValues.Clear(); foreach (Feature fet in fets) { fieldValues.Add(fet.GetFieldValue(fieldIndex)); //获得选择区域名称 } } } string aoiprovider = "省级行政区域_面.shp"; string keyname = "NAME"; string sweVolFile = fname[0].Replace("MSWE", "SVOL"); if (!File.Exists(sweVolFile)) { IFileExtractResult sweVolResult = ComputeSnowSWEVOL(fname[0]); sweVolFile = sweVolResult.FileName; } return(VSTATAlgorithm(sweVolFile, aoiprovider, keyname)); } if (instance.OutFileIdentify == "VCBC") { using (frmStatSXRegionTemplates frm = new frmStatSXRegionTemplates()) { if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Feature[] fets = frm.GetSelectedFeatures(); fets = frm.GetStatFeatures(out fieldName, out shapeFilename, out fieldIndex); fieldValues.Clear(); foreach (Feature fet in fets) { fieldValues.Add(fet.GetFieldValue(fieldIndex)); //获得选择区域名称 } } } string aoiprovider = "县级行政区域_面.shp"; string keyname = "NAME"; string sweVolFile = fname[0].Replace("MSWE", "SVOL"); if (!File.Exists(sweVolFile)) { IFileExtractResult sweVolResult = ComputeSnowSWEVOL(fname[0]); sweVolFile = sweVolResult.FileName; } return(VSTATAlgorithm(sweVolFile, aoiprovider, keyname)); } if (instance.OutFileIdentify == "VLUT") { string aoiprovider = "土地利用类型_合并.shp"; string keyname = "NAME"; string sweVolFile = fname[0].Replace("MSWE", "SVOL"); if (!File.Exists(sweVolFile)) { IFileExtractResult sweVolResult = ComputeSnowSWEVOL(fname[0]); sweVolFile = sweVolResult.FileName; } return(VSTATAlgorithm(sweVolFile, aoiprovider, keyname)); } if (instance.OutFileIdentify == "VCAR") { string aoiprovider = ""; string keyname = ""; string sweVolFile = fname[0].Replace("MSWE", "SVOL"); if (!File.Exists(sweVolFile)) { IFileExtractResult sweVolResult = ComputeSnowSWEVOL(fname[0]); sweVolFile = sweVolResult.FileName; } return(VSTATAlgorithm(sweVolFile, aoiprovider, keyname)); } } } return(null); }