示例#1
0
 private void GetHideCols(bool singleFile, IStatResult result)
 {
     if (_indexies == null)
     {
         _indexies = new List <int>();
     }
     else
     {
         _indexies.Clear();
     }
     if (singleFile)
     {
         int length    = result.Columns.Length;
         int hideCount = HideColName.Length;
         for (int j = 0; j < length; j++)
         {
             for (int i = 0; i < hideCount; i++)
             {
                 if (result.Columns[j].IndexOf(HideColName[i]) != -1)
                 {
                     _indexies.Add(j);
                     break;
                 }
             }
         }
     }
 }
 public static string ExportStaticResult(string fileName, IStatResult result, masExcelDrawStatType drawType, string title, int colOffset, bool hasLegend, string xName, string yName)
 {
     try
     {
         using (StatResultToChartInExcelFile excelControl = new StatResultToChartInExcelFile())
         {
             excelControl.Init(drawType);
             excelControl.Add(title, result, true, colOffset, false, xName, yName);
             if (!fileName.ToUpper().EndsWith(".XLSX"))
             {
                 fileName += ".XLSX";
             }
             excelControl.SaveFile(fileName);
         }
     }
     catch (Exception)
     {
         using (StatResultToTxtFile txtControl = new StatResultToTxtFile())
         {
             if (!fileName.ToUpper().EndsWith(".TXT"))
             {
                 fileName += ".TXT";
             }
             txtControl.WriteResultToTxt(title + "\n");
             txtControl.WriteResultToTxt("统计日期:" + DateTime.Today.Date.ToShortDateString() + "\n");
             txtControl.WriteResultToTxt(result);
             bool isSave = txtControl.SaveFile(fileName);
             if (!isSave)
             {
                 return(String.Empty);
             }
         }
     }
     return(fileName);
 }
示例#3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="windowText"></param>
 /// <param name="result"></param>
 /// <param name="drawChart"></param>
 /// <param name="colOffset">开始绘制图表的偏移列数,0为从第一列开始绘制</param>
 /// <param name="xName">横轴标题</param>
 /// <param name="yName">纵轴标题</param>
 public void Add(string windowText, IStatResult result, bool drawChart, int colOffset, bool hasLegend, string xName, string yName)
 {
     _windowText  = windowText;
     _result      = result;
     _isDrawChart = drawChart;
     _needLoad    = true;
     Display(result, drawChart, colOffset, hasLegend, xName, yName);
 }
示例#4
0
 public void Add(bool singleFile, string windowText, IStatResult result, bool isTotal, int statImage)
 {
     if (!string.IsNullOrEmpty(windowText))
     {
         Text = windowText;
     }
     richTextBox1.Text = string.Empty;
     Append(singleFile, result, isTotal, statImage);
 }
示例#5
0
        private void SupplySpace(bool singleFile, IStatResult result)
        {
            int length = result.Columns.Length + initBCol - bCol - _indexies.Count;

            for (int surplusCol = 0; surplusCol < length; surplusCol++)
            {
                winExcelControl1.SetCellValue(bRow, bCol, 1, masExcelAlignType.General, "", null);
                bCol++;
            }
        }
示例#6
0
        private void SupplySpace(IStatResult result)
        {
            int length = result.Columns.Length + initBCol - bCol;

            for (int surplusCol = 0; surplusCol < length; surplusCol++)
            {
                _winExcelControl.SetCellValue(bRow, bCol, 1, masExcelAlignType.General, "", null);
                bCol++;
            }
        }
示例#7
0
 public void Add(bool singleFile, string windowText, IStatResult result, bool isTotal, int statImage)
 {
     _singleFile = singleFile;
     _windowText = windowText;
     _result     = result;
     _isTotal    = isTotal;
     _statImage  = statImage;
     _needLoad   = true;
     _appendType = enumAppendExcelType.Base;
 }
        private IExtractResult StatProcentRaster <T>(string fname, Dictionary <string, Func <short, bool> > filters, Action <int, string> progressTracker)
        {
            string statString = AreaStatProvider.GetAreaStatItemFileName("行政区划");
            SortedDictionary <string, double[][]> srcResult = RasterStatFactory.StatPercent <short>(fname, statString, filters, progressTracker);
            //删除为空的AOI区域以及计算百分比
            SortedDictionary <string, double[][]> statResult = new SortedDictionary <string, double[][]>();
            //区间个数
            int regionCount = filters.Keys.Count;

            foreach (string key in srcResult.Keys)
            {
                if (srcResult[key] == null)
                {
                    continue;
                }
                else
                {
                    int        zeroCount = 0;
                    double[][] value     = new double[regionCount][];
                    for (int i = 0; i < regionCount; i++)
                    {
                        value[i] = new double[] { srcResult[key][i][0], srcResult[key][i][0] / srcResult[key][i][1] * 100 };
                        if (value[i][0] == 0)
                        {
                            zeroCount++;
                        }
                    }
                    //如果全为0,也不添加
                    if (zeroCount < regionCount)
                    {
                        statResult.Add(key, value);
                    }
                }
            }
            if (statResult.Count == 0)
            {
                return(null);
            }
            string      productName = _subProductDef.ProductDef.Name;
            string      title       = productName + "行政区划" + "植被指数统计";
            string      subTitle    = GetSubTitle(fname);
            IStatResult results     = DicToStatResult(statResult, filters.Keys.ToArray(), subTitle);

            if (results == null)
            {
                return(null);
            }
            string outFileIdentify = GetStringArgument("OutFileIdentify");
            string productIdentify = _subProductDef.ProductDef.Identify;
            string filename        = StatResultToFile(new string[] { fname }, results, productIdentify, outFileIdentify, title, null, 1, false, 1);

            return(new FileExtractResult(outFileIdentify, filename));
        }
示例#9
0
 public void Add(bool singleFile, string windowText, IStatResult result, int displayCol, bool dislayDateLabel, bool isTotal, int statImage)
 {
     _singleFile      = singleFile;
     _windowText      = windowText;
     _result          = result;
     _displayCol      = displayCol;
     _dislayDateLabel = dislayDateLabel;
     _isTotal         = isTotal;
     _statImage       = statImage;
     _needLoad        = true;
     _appendType      = enumAppendExcelType.DisplayColLable;
 }
示例#10
0
        private void Append(IStatResult result, bool drawChart, int colOffset, bool hasLegend, string xName, string yName)
        {
            if (result == null)
            {
                return;
            }
            bCol = initBCol;
            bRow = 1;
            int currentCol = -1;

            _winExcelControl.SetCellValue(bRow, bCol, bRow, bCol + result.Columns.Length - 1, 1, masExcelAlignType.Center, Text.Replace(".", ""), "@");
            bRow++;
            _winExcelControl.SetCellValue(bRow, bCol, bRow, bCol + result.Columns.Length - 1, 1, masExcelAlignType.General, result.Title, null);
            if (result.Columns != null && result.Columns.Length > 0)
            {
                bRow++;
                foreach (string colname in result.Columns)
                {
                    currentCol++;
                    _winExcelControl.SetCellValue(bRow, bCol, 1, masExcelAlignType.General, colname, null);
                    _winExcelControl.SetBackColor(bRow, bCol, bRow, bCol, 216, 216, 216);
                    bCol++;
                }
            }
            //
            int statBRow = bRow + 1;

            if (result.Rows != null && result.Rows.Length > 0)
            {
                foreach (string[] row in result.Rows)
                {
                    currentCol = -1;
                    bCol       = initBCol;
                    bRow++;
                    foreach (string colContext in row)
                    {
                        currentCol++;
                        _winExcelControl.SetCellValue(bRow, bCol, 1, masExcelAlignType.General, SetRound(colContext), null);
                        bCol++;
                    }
                    SupplySpace(result);
                }
            }
            if (drawChart)
            {
                _winExcelControl.DrawStat(statBRow - 1, initBCol + colOffset, bRow, initBCol + result.Columns.Length - 1, "图表", Text.Replace(".", ""), xName,
                                          yName,
                                          _masExcelDrawStatType, false, hasLegend);
            }
            bRow += 3;
        }
示例#11
0
 public void Add(bool singleFile, string windowText, IStatResult result, int displayCol, bool isTotal, int totalAll, int statImage, byte baseCol)
 {
     _singleFile = singleFile;
     _windowText = windowText;
     _result     = result;
     _displayCol = displayCol;
     _isTotal    = isTotal;
     _totalAll   = totalAll;
     _statImage  = statImage;
     _needLoad   = true;
     _appendType = enumAppendExcelType.DisplayColAllTotal;
     _baseCol    = baseCol;
     Display();
 }
示例#12
0
 private void Display(IStatResult result, bool drawChart, int colOffset, bool hasLegend, string xName, string yName)
 {
     if (_needLoad)
     {
         if (!string.IsNullOrEmpty(_windowText))
         {
             Text = _windowText;
         }
         //GetHideCols(_singleFile, _result);
         Append(result, drawChart, colOffset, hasLegend, xName, yName);
         _winExcelControl.UnLock();
         _needLoad = false;
     }
     this.Refresh();
 }
示例#13
0
        public void Append(bool singleFile, IStatResult result, bool isTotal, int statImage)
        {
            if (result == null)
            {
                return;
            }
            StringBuilder sb = new StringBuilder();

            if (richTextBox1.Text != string.Empty)
            {
                sb.AppendLine(string.Empty);
            }
            sb.AppendLine(result.Title.PadLeft(50));
            //
            if (result.Columns != null && result.Columns.Length > 0)
            {
                string colLineString = null;
                foreach (string colname in result.Columns)
                {
                    colLineString += colname.PadRight(20);
                }
                sb.AppendLine(colLineString);
                sb.AppendLine("-".PadRight(24 * result.Columns.Length, '-'));
            }
            //
            if (result.Rows != null && result.Rows.Length > 0)
            {
                foreach (string[] row in result.Rows)
                {
                    string rowLineString = null;
                    foreach (string v in row)
                    {
                        if (v == null)
                        {
                            rowLineString += string.Empty.PadRight(30);
                        }
                        else
                        {
                            rowLineString += v.PadRight(30);
                        }
                    }
                    sb.AppendLine(rowLineString);
                }
            }
            //
            richTextBox1.Text += sb.ToString();
            sb = null;
        }
示例#14
0
 public void Add(bool singleFile, string windowText, IStatResult result, int startCol, int displayCol, bool isTotal, int totalAll, int statImage, byte baseCol, int chartType)
 {
     _singleFile           = singleFile;
     _windowText           = windowText;
     _result               = result;
     _displayCol           = displayCol;
     _isTotal              = isTotal;
     _totalAll             = totalAll;
     _statImage            = statImage;
     _needLoad             = true;
     _appendType           = enumAppendExcelType.DisplayColAllTotal;
     _startCol             = startCol;
     _baseCol              = baseCol;
     _masExcelDrawStatType = chartType == 1 ? masExcelDrawStatType.xlColumnClustered : masExcelDrawStatType.xlLine;
     Display();
 }
示例#15
0
 public void Add(bool singleFile, string windowText, IStatResult result, int startCol, int displayCol, bool dislayDateLabel, bool isTotal, int statImage, List <RowDisplayDef> rowRuler, int uionBCol, byte baseCol)
 {
     _singleFile      = singleFile;
     _windowText      = windowText;
     _result          = result;
     _displayCol      = displayCol;
     _dislayDateLabel = dislayDateLabel;
     _isTotal         = isTotal;
     _statImage       = statImage;
     _needLoad        = true;
     _appendType      = enumAppendExcelType.DisplayColLableAndRowRuler;
     _rowRulers       = rowRuler;
     _startCol        = startCol;
     _baseCol         = baseCol;
     _uionBCol        = uionBCol;
     Display();
 }
        private IExtractResult CreatCustomStatResult(Dictionary <string, int[]> aoi, SortedDictionary <float, float> regions, float resultZoom, string[] fname, string outFileId)
        {
            string         productTitle = _argumentProvider.GetArg("ProductTitle").ToString();
            string         extInfos     = GetStringArgument("extinfo");
            string         title        = "统计日期:" + DateTime.Now.ToShortDateString();
            RasterIdentify id           = new RasterIdentify(fname[0]);

            if (id.OrbitDateTime != DateTime.MinValue)
            {
                title += "  轨道日期:" + id.OrbitDateTime;
            }
            IRasterDataProvider prd        = GeoDataDriver.Open(fname[0]) as IRasterDataProvider;
            IStatResult         statResult = CreatStatResultItem(regions, aoi, prd, resultZoom, title);
            string filename = StatResultToFile(fname, statResult, "VGT", outFileId, "植被指数自定义区域统计", extInfos, 1, true, 1);

            return(new FileExtractResult(outFileId, filename));
        }
        private IStatResult CalcAvg(IStatResult srcStatResult, List <int> displayRowNum)
        {
            string        temp;
            float         value      = 0;
            List <string> newColumns = new List <string>();

            newColumns.AddRange(srcStatResult.Columns);
            List <string[]> newRows = new List <string[]>();

            newRows.AddRange(srcStatResult.Rows);
            List <string> rowTemp     = new List <string>();
            int           startCol    = 0;
            int           addColIndex = srcStatResult.Rows[displayRowNum[0] - 3].Length;

            for (int col = 0; col < srcStatResult.Columns.Length; col++)
            {
                if (col >= srcStatResult.Rows[displayRowNum[0] - 3].Length)
                {
                    break;
                }
                temp = srcStatResult.Rows[displayRowNum[0] - 3][col];
                if (float.TryParse(temp, out value))
                {
                    foreach (int rowNum in displayRowNum)
                    {
                        rowTemp.AddRange(newRows[rowNum - 3]);
                        rowTemp.Add(AverageCell(displayRowNum[0] + 4, displayRowNum[displayRowNum.Count - 1] + 4, col + startCol));
                        rowTemp.Add(AverageDenCell(rowNum + 4, col + startCol, addColIndex + startCol));
                        rowTemp.Add(AverageDenPeCell(rowNum + 4, addColIndex + 1 + startCol, addColIndex + startCol));
                        newRows[rowNum - 3] = rowTemp.ToArray();
                        rowTemp.Clear();
                    }
                    addColIndex += 3;
                    if (!newColumns.Contains(newColumns[col] + "均值"))
                    {
                        newColumns.AddRange(new string[] { newColumns[col] + "均值", newColumns[col] + "距平", newColumns[col] + "距平率" });
                    }
                }
                else
                {
                    startCol++;
                }
            }
            return(new StatResult("", newColumns.ToArray(), newRows.ToArray()));
        }
示例#18
0
        public string StatResultToFile(string[] files, IStatResult results, string productIdentify, string outputIdentify, string title, string extinfo)
        {
            string filename = GetFileName(files, productIdentify, outputIdentify, ".XLSX", extinfo);

            if (string.IsNullOrEmpty(filename))
            {
                return(string.Empty);
            }
            try
            {
                if (File.Exists(filename))
                {
                    File.Delete(filename);
                }
                using (StatResultToExcelFile excelControl = new StatResultToExcelFile())
                {
                    excelControl.Init();
                    excelControl.Add(true, title, results, true, 1);
                    if (!filename.ToUpper().EndsWith(".XLSX"))
                    {
                        filename += ".XLSX";
                    }
                    excelControl.SaveFile(filename);
                }
            }
            catch (Exception)
            {
                using (StatResultToTxtFile txtControl = new StatResultToTxtFile())
                {
                    if (!filename.ToUpper().EndsWith(".TXT"))
                    {
                        filename += ".TXT";
                    }
                    txtControl.WriteResultToTxt(title + "\n");
                    txtControl.WriteResultToTxt("统计日期:" + DateTime.Today.Date.ToShortDateString() + "\n");
                    txtControl.WriteResultToTxt(results);
                    bool isSave = txtControl.SaveFile(filename);
                    if (!isSave)
                    {
                        return(String.Empty);
                    }
                }
            }
            return(filename);
        }
示例#19
0
        public IExtractResult AreaStatResult(Func <Int16, bool> filter, string[] files)
        {
            object aioObj          = _argumentProvider.GetArg("AOI");
            string outFileIdentify = GetStringArgument("OutFileIdentify");
            string extInfos        = GetStringArgument("extinfo");
            string title           = "蓝藻当前区域面积统计";

            StatResultItem[] areaResult = AreaStat(aioObj, filter, files);
            if (areaResult == null)
            {
                return(null);
            }
            IStatResult results  = StatResultItemToIStatResult.ItemsToResults(areaResult, files);
            string      fileName = StatResultToFile(files, results, "BAG", outFileIdentify, title, extInfos, 1, false);

            //StatResultToFile(files, areaResult, productIdentify, outFileIdentify, title, extInfos, 1);
            return(new FileExtractResult(outFileIdentify, fileName));
        }
示例#20
0
        public void WriteResultToTxt(IStatResult statResult)
        {
            StringBuilder colStrBud = new StringBuilder();

            foreach (string s in statResult.Columns)
            {
                colStrBud.Append(s.PadRight(15, ' ') + "\t");
            }
            colStrBud.Append("\n");
            _strList.Add(colStrBud.ToString());
            int col = statResult.Rows[0].Count();
            int row = statResult.Rows.Length;

            for (int i = 0; i < row; i++)
            {
                WriteResultToTxt(statResult.Rows[i], "\t");
                _strList.Add("\n");
            }
        }
        private IStatResult AddDate(IStatResult curStatResult, string date)
        {
            List <string>   columns  = new List <string>();
            List <string[]> statRows = new List <string[]>();
            List <string>   rowTemp  = new List <string>();

            columns.AddRange(curStatResult.Columns);
            columns.Insert(1, "时间");
            for (int i = 0; i < curStatResult.Rows.Length; i++)
            {
                rowTemp.AddRange(curStatResult.Rows[i]);
                rowTemp.Insert(1, date);
                statRows.Add(rowTemp.ToArray());
                rowTemp.Clear();
            }
            StringArrayComparer comparer = new StringArrayComparer(true);

            statRows.Sort(comparer);
            return(new StatResult("", columns.ToArray(), statRows.ToArray()));
        }
        //private string CreatTitleByFileName(string fname)
        //{
        //    RasterIdentify id = new RasterIdentify(fname);
        //    string identify = id.SubProductIdentify;
        //    if (string.IsNullOrEmpty(identify))
        //        return null;
        //    switch (identify)
        //    {
        //        case "NDVI":
        //            return "植被指数NDVI面积统计";
        //        case "0RVI":
        //            return "植被指数RVI面积统计";
        //        case "0EVI":
        //            return "植被指数EVI面积统计";
        //        case "0DVI":
        //            return "植被指数DVI面积统计";
        //        case "0VCI":
        //            return "植被状态指数面积统计";
        //        case "CHAZ":
        //            return "植被指数差值面积统计";
        //        default:
        //            return "植被指数面积统计";
        //    }
        //}

        private bool TryCreatExcelFile(IStatResult StatResult, string productTitle, string outFileName)
        {
            try
            {
                if (File.Exists(outFileName))
                {
                    File.Delete(outFileName);
                }
                using (StatResultToExcelFile excelControl = new StatResultToExcelFile())
                {
                    excelControl.Init();
                    excelControl.Add(true, productTitle, StatResult, true, 1);
                    if (!outFileName.ToUpper().EndsWith(".XLSX"))
                    {
                        outFileName += ".XLSX";
                    }
                    excelControl.SaveFile(outFileName);
                }
                return(true);
            }
            catch (Exception)
            {
                using (StatResultToTxtFile txtControl = new StatResultToTxtFile())
                {
                    if (!outFileName.ToUpper().EndsWith(".TXT"))
                    {
                        outFileName += ".TXT";
                    }
                    txtControl.WriteResultToTxt(productTitle + "\n");
                    txtControl.WriteResultToTxt("统计日期:" + DateTime.Today.Date.ToShortDateString() + "\n");
                    txtControl.WriteResultToTxt(StatResult);
                    bool isSave = txtControl.SaveFile(outFileName);
                    if (!isSave)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
示例#23
0
        private Dictionary <string, StatInfoBase[]> GetDayInfo(string filename, string key, Dictionary <string, StatInfoBase[]> subResult, ref StatInfoBase statInfo, IArgumentProvider argProvider, Action <int, string> progressTracker)
        {
            IStatResult result = CalcAreaByAlgorithmOneFile(argProvider, progressTracker, filename);

            if (result == null)
            {
                return(subResult);
            }
            statInfo.DayStatResult = result;
            if (!subResult.ContainsKey(key))
            {
                subResult.Add(key, new StatInfoBase[] { statInfo });
            }
            else
            {
                List <StatInfoBase> temp = new List <StatInfoBase>();
                temp.AddRange(subResult[key]);
                temp.Add(statInfo);
                subResult[key] = temp.ToArray();
            }
            return(subResult);
        }
示例#24
0
        private IExtractResult StatRasterByVector(string instanceName, string aoiTemplate, Dictionary <string, Func <float, bool> > filters, Action <int, string> progressTracker)
        {
            object aioObj = _argumentProvider.GetArg("AOI");
            string title  = GetStringArgument("title");

            string[] files           = GetStringArray("SelectedPrimaryFiles");
            string   extInfos        = GetStringArgument("extinfo");
            string   outFileIdentify = GetStringArgument("OutFileIdentify");//outfileidentify
            string   statname        = GetStringArgument("statname");
            string   productName     = _subProductDef.ProductDef.Name;
            string   productIdentify = _subProductDef.ProductDef.Identify;
            Dictionary <string, SortedDictionary <string, double> > dic = null;

            if (files == null || files.Length == 0)
            {
                return(null);
            }
            foreach (string file in files)
            {
                dic = RasterStatFactory.Stat(files[0], aoiTemplate, filters, progressTracker);
            }
            dic = RasterStatFactory.Stat(files[0], aoiTemplate, filters, progressTracker);
            if (dic == null || dic.Count == 0)
            {
                return(null);
            }
            title = productName + statname + instanceName;
            string      subTitle = GetSubTitle(files);
            IStatResult results  = DicToStatResult(dic, filters.Keys.ToArray(), subTitle);

            if (results == null)
            {
                return(null);
            }
            string filename = StatResultToFile(files, results, productIdentify, outFileIdentify, title, extInfos, 1, true, 1);

            return(new FileExtractResult(outFileIdentify, filename));
        }
示例#25
0
        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
        }
示例#26
0
        public string StatResultToFile(string[] files, StatResultItem[] resultItems, string productIdentify, string outputIdentify, string title, string extinfo)
        {
            IStatResult results = StatResultItemToIStatResult.ItemsToResults(resultItems);

            return(StatResultToFile(files, results, productIdentify, outputIdentify, title, extinfo));
        }
示例#27
0
        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);
                }
            }
        }
示例#28
0
        private IExtractResult TSTATAlgorithmStat(string outId, SubProductInstanceDef instance, Dictionary <string, Func <short, bool> > filters, Action <int, string> progressTracker)
        {
            string[]        files     = GetStringArray("SelectedPrimaryFiles");
            IStatResult     temp      = null;
            List <string>   colums    = new List <string>();
            List <string[]> rowTemp   = new List <string[]>();
            IStatResult     dstResult = null;
            RasterIdentify  rid       = null;
            string          dateStr   = _argumentProvider.GetArg("tostringtype").ToString();
            int             fileIndex = 0;
            float           step      = 90f / files.Length;

            try
            {
                if (outId == "CCAR")
                {
                    foreach (string file in files)
                    {
                        if (progressTracker != null)
                        {
                            progressTracker.Invoke((int)Math.Ceiling(fileIndex * step), "正在统计第[" + fileIndex + "]个文件,请稍后...");
                        }
                        temp = StatRasterToStatResult <short>(instance, new string[] { file }, filters, progressTracker);
                        rid  = new RasterIdentify(file);
                        foreach (string[] cols in temp.Rows)
                        {
                            cols[0] = rid.OrbitDateTime.ToString(dateStr);
                            rowTemp.Add(cols);
                        }
                        if (colums.Count == 0)
                        {
                            colums.AddRange(temp.Columns);
                        }
                    }
                    rowTemp.Sort((before, last) => before.First().CompareTo(last.First()));
                    dstResult = new StatResult(null, colums.ToArray(), rowTemp.ToArray());
                    if (progressTracker != null)
                    {
                        progressTracker.Invoke(95, "正在写入统计信息,请稍后...");
                    }
                    return(new FileExtractResult("LST", StatResultToFile(files, dstResult, "LST", "T" + outId.Substring(0, 3), "", "", 1, false)));
                }
                if (instance.AOIProvider == "省级行政区划" || instance.AOIProvider == "土地利用类型")
                {
                    string        statVector = instance.AOIProvider == "省级行政区划" ? "行政区划" : "土地利用类型";
                    string        title;
                    string[]      colDescs;
                    IStatResult[] tempArray      = null;
                    IStatResult[] dstResultArray = null;
                    List <string> tempList       = null;
                    foreach (string file in files)
                    {
                        fileIndex++;
                        if (progressTracker != null)
                        {
                            progressTracker.Invoke((int)Math.Ceiling(fileIndex * step), "正在统计第[" + fileIndex + "]个文件,请稍后...");
                        }
                        tempArray = StatProcentRasterToStatResult(file, statVector, filters, null, out title, out colDescs, true);
                        if (dstResultArray == null)
                        {
                            dstResultArray = new IStatResult[tempArray.Length];
                        }
                        rid = new RasterIdentify(file);
                        for (int i = 0; i < dstResultArray.Length; i++)
                        {
                            try
                            {
                                foreach (string[] cols in tempArray[i].Rows)
                                {
                                    tempList = new List <string>();
                                    tempList.AddRange(cols);
                                    tempList.Insert(1, rid.OrbitDateTime.ToString(dateStr));
                                    rowTemp.Add(tempList.ToArray());
                                }
                                if (colums.Count == 0)
                                {
                                    tempList = new List <string>();
                                    tempList.AddRange(tempArray[i].Columns);
                                    tempList.Insert(1, "日期");
                                    colums.AddRange(tempList.ToArray());
                                }
                                if (dstResultArray[i] == null)
                                {
                                    dstResultArray[i] = new StatResult(null, colums.ToArray(), rowTemp.ToArray());
                                }
                                else
                                {
                                    List <string[]> tempRowsFromArray = new List <string[]>();
                                    tempRowsFromArray.AddRange(dstResultArray[i].Rows);
                                    tempRowsFromArray.AddRange(rowTemp.ToArray());
                                    StringArrayComparer comparer = new StringArrayComparer(true);
                                    tempRowsFromArray.Sort(comparer);
                                    dstResultArray[i] = new StatResult(null, colums.ToArray(), tempRowsFromArray.ToArray());
                                }
                            }
                            finally
                            {
                                colums.Clear();
                                rowTemp.Clear();
                            }
                        }
                    }
                    if (progressTracker != null)
                    {
                        progressTracker.Invoke(95, "正在写入统计信息,请稍后...");
                    }
                    string              outFileIdentify  = GetStringArgument("OutFileIdentify");
                    string[]            outFileIdentifys = new string[] { "T" + outFileIdentify.Substring(0, 3), "T" + outFileIdentify.Substring(0, 2) + "P" };
                    IExtractResultArray array            = new ExtractResultArray("LST");
                    for (int i = 0; i < dstResultArray.Length; i++)
                    {
                        List <RowDisplayDef> rowRulers     = new List <RowDisplayDef>();
                        List <int>           displayRowNum = new List <int>();
                        int    count  = -1;
                        string befStr = dstResultArray[i].Rows[0].First();
                        for (int row = 0; row < dstResultArray[i].Rows.Length; row++)
                        {
                            count++;
                            if (dstResultArray[i].Rows[row].First() == befStr)
                            {
                                displayRowNum.Add(count + 3);
                                continue;
                            }
                            AddRowRuler(ref rowRulers, displayRowNum, dstResultArray[i].Rows[row - 1][0], true, false, false);
                            displayRowNum.Clear();
                            befStr = dstResultArray[i].Rows[row].First();
                            displayRowNum.Add(count + 3);
                        }
                        AddRowRuler(ref rowRulers, displayRowNum, befStr, true, false, false);
                        array.Add(new FileExtractResult("LST", StatResultToFile(files, dstResultArray[i], "LST", outFileIdentifys[i], "", "", 1, rowRulers, 3, (dstResultArray[i].Columns.Length - 2))));
                    }
                    return(array);
                }
            }
            finally
            {
                if (progressTracker != null)
                {
                    progressTracker.Invoke(100, "完成统计分析!");
                }
            }
            PrintInfo("指定的算法\"" + instance.Name + "\"没有实现。");
            return(null);
        }
示例#29
0
        public void Append(bool singleFile, IStatResult result, bool displayDataLabel, bool isTotal, int statImage)
        {
            if (result == null)
            {
                return;
            }
            bCol        = initBCol;
            currentBRow = bRow;
            currentBCol = bCol;
            currentCol  = -1;
            winExcelControl1.SetCellValue(bRow, bCol, bRow, bCol + result.Columns.Length - 1 - _indexies.Count, 1, masExcelAlignType.Center, Text.Replace(".", ""), "@");
            bRow++;
            winExcelControl1.SetCellValue(bRow, bCol, bRow, bCol + result.Columns.Length - 1 - _indexies.Count, 1, masExcelAlignType.General, result.Title, null);
            if (result.Columns != null && result.Columns.Length > 0)
            {
                bRow++;
                foreach (string colname in result.Columns)
                {
                    currentCol++;
                    if (_indexies.Contains(currentCol))
                    {
                        continue;
                    }
                    winExcelControl1.SetCellValue(bRow, bCol, 1, masExcelAlignType.General, colname, null);
                    winExcelControl1.SetBackColor(bRow, bCol, bRow, bCol, 216, 216, 216);
                    bCol++;
                }
            }
            //
            int statBRow = bRow + 1;

            if (result.Rows != null && result.Rows.Length > 0)
            {
                foreach (string[] row in result.Rows)
                {
                    currentCol = -1;
                    bCol       = initBCol;
                    bRow++;
                    foreach (string colContext in row)
                    {
                        currentCol++;
                        if (_indexies.Contains(currentCol))
                        {
                            continue;
                        }
                        winExcelControl1.SetCellValue(bRow, bCol, 1, masExcelAlignType.General, SetRound(colContext), null);
                        bCol++;
                    }
                    SupplySpace(singleFile, result);
                }
                if (isTotal && result.Rows.Length != 1)
                {
                    winExcelControl1.SetTotalCellValue(statBRow - 1, initBCol, bRow, initBCol + result.Columns.Length - 1 - _indexies.Count, bCol, 1, masExcelAlignType.General, null);
                }
            }
            if (statImage != 0)
            {
                winExcelControl1.DrawStat(statBRow - 1, initBCol, bRow, initBCol + result.Columns.Length - 1 - _indexies.Count, "图表", Text.Replace(".", ""), "",
                                          result.Columns[1].IndexOf("(") != -1 ? (result.Columns[1].Substring(result.Columns[1].IndexOf("(") + 1, result.Columns[1].IndexOf(")") - result.Columns[1].IndexOf("(") - 1)) : "",
                                          _masExcelDrawStatType, displayDataLabel);
            }
            bRow += 3;
        }
示例#30
0
        private IExtractResult SateValAlgorithm(Action <int, string> progressTracker)
        {
            ValArguments args = _argumentProvider.GetArg("SateArgs") as ValArguments;

            if (args == null)
            {
                return(null);
            }
            string toValFile  = args.FileNamesToVal[0];
            string forValFile = args.FileNamesForVal[0];
            string invalid    = args.Invalid;
            //先判断时间是否一样
            string toValDate  = "0000";
            string forValDate = "0000";

            try
            {
                foreach (Regex dt in DataReg)
                {
                    Match m1 = dt.Match(Path.GetFileName(toValFile));
                    Match m2 = dt.Match(Path.GetFileName(forValFile));
                    if (m1.Success)
                    {
                        toValDate = m1.Value;
                    }
                    if (m2.Success)
                    {
                        forValDate = m2.Value;
                    }
                }
                if (toValDate == "0000" || forValDate == "0000")
                {
                    MessageBox.Show("数据文件时间为空,默认两文件时间相符");
                }
                else
                {
                    int      year     = Convert.ToInt32(toValDate.Substring(0, 4));
                    int      month    = Convert.ToInt32(toValDate.Substring(4, 2));
                    int      day      = Convert.ToInt32(toValDate.Substring(6, 2));
                    DateTime datetime = new DateTime(year, month, day);
                    string   days     = Convert.ToString(datetime.DayOfYear);

                    if (days != forValDate.Substring(1))
                    {
                        MessageBox.Show("提示:对比数据时间不同");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("异常信息:" + ex.Message);
            }
            //再看两个数据范围是否相同
            IRasterDataProvider forValRaster = GeoDataDriver.Open(forValFile) as IRasterDataProvider;
            IRasterDataProvider toValRaster  = GeoDataDriver.Open(toValFile) as IRasterDataProvider;

            if (forValRaster.CoordEnvelope.MaxX != toValRaster.CoordEnvelope.MaxX ||
                forValRaster.CoordEnvelope.MinX != toValRaster.CoordEnvelope.MinX ||
                forValRaster.CoordEnvelope.MaxY != toValRaster.CoordEnvelope.MaxY ||
                forValRaster.CoordEnvelope.MinY != toValRaster.CoordEnvelope.MinY ||
                toValRaster.Height != forValRaster.Height || toValRaster.Width != toValRaster.Width)
            {
                MessageBox.Show("两个数据空间范围不一致");
                //这里也可修改为读取两数据的交差范围,做直方图
                return(null);
            }
            #region//读取数据
            Int16[]     toValbuffer  = new Int16[toValRaster.Height * toValRaster.Width];
            Int16[]     forValbuffer = new Int16[toValRaster.Height * toValRaster.Width];
            Int16[]     toVal        = new Int16[toValRaster.Height * toValRaster.Width];
            Int16[]     forVal       = new Int16[toValRaster.Height * toValRaster.Width];
            IRasterBand toValBand    = toValRaster.GetRasterBand(1);
            IRasterBand forValBand   = forValRaster.GetRasterBand(1);
            unsafe
            {
                fixed(Int16 *pointer = toValbuffer)
                {
                    IntPtr ptr = new IntPtr(pointer);

                    toValBand.Read(0, 0, toValRaster.Width, toValRaster.Height, ptr, toValRaster.DataType,
                                   toValRaster.Width, toValRaster.Height);
                    for (int i = 0; i < toValRaster.Height * toValRaster.Width; i++)
                    {
                        toVal[i] = toValbuffer[i];
                    }
                }

                fixed(Int16 *pointer = forValbuffer)
                {
                    IntPtr ptr = new IntPtr(pointer);

                    forValBand.Read(0, 0, forValRaster.Width, forValRaster.Height, ptr, forValRaster.DataType,
                                    forValRaster.Width, forValRaster.Height);
                    for (int i = 0; i < forValRaster.Height * forValRaster.Width; i++)
                    {
                        forVal[i] = forValbuffer[i];
                    }
                }
            }
            #endregion
            IExtractResultArray array = new ExtractResultArray("统计表格");
            if (args.CreatHistogram)
            {
                List <string[]> listRowHist  = new List <string[]>();
                string          histfilename = "";
                IStatResult     fresult      = null;
                int             maxcol       = 10;
                if (!String.IsNullOrEmpty(args.MaxColumns))
                {
                    maxcol = Convert.ToInt32(args.MaxColumns);
                }
                IStaticComputer <Int16> computer = new StaticComputerInt16();
                listRowHist = computer.ComputeDeviation(toVal, forVal, GetInvalidArray(args.Invalid), GetInvalidArray(args.ForInvalid), maxcol);
                string   sentitle = "统计日期:" + DateTime.Now.ToShortDateString();
                string[] columns  = new string[] { "偏差值", "累加值" };
                fresult = new StatResult(sentitle, columns, listRowHist.ToArray());
                string title = "陆表温度产品偏差直方图";
                histfilename = StatResultToFile(new string[] { toValFile }, fresult, "VAL", "HIST", title, null, 1, true, 1);
                IFileExtractResult res = new FileExtractResult("HIST", histfilename);
                array.Add(res);
            }
            if (args.CreatRMSE)
            {
                IStaticComputer <Int16> computer = new StaticComputerInt16();
                double rmse = computer.ComputeRMSE(toVal, forVal, GetInvalidArray(args.Invalid), GetInvalidArray(args.ForInvalid));
                MessageBox.Show("数据均方根误差是:" + Convert.ToString(rmse));
            }
            #region  用这种方式出栅格数据的散点图
            //if (args.CreatScatter)
            //{
            //    List<string[]> listRow = new List<string[]>();    //散点图
            //    for (int i = 0; i < toValRaster.Height * toValRaster.Width; i++)
            //    {
            //        //剔除无效值
            //        if (!String.IsNullOrEmpty(args.invalid))
            //        {
            //            if (args.invalid.Contains(Convert.ToString(toVal[i])) || args.invalid.Contains(Convert.ToString(forVal[i])))
            //            {
            //            }
            //            else
            //            {
            //                string[] row = new string[] { Convert.ToString(toVal[i]), Convert.ToString(forVal[i]) };
            //                listRow.Add(row);

            //            }
            //        }
            //        else
            //        {
            //            string[] row = new string[] { Convert.ToString(toVal[i]), Convert.ToString(forVal[i]) };
            //            listRow.Add(row);
            //        }
            //    }
            //    string[][] rows = listRow.ToArray();
            //    IStatResult result = new StatResult("统计时间:", new string[] { "待验证云参数", "MOD06云产品" }, rows);
            //    string title = "陆表温度数据与MODIS LST对比";
            //    string filename = "";
            //    try
            //    {
            //        using (StatResultToChartInExcelFile excelControl = new StatResultToChartInExcelFile())
            //        {
            //            excelControl.Init(masExcelDrawStatType.xlXYScatter);
            //            excelControl.Add("数据对比", result, true, 0, false, result.Columns[0], result.Columns[1
            //                ]);
            //            filename = StatResultToFile(new string[] { toValFile }, result, "VAL", "SCAT", title, null, 1, true, 1);
            //            if (!filename.ToUpper().EndsWith(".XLSX"))
            //                filename += ".XLSX";
            //            excelControl.SaveFile(filename);
            //            IFileExtractResult res = new FileExtractResult("SCAT", filename);
            //            array.Add(res);
            //        }
            //    }
            //    catch (Exception ex)
            //    {

            //    }
            //}
            #endregion
            return(array);
        }