private IExtractResult HistoryDataLayoutAlgorithm(Action <int, string> progressTracker) { //1.获取到数据 List <string> list = ExportManager.GetInstance().List; //这个针对查询出来的数据出专题图 string[] inputfiles = list.ToArray(); //再加一上基于 同期统计数据的专题图,如果是冬季的,还要再计算一次 StatisticResultManager manager = StatisticResultManager.GetInstance(); List <string> list2 = manager.GetFilePathFromList(); //得到的是基于数据查询的数据又做的统计数据 if (list2.Count != 0) { inputfiles = list2.ToArray(); period = "yes"; Match m = DataReg2.Match(inputfiles[0]); if (m.Success) { Iswinter = "yes"; } } //处理后的数据存储路径 string savePath = _argumentProvider.GetArg("HistoryDataSave") as string; regioNames = _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 inputfiles) { if (Path.GetFileName(file).Contains(Str)) { fnamelist.Add(file); } } inputfiles = fnamelist.ToArray(); //处理后的数据,用它来出专题图 List <string> afterProcessfiles = new List <string>(); //(插一步,通过这个原始选择的文件名时间信息把专题图名称确定) //2.确定选择区域,没有选或者中国区域不要用裁,如果是其地区首先裁切,并且放到指定文件夹下 aoiContainer = new GeoDo.RSS.Core.VectorDrawing.AOIContainerLayer(); MulRegionsClip muticlip = new MulRegionsClip(); //裁切 MWSSmoothHelp smooth = new MWSSmoothHelp(); //平滑 string regionsname = ""; #region 获得目标区域 aoiContainer = new GeoDo.RSS.Core.VectorDrawing.AOIContainerLayer(); string fieldName; string shapeFilename; int fieldIndex = -1; List <string> fieldValues = new List <string>(); 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(regioNames)) { regionsname = regioNames.Trim(); } } } } else //没有点击确定,返回空 { return(null); } } #endregion if (aoiContainer == null) { //不用裁切,只做中值滤波的平滑处理。 regionsname = "全国"; foreach (string infile in inputfiles) { //创建专题图路径 gxdsave = savePath + "\\" + regionsname + "\\" + "专题图"; if (!System.IO.Directory.Exists(gxdsave))//如果不存在这个路径 { System.IO.Directory.CreateDirectory(gxdsave); } //创建平滑路径 string smoothsave = savePath + "\\" + regionsname + "\\" + "平滑"; if (!System.IO.Directory.Exists(smoothsave)) { System.IO.Directory.CreateDirectory(smoothsave); } //创建平滑\\中值 string filtersave = smoothsave + "\\" + "中值"; if (!System.IO.Directory.Exists(filtersave)) { System.IO.Directory.CreateDirectory(filtersave); } string filterfile = smooth.ComputerMid(infile, 5, filtersave); string hdrfile = Path.GetDirectoryName(filterfile) + "\\" + Path.GetFileNameWithoutExtension(filterfile) + ".hdr"; afterProcessfiles.Add(filterfile); } } else { //创建裁切路径 string clipsave = savePath + "\\" + regionsname + "\\" + "裁切"; if (!System.IO.Directory.Exists(clipsave))//如果不存在这个路径 { System.IO.Directory.CreateDirectory(clipsave); } //创建专题图路径 gxdsave = savePath + "\\" + regionsname + "\\" + "专题图"; if (!System.IO.Directory.Exists(gxdsave))//如果不存在这个路径 { System.IO.Directory.CreateDirectory(gxdsave); } //创建平滑路径 string smoothsave = savePath + "\\" + regionsname + "\\" + "平滑"; if (!System.IO.Directory.Exists(smoothsave)) { System.IO.Directory.CreateDirectory(smoothsave); } //创建平滑\\中值 string filtersave = smoothsave + "\\" + "中值"; if (!System.IO.Directory.Exists(filtersave)) { System.IO.Directory.CreateDirectory(filtersave); } //创建平滑\\插值 string bilisave = smoothsave + "\\" + "插值"; if (!System.IO.Directory.Exists(bilisave)) { System.IO.Directory.CreateDirectory(bilisave); } foreach (string infile in inputfiles) { //加一个条件判断要处理的数据是否已经存在,如果存就不用再做 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); } //裁切后要对数据中值、插值 string filterfile = smooth.ComputerMid(newclipfile, 5, filtersave); string bilifile = smooth.Bilinear(filterfile, 10, bilisave); afterProcessfiles.Add(bilifile); } } //把处理后的afterProcessfiles.ToArray()数组文件名标识变为“HFSD”或“HFWE”。 foreach (string file in afterProcessfiles.ToArray()) { string hdrfile = Path.GetDirectoryName(file) + "\\" + Path.GetFileNameWithoutExtension(file) + ".hdr"; string newfile = ""; string newhdr = ""; if (file.Contains("MWSD")) { newfile = file.Replace("MWSD", "HFSD"); newhdr = hdrfile.Replace("MWSD", "HFSD"); } if (file.Contains("MSWE")) { newfile = file.Replace("MSWE", "HFWE"); newhdr = hdrfile.Replace("MSWE", "HFWE"); } FileInfo fi = new FileInfo(file); if (!File.Exists(newfile)) { fi.MoveTo(newfile); } FileInfo fihdr = new FileInfo(hdrfile); if (!File.Exists(newhdr)) { fihdr.MoveTo(newhdr); } imgfiles.Add(newfile); } IExtractResultArray results = new ExtractResultArray(""); foreach (string arguments in imgfiles.ToArray()) { string product = ""; if (arguments.Contains("HFSD")) { _argumentProvider.SetArg("OutFileIdentify", "HSDI"); product = "雪深"; } if (arguments.Contains("HFWE")) { _argumentProvider.SetArg("OutFileIdentify", "HSWI"); product = "雪水当量"; } //解析文件名确定专题图名称 string filename = Path.GetFileNameWithoutExtension(arguments); if (period == "yes") //同期统计的 { if (Iswinter == "yes") { Match m = DataReg2.Match(filename); string year = ""; if (m.Success) { year = m.Value; } imgname = year.Substring(0, 4) + "年" + "冬季" + regionsname + product + "分布图"; } else { Regex DataReg1 = new Regex(@"(?<year>\d{4})_(?<year>\d{4})", RegexOptions.Compiled); Match m = DataReg1.Match(filename); string year = ""; if (m.Success) { year = m.Value; } //提取年至avg之间的字符 string filetime = filename.Substring(filename.IndexOf(year), filename.Length - 3 - filename.IndexOf(year)); string[] mxchars = filetime.Split(new char[] { '_' }); string mx = "";//月+旬 if (filename.Contains("Xun")) { if (mxchars[3] == "1") { mx = mxchars[2] + "月" + "上旬"; } if (mxchars[3] == "2") { mx = mxchars[2] + "月" + "中旬"; } if (mxchars[3] == "3") { mx = mxchars[2] + "月" + "下旬"; } } if (filename.Contains("Month")) { mx = mxchars[2] + "月"; } imgname = year + "年" + mx + regionsname + product + "分布图"; } } else { Regex DataReg = new Regex(@"(?<year>\d{4})", RegexOptions.Compiled); Match m = DataReg.Match(filename); string year = ""; if (m.Success) { year = m.Value; } //提取年至avg之间的字符 string filetime = filename.Substring(filename.IndexOf(year), filename.Length - 3 - filename.IndexOf(year)); string[] mxchars = filetime.Split(new char[] { '_' }); string mx = "";//月+旬 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] + "月"; } if (filetime.Contains("Season")) { mx = mxchars[1] + "季度"; } imgname = year + "年" + mx + regionsname + product + "分布图"; } _argumentProvider.SetArg("SelectedPrimaryFiles", arguments); _argumentProvider.SetArg("fileOpenArgs", arguments); FileExtractResult result = ThemeGraphyResult(null) as FileExtractResult; //增加矢量 string autopath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"SystemData\ProductArgs\MWS\shppath.txt"); string shpFile = ""; if (File.Exists(autopath)) { FileStream fauto = new FileStream(autopath, FileMode.Open, FileAccess.Read); StreamReader rauto = new StreamReader(fauto, Encoding.GetEncoding("gb2312")); shpFile = rauto.ReadLine(); rauto.Close(); fauto.Close(); } else { shpFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"数据引用\基础矢量\行政区划\线\中国边界_线.shp"); } CreateMcd(shpFile); _shpFile = shpFile; _gxdFile = (result as FileExtractResult).FileName; AddShpToGxd(); FileInfo fi = new FileInfo(result.FileName); string newresultfile = Path.Combine(gxdsave, Path.GetFileNameWithoutExtension(arguments) + ".gxd"); if (!File.Exists(newresultfile)) { fi.MoveTo(newresultfile); } else { FileInfo fi1 = new FileInfo(newresultfile); fi1.Delete(); } IFileExtractResult res = new FileExtractResult(_subProductDef.Identify, newresultfile, false); results.Add(res); } return(results); }
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 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 JuPingAnalysisAlgorithm(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(); //得到的是基于数据查询的数据又做的统计数据 regionNames = _argumentProvider.GetArg("regionNames") as string; //处理后的数据,用它来出专题图 List <string> afterProcessfiles = new List <string>(); #region 获得目标区域 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(); List <string> jpfiles = new List <string>();//存放相减的距平分析文件 string date = ""; string jupingfile = ""; IExtractResultArray array = new ExtractResultArray("距平分析"); 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); } } 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); } foreach (string inputCurrentFile in inputCurrentFiles) { Regex DataReg2 = new Regex(@"(?<year>\d{4})_(?<month>\d{2})_(?<year>\d{4})_(?<month>\d{1})", RegexOptions.Compiled); Match m = DataReg2.Match(inputCurrentFile); //提取每年冬季的时间 string year = ""; if (m.Success) { year = m.Value; } jupingfile = JuPinComputer(inputCurrentFile, inputHistoryFiles[0], jpsavepath); string hdrfile = Path.GetDirectoryName(jupingfile) + "\\" + Path.GetFileNameWithoutExtension(jupingfile) + ".hdr"; FileInfo fi = new FileInfo(jupingfile); string newjpfile = Path.Combine(jpsavepath, Path.GetFileNameWithoutExtension(jupingfile) + "_" + year.Substring(0, 4) + ".dat"); string newhdrfile = Path.Combine(jpsavepath, Path.GetFileNameWithoutExtension(jupingfile) + "_" + year.Substring(0, 4) + ".hdr"); fi.MoveTo(newjpfile); FileInfo fihdr = new FileInfo(hdrfile); fihdr.MoveTo(newhdrfile); jpfiles.Add(newjpfile); } } else { //例 2013年11月上旬-2013年11月下旬分别与1987-2013年11月上中下旬 同期比较 一对一计算距平 inputCurrentFiles = list1.ToArray(); inputHistoryFiles = list2.ToArray(); if (inputCurrentFiles == null || inputCurrentFiles.Length < 0 || inputHistoryFiles == null || inputHistoryFiles.Length < 0) { PrintInfo("缺少分析文件"); return(null); } if ((inputCurrentFiles.Length) * 2 != inputHistoryFiles.Length) { MessageBox.Show("当年数据与同期数据不对应"); return(null); } foreach (string inputCurrentFile 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(inputCurrentFile); Match m = DataReg.Match(cfile); 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)) { jupingfile = JuPinComputer(inputCurrentFile, inputHistoryFile, jpsavepath); jpfiles.Add(jupingfile); break; } } } } #region 距平的文件在jpfiles 中,下面是裁切和平滑处理 MulRegionsClip muticlip = new MulRegionsClip(); //裁切 MWSSmoothHelp smooth = new MWSSmoothHelp(); //平滑 //创建专题图路径 gxdsave = jpsavepath + "\\" + regionsname + "\\" + "专题图"; if (!System.IO.Directory.Exists(gxdsave))//如果不存在这个路径 { System.IO.Directory.CreateDirectory(gxdsave); } //创建平滑路径 string smoothsave = jpsavepath + "\\" + regionsname + "\\" + "平滑"; if (!System.IO.Directory.Exists(smoothsave)) { System.IO.Directory.CreateDirectory(smoothsave); } //创建平滑\\中值 string filtersave = smoothsave + "\\" + "中值"; if (!System.IO.Directory.Exists(filtersave)) { System.IO.Directory.CreateDirectory(filtersave); } if (aoiContainer == null) { //只做中值处理 foreach (string infile in jpfiles) { // 先判断这个文件是否存在,存在了就不做 string filterfile = filtersave + "\\" + Path.GetFileName(infile); if (!File.Exists(filterfile)) { filterfile = smooth.ComputerMid(infile, 5, filtersave); } afterProcessfiles.Add(filterfile); toBarfiles.Add(infile); } } else { // 裁切 // 中值 // 插值 string clipsave = jpsavepath + "\\" + regionsname + "\\" + "裁切"; if (!System.IO.Directory.Exists(clipsave))//如果不存在这个路径 { System.IO.Directory.CreateDirectory(clipsave); } string bilisave = smoothsave + "\\" + "插值"; if (!System.IO.Directory.Exists(bilisave)) { System.IO.Directory.CreateDirectory(bilisave); } foreach (string infile in jpfiles) { string newclipfile = 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); } toBarfiles.Add(newclipfile); //加上裁切后的文件 //中值、插值 string filterfile = smooth.ComputerMid(newclipfile, 5, filtersave); string bilifile = smooth.Bilinear(filterfile, 10, bilisave); afterProcessfiles.Add(bilifile); } } #endregion //出专题图 #region IExtractResultArray results = new ExtractResultArray(""); foreach (string arguments in afterProcessfiles.ToArray()) { string product = ""; if (arguments.Contains("MWSD")) { product = "雪深"; _argumentProvider.SetArg("OutFileIdentify", "JPDI"); } if (arguments.Contains("MSWE")) { product = "雪水当量"; _argumentProvider.SetArg("OutFileIdentify", "JPEI"); } //解析文件名确定专题图名称 string filename = Path.GetFileNameWithoutExtension(arguments); if (paras[1] == "usual") { Regex DataReg1 = new Regex(@"(?<year>\d{4})_(?<year>\d{4})", RegexOptions.Compiled); Match m = DataReg1.Match(filename); string year = ""; if (m.Success) { year = m.Value; } //提取年至avg之间的字符 string filetime = filename.Substring(filename.IndexOf(year), filename.Length - 3 - filename.IndexOf(year)); string[] mxchars = filetime.Split(new char[] { '_' }); string mx = "";//月+旬 if (filename.Contains("Xun")) { if (mxchars[3] == "1") { mx = mxchars[2] + "月" + "上旬"; } if (mxchars[3] == "2") { mx = mxchars[2] + "月" + "中旬"; } if (mxchars[3] == "3") { mx = mxchars[2] + "月" + "下旬"; } } if (filename.Contains("Month")) { mx = mxchars[2] + "月"; } imgname = year.Substring(5, 4) + "年" + mx + regionsname + product + "距平分布图(" + paras[2] + "年)"; } if (paras[1] == "winter") { imgname = Path.GetFileNameWithoutExtension(arguments).Substring(Path.GetFileNameWithoutExtension(arguments).Length - 4, 4) + "年" + "冬季" + regionsname + product + "距平分布图(" + paras[2] + "年)"; } _argumentProvider.SetArg("SelectedPrimaryFiles", arguments); _argumentProvider.SetArg("fileOpenArgs", arguments); FileExtractResult result = ThemeGraphyResult(null) as FileExtractResult; //增加矢量 string autopath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"SystemData\ProductArgs\MWS\shppath.txt"); string shpFile = ""; if (File.Exists(autopath)) { FileStream fauto = new FileStream(autopath, FileMode.Open, FileAccess.Read); StreamReader rauto = new StreamReader(fauto, Encoding.GetEncoding("gb2312")); shpFile = rauto.ReadLine(); rauto.Close(); fauto.Close(); } else { shpFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"数据引用\基础矢量\行政区划\线\中国边界_线.shp"); } CreateMcd(shpFile); _shpFile = shpFile; _gxdFile = (result as FileExtractResult).FileName; AddShpToGxd(); string newresultfile = Path.Combine(gxdsave, Path.GetFileNameWithoutExtension(arguments) + ".gxd"); FileInfo fi = new FileInfo(result.FileName); if (!File.Exists(newresultfile)) { fi.MoveTo(newresultfile); } else { FileInfo fi1 = new FileInfo(newresultfile); fi1.Delete(); } IFileExtractResult res = new FileExtractResult(_subProductDef.Identify, newresultfile, false); results.Add(res); } #endregion return(results); }