private IExtractResult IMGAlgorithm()
        {
            string instanceIdentify = _argumentProvider.GetArg("OutFileIdentify") as string;

            if (string.IsNullOrWhiteSpace(instanceIdentify))
            {
                return(null);
            }
            SubProductInstanceDef instance = FindSubProductInstanceDefs(instanceIdentify);

            if (instance == null)
            {
                return(ThemeGraphyResult(null));
            }
            if (instanceIdentify == "0MSI")
            {
                return(ThemeGraphyMCSIDBLV(instance));
            }
            else if (instanceIdentify == "FLSI")
            {
                string[] files = GetStringArray("SelectedPrimaryFiles");
                if (files == null || files.Length == 0)
                {
                    TrySetSelectedPrimaryFiles(ref files);
                }
                if (files == null || files.Length == 0)
                {
                    return(null);
                }
                string colorTableFile               = ProductColorTableParser.LoadProColorTable("FLD");
                ProductColorTable[] colorTabels     = ProductColorTableParser.Parse(colorTableFile);
                ProductColorTable[] colorTabelsBack = ProductColorTableParser.Parse(colorTableFile);
                foreach (ProductColorTable pct in colorTabels)
                {
                    if (pct.ColorTableName != "FLD" + instanceIdentify)
                    {
                        continue;
                    }
                    List <int> colorNums = new List <int>();
                    using (IRasterDataProvider rdp = GeoDataDriver.Open(files[0]) as IRasterDataProvider)
                    {
                        LastDaysSetValue outLastDays = (rdp as MemoryRasterDataProvider).GetExtHeader <LastDaysSetValue>();
                        for (int i = 0; i < outLastDays.LastDaysColor.Length; i++)
                        {
                            if (outLastDays.LastDaysColor[i] == 0)
                            {
                                break;
                            }
                            colorNums.Add(outLastDays.LastDaysColor[i]);
                        }
                    }
                    if (colorNums.Count == 0)
                    {
                        break;
                    }
                    List <ProductColor> pcList = new List <ProductColor>();
                    pcList.Add(pct.ProductColors[0]);
                    pct.ProductColors[1].MaxValue  = colorNums[0] + 1;
                    pct.ProductColors[1].LableText = "  " + (pct.ProductColors[1].MaxValue - 1).ToString();
                    pcList.Add(pct.ProductColors[1]);
                    for (int i = 2; i < colorNums.Count + 1; i++)
                    {
                        pct.ProductColors[i].MinValue  = colorNums[i - 2] + 1;
                        pct.ProductColors[i].MaxValue  = colorNums[i - 1] + 1;
                        pct.ProductColors[i].LableText = "  " + (pct.ProductColors[i].MaxValue - 1).ToString();
                        pcList.Add(pct.ProductColors[i]);
                    }
                    //ProductColor newpc = new ProductColor();
                    //newpc.Color = pct.ProductColors[pct.ProductColors.Length - 3].Color;
                    //newpc.DisplayLengend = pct.ProductColors[pct.ProductColors.Length - 3].DisplayLengend;
                    //newpc.LableText = ">" + colorNums[colorNums.Count - 1] + "天";
                    //newpc.MaxValue = pct.ProductColors[pct.ProductColors.Length - 3].MaxValue;
                    //newpc.MinValue = colorNums[colorNums.Count - 1] + 1;
                    //pcList.Add(newpc);
                    pcList.Add(pct.ProductColors[pct.ProductColors.Length - 2]);
                    pcList.Add(pct.ProductColors[pct.ProductColors.Length - 1]);
                    pct.ProductColors = pcList.ToArray();
                    ProductColorTableParser.WriteToXml(colorTabels, colorTableFile);
                    ProductColorTableFactory.ReLoadAllColorTables();
                    LayoutTemplateHelper.UpdateLegend(colorTabels, null);
                    ProductColorTableParser.WriteToXml(colorTabelsBack, colorTableFile);
                }
                return(ThemeGraphyResult(null));
            }
            else
            {
                return(ThemeGraphyResult(null));
            }
        }
        private IExtractResult STATAlgorithm(Action <int, string> progressTracker)
        {
            object aioObj                  = _argumentProvider.GetArg("AOI");
            string outFileIdentify         = GetStringArgument("OutFileIdentify");
            SubProductInstanceDef instance = FindSubProductInstanceDefs(outFileIdentify);

            string[] files    = GetStringArray("SelectedPrimaryFiles");
            string   extInfos = GetStringArgument("extinfo");

            if (files == null || files.Length == 0)
            {
                return(null);
            }
            _argumentProvider.SetArg("statname", "变化水体");
            if (outFileIdentify == "COCC")
            {
                Dictionary <string, Func <short, bool> > dic = new Dictionary <string, Func <short, bool> >();
                dic.Add("扩大水体面积(平方公里)", (v) => { return(v == 4); });
                dic.Add("未变水体面积(平方公里)", (v) => { return(v == 1); });
                dic.Add("缩小水体面积(平方公里)", (v) => { return(v == 5); });
                return(StatRaster <short>(instance, dic, progressTracker));
            }
            if (outFileIdentify == "COCU")
            {
                _argumentProvider.SetArg("statname", "洪涝水体");
                Dictionary <string, Func <short, bool> > dic = new Dictionary <string, Func <short, bool> >();
                dic.Add("洪涝水体面积", (v) => { return(v == 4); });
                return(StatRaster <short>(instance, dic, progressTracker));
            }
            if (outFileIdentify == "CODU")
            {
                _argumentProvider.SetArg("statname", "洪涝水体");
                using (IRasterDataProvider rdp = GeoDataDriver.Open(files[0]) as IRasterDataProvider)
                {
                    LastDaysSetValue           outLastDays = (rdp as MemoryRasterDataProvider).GetExtHeader <LastDaysSetValue>();
                    Dictionary <string, int[]> coduDic     = new Dictionary <string, int[]>();
                    coduDic.Add("<" + outLastDays.LastDaysColor[0].ToString() + "日", new int[] { outLastDays.LastDaysColor[0], 0 });
                    for (int i = 1; i < outLastDays.LastDaysColor.Length; i++)
                    {
                        if (outLastDays.LastDaysColor[i] == 0)
                        {
                            break;
                        }
                        coduDic.Add(outLastDays.LastDaysColor[i - 1].ToString() + "日~" +
                                    outLastDays.LastDaysColor[i].ToString() + "日", new int[] { outLastDays.LastDaysColor[i - 1], outLastDays.LastDaysColor[i] });
                    }
                    Dictionary <string, Func <short, bool> > dic = new Dictionary <string, Func <short, bool> >();
                    int index = -1;
                    foreach (string key in coduDic.Keys)
                    {
                        index++;
                        string funKey = key;
                        if (index == 0)
                        {
                            dic.Add("洪涝" + key, (v) => { return(v > 0 && v <= coduDic[funKey][0]); });
                        }
                        else
                        {
                            dic.Add("洪涝" + key, (v) => { return(v > coduDic[funKey][0] && v <= coduDic[funKey][1]); });
                        }
                    }
                    return(StatRaster <short>(instance, dic, progressTracker));
                }
            }

            string title = string.Empty;

            StatResultItem[] floodResult  = CommProductStat.AreaStat <Int16>("变化水体", files[0], ref title, aioObj, (v) => { return(v == 4); });
            StatResultItem[] sameResult   = CommProductStat.AreaStat <Int16>("变化水体", files[0], ref title, aioObj, (v) => { return(v == 1); });
            StatResultItem[] reduceResult = CommProductStat.AreaStat <Int16>("变化水体", files[0], ref title, aioObj, (v) => { return(v == 5); });
            if (floodResult == null && sameResult == null && reduceResult == null)
            {
                return(null);
            }
            //增加单次面积统计百分比计算

            bool   isTotal = true;
            double floodPercent = 0, samePercent = 0, reducePercent = 0;

            if (floodResult.Length == 1 && sameResult.Length == 1 && reduceResult.Length == 1)
            {
                double histroyArea = sameResult[0].Value + reduceResult[0].Value;
                floodPercent  = Math.Round(floodResult[0].Value / histroyArea * 100, 2);
                samePercent   = Math.Round(sameResult[0].Value / histroyArea * 100, 2);
                reducePercent = Math.Round(reduceResult[0].Value / histroyArea * 100, 2);

                floodResult  = AddPercent(floodResult, floodPercent);
                sameResult   = AddPercent(sameResult, samePercent);
                reduceResult = AddPercent(reduceResult, reducePercent);
                isTotal      = false;
            }

            //
            Dictionary <string, string[]> result = new Dictionary <string, string[]>();

            StatResultItem[][] resultArray       = new StatResultItem[][] { floodResult, sameResult, reduceResult };
            for (int i = 0; i < 3; i++)
            {
                if (resultArray[i] != null && resultArray[i].Length > 0)
                {
                    foreach (StatResultItem item in resultArray[i])
                    {
                        if (result.ContainsKey(item.Name))
                        {
                            result[item.Name][i] = item.Value.ToString();
                        }
                        else
                        {
                            result.Add(item.Name, new string[3]);
                            result[item.Name][i] = item.Value.ToString();
                        }
                    }
                }
            }
            if (result.Count == 0)
            {
                return(null);
            }
            List <string[]> resultList = new List <string[]>();

            foreach (string key in result.Keys)
            {
                resultList.Add(new string[] { key, result[key][0], result[key][1], result[key][2] });
            }
            string         sentitle = "统计日期:" + DateTime.Now.ToShortDateString();
            RasterIdentify id       = new RasterIdentify(files[0]);

            if (id.MinOrbitDate != DateTime.MinValue && id.MaxOrbitDate != DateTime.MaxValue && id.MaxOrbitDate != id.MinOrbitDate)
            {
                sentitle += "    背景水体日期:" + id.MinOrbitDate.ToShortDateString();
                sentitle += "    轨道日期:" + id.MaxOrbitDate.ToShortDateString();
            }
            else
            {
                if (id.OrbitDateTime != null)
                {
                    sentitle += "    轨道日期:" + id.OrbitDateTime.ToShortDateString();
                }
            }
            string[]    columns        = new string[] { "矢量分区", "扩大水体面积(平方公里)", "未变水体面积(平方公里)", "缩小水体面积(平方公里)" };
            IStatResult fresult        = new StatResult(sentitle, columns, resultList.ToArray());
            string      outputIdentify = _argumentProvider.GetArg("OutFileIdentify").ToString();
            string      filename       = StatResultToFile(files, fresult, "FLD", outputIdentify, title, null, 1, isTotal, 1);


            return(new FileExtractResult(outputIdentify, filename));
        }
Exemple #3
0
        private IExtractResult FLODLastFiles(string[] flodFiles, Action <int, string> progressTracker)
        {
            if (flodFiles == null || flodFiles.Length < 1)
            {
                return(null);
            }
            string[]           sortedFiles = SortFileName(flodFiles);
            List <RasterMaper> rms         = new List <RasterMaper>();
            RasterIdentify     daysByri    = null;
            List <UInt16>      days        = new List <UInt16>();
            List <UInt16>      fd3Days     = null;//三个数据时的分段日数值

            bool[] fd3Infos = new bool[7] {
                false, false, false, false, false, false, false
            };                                                                                //三个数据时的7种分段情况
            UInt16 defCloudy = (UInt16)_argumentProvider.GetArg("defCloudy");
            UInt16 defWater  = (UInt16)_argumentProvider.GetArg("defWater");
            bool   autoFJ    = bool.Parse(_argumentProvider.GetArg("autoFJ").ToString());

            try
            {
                foreach (string file in sortedFiles)
                {
                    IRasterDataProvider flodRaster = RasterDataDriver.Open(file) as IRasterDataProvider;
                    RasterMaper         rm         = new RasterMaper(flodRaster, new int[] { 1 });
                    rms.Add(rm);
                    daysByri = new RasterIdentify(file);
                    days.Add((UInt16)((DateTime.Parse(daysByri.MaxOrbitDate.ToShortDateString()) - DateTime.Parse(daysByri.MinOrbitDate.ToShortDateString())).Days));
                }
                int extendHeaderLength = days.Count * 2;
                if (days.Count == 3)
                {
                    fd3Days = SetFD3Days(days);
                }
                //输出文件准备(作为输入栅格并集处理)
                RasterIdentify ri          = GetRasterIdentifyID(flodFiles, null);
                string         outFileName = ri.ToWksFullFileName(".dat");
                //创建结果数据
                using (IRasterDataProvider outRaster = CreateOutRaster(outFileName, rms.ToArray(), extendHeaderLength))
                {
                    //栅格数据映射
                    RasterMaper[] fileIns  = rms.ToArray();
                    RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                    //创建处理模型
                    RasterProcessModel <UInt16, UInt16> rfr = null;
                    rfr = new RasterProcessModel <UInt16, UInt16>(progressTracker);
                    rfr.SetRaster(fileIns, fileOuts);
                    int           fileCount = fileIns.Length;
                    List <UInt16> everyDays = new List <UInt16>();
                    rfr.RegisterCalcModel(new RasterCalcHandler <UInt16, UInt16>((rvInVistor, rvOutVistor, aoi) =>
                    {
                        int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX;
                        for (int i = 0; i < dataLength; i++)
                        {
                            if (rvInVistor[0].RasterBandsData[0][i] == 4)
                            {
                                everyDays.Add(days[0]);
                            }
                            else if (rvInVistor[0].RasterBandsData[0][i] == 1 || rvInVistor[0].RasterBandsData[0][i] == 5)
                            {
                                everyDays.Add(defWater);
                            }
                            for (int fileIndex = 1; fileIndex < fileCount; fileIndex++)
                            {
                                if ((rvInVistor[fileIndex].RasterBandsData[0][i] == 4) || ProIsFlood(rvInVistor, i, fileIndex))
                                {
                                    everyDays.Add(days[fileIndex]);
                                }
                                else
                                {
                                    everyDays.Add(0);
                                }
                            }
                            rvOutVistor[0].RasterBandsData[0][i] = AnalysisLastDays(everyDays, fd3Days, ref fd3Infos);
                            everyDays.Clear();
                        }
                    }));
                    //执行
                    rfr.Excute();
                    FileExtractResult res = new FileExtractResult(_subProductDef.Identify, outFileName, true);
                    res.SetDispaly(false);
                    LastDaysSetValue extHeader = SetColorLegend(fd3Days, fd3Infos);
                    (outRaster as MemoryRasterDataProvider).SetExtHeader <LastDaysSetValue>(extHeader, extendHeaderLength);
                    return(res);
                }
            }
            finally
            {
                foreach (RasterMaper rm in rms)
                {
                    rm.Raster.Dispose();
                }
            }
        }