Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //using (MemoryMappedFile mmf = MemoryMappedFile.CreateFromFile(
            //    "f:\\mmf.dat", FileMode.Create, "mmf", ((long)10000 * (long)10000)))
            //{
            //    MemoryMappedViewAccessor acc = mmf.CreateViewAccessor();
            //}
            string      filename = @"G:\1.xlsx";
            IStatResult result   = new StatResult("统计时间:", new string[] { "时间", "待验证数据", "验证数据" }, new string[][] { new string[] { "2013/3/1", "5.4", "4.9" }, new string[] { "2013/3/2", "3.9", "2.8" }, new string[] { "2013/3/3", "8.9", "8.8" }, new string[] { "2013/3/4", "7.8", "7.4" } });

            try
            {
                using (StatResultToChartInExcelFile excelControl = new StatResultToChartInExcelFile())
                {
                    excelControl.Init(masExcelDrawStatType.xlXYScatter);
                    excelControl.Add("气溶胶产品数据对比", result, true, 1, false, result.Columns[1], result.Columns[2
                                     ]);
                    if (!filename.ToUpper().EndsWith(".XLSX"))
                    {
                        filename += ".XLSX";
                    }
                    excelControl.SaveFile(filename);
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
        private IExtractResult DataVal(ValArguments args)
        {
            //分波长,每个波长多时次进行验证(前提各时次地理位置相同)
            //2,3,4
            IVectorFeatureDataReader reader = AeronetDataReaderFactory.GetVectorFeatureDataReader(args.FileNamesToVal[0], new object[] { "LEV20" });

            Dictionary <string, List <AslDataSet> >[] fieldValue = new Dictionary <string, List <AslDataSet> >[] { new Dictionary <string, List <AslDataSet> > {
                                                                                                                   },
                                                                                                                   new Dictionary <string, List <AslDataSet> > {
                                                                                                                   }, new Dictionary <string, List <AslDataSet> > {
                                                                                                                   } }; ///分别为470,550,650波长,每个字典分别为站点名为关键字,值为观测站点值的时间序列
            foreach (string item in args.FileNamesForVal)
            {
                RasterIdentify rid = new RasterIdentify(item);
                using (IRasterDataProvider dataPrd2Val = GeoDataDriver.Open(item) as IRasterDataProvider)
                {
                    //470
                    for (int bandNo = 2; bandNo < 5; bandNo++)
                    {
                        string description = dataPrd2Val.GetRasterBand(bandNo).Description;
                        string key         = Regex.Match(description, pattern).ToString();
                        int    bandLength  = Int32.Parse(key);
                        int    fieldIndex  = 0;
                        //求验证数据中的Field
                        for (int i = 5; i < 20; i++)
                        {
                            if (bandLength >= GetBandLength(reader.Fields[i]) &&
                                bandLength < GetBandLength(reader.Fields[i - 1]))
                            {
                                fieldIndex = i;
                                break;
                            }
                        }
                        //验证数据中在范围内时间内的Feature
                        string    timeString   = rid.OrbitDateTime.ToString("dd:MM:yyyy");
                        string    t3           = rid.OrbitDateTime.ToString("yyyy/MM/dd");
                        Feature[] feature4Vals = GetValFeature(reader.Features, dataPrd2Val.CoordEnvelope, timeString);
                        foreach (Feature fet in feature4Vals)
                        {
                            //已存在该站点
                            string location  = fet.FieldValues[0];
                            double value4Val = StringToDouble(fet.FieldValues, fieldIndex);
                            if (value4Val == -9999)
                            {
                                continue;
                            }
                            double value2Val = ReadDataValueInRaster(dataPrd2Val, fet.Geometry.Envelope.MinX, fet.Geometry.Envelope.MinY, bandNo);
                            if (value2Val < 0)//去除无效值
                            {
                                continue;
                            }
                            if (fieldValue[bandNo - 2].ContainsKey(location))
                            {
                                fieldValue[bandNo - 2][location].Add(new AslDataSet(t3, new double[] { value2Val, value4Val }));
                            }
                            else
                            {
                                fieldValue[bandNo - 2].Add(location, new List <AslDataSet> {
                                    new AslDataSet(t3, new double[] { value2Val, value4Val })
                                });
                            }
                        }
                    }
                }
            }
            IExtractResultArray array = new ExtractResultArray("统计表格");

            //生成结果
            if (args.CreatScatter)
            {
                for (int i = 0; i < fieldValue.Length; i++)
                {
                    foreach (string key in fieldValue[i].Keys)
                    {
                        List <string[]> rowList = new List <string[]>();
                        foreach (AslDataSet set in fieldValue[i][key])
                        {
                            rowList.Add(new string[] { set.DateString, set.SiteValue[0].ToString(), set.SiteValue[1].ToString() });
                        }
                        string[][]  rows     = rowList.ToArray();
                        IStatResult result   = new StatResult("站点名称:" + key + "波长:" + GetBandLength(i), new string[] { "时间", "待验证ASL", "Aeronet LST" }, rows);
                        string      title    = "气溶胶产品数据对比";
                        string      filename = GetOutputFileName(args.FileNamesForVal, "SCAT", key, GetBandLength(i));
                        try
                        {
                            using (StatResultToChartInExcelFile excelControl = new StatResultToChartInExcelFile())
                            {
                                excelControl.Init(masExcelDrawStatType.xlXYScatter);
                                excelControl.Add(title, result, true, 1, false, result.Columns[1], result.Columns[2]);
                                if (!filename.ToUpper().EndsWith(".XLSX"))
                                {
                                    filename += ".XLSX";
                                }
                                excelControl.SaveFile(filename);
                                IFileExtractResult res = new FileExtractResult("SCAT", filename);
                                array.Add(res);
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
            if (args.CreatTimeSeq)
            {
                for (int i = 0; i < fieldValue.Length; i++)
                {
                    foreach (string key in fieldValue[i].Keys)
                    {
                        List <string[]> rowList = new List <string[]>();
                        foreach (AslDataSet set in fieldValue[i][key])
                        {
                            rowList.Add(new string[] { set.DateString, set.SiteValue[0].ToString(), set.SiteValue[1].ToString() });
                        }
                        string[][]  rows     = rowList.ToArray();
                        IStatResult result   = new StatResult("站点名称:" + key + "波长:" + GetBandLength(i), new string[] { "时间", "待验证ASL", "Aeronet LST" }, rows);
                        string      title    = "气溶胶产品数据对比";
                        string      filename = GetOutputFileName(args.FileNamesForVal, "SEQD", key, GetBandLength(i));
                        try
                        {
                            using (StatResultToChartInExcelFile excelControl = new StatResultToChartInExcelFile())
                            {
                                excelControl.Init(masExcelDrawStatType.xlLineMarkers);
                                excelControl.Add(title, result, true, 0, true, result.Columns[0], "ASL");
                                if (!filename.ToUpper().EndsWith(".XLSX"))
                                {
                                    filename += ".XLSX";
                                }
                                excelControl.SaveFile(filename);
                                IFileExtractResult res = new FileExtractResult("SEQD", filename);
                                array.Add(res);
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
            return(array);
        }