Пример #1
0
        private StatResultItem[] ApplyStatByVectorFile(IRasterDataProvider prd, Dictionary <string, int[]> aoi)
        {
            if (aoi == null || aoi.Count == 0)
            {
                return(null);
            }
            double totalArea            = 0;
            List <StatResultItem> items = new List <StatResultItem>();

            foreach (string fea in aoi.Keys)
            {
                if (aoi[fea] == null)
                {
                    totalArea = 0;
                }
                else
                {
                    totalArea = GetTotalArea(prd, aoi[fea]);
                }
                StatResultItem it = new StatResultItem();
                it.Name  = fea;
                it.Value = totalArea;
                items.Add(it);
            }
            return(items != null?items.ToArray() : null);
        }
Пример #2
0
        private StatResultItem[] StatAreaCustom(IRasterDataProvider prd, Dictionary <string, int[]> aoi)
        {
            StatResultItem[] results = null;
            results = ResultsWithoutZero(ApplyStatByVectorFile(prd, aoi));
            if (results == null || results.Length == 0)
            {
                return(null);
            }
            List <StatResultItem> primaryItems = new List <StatResultItem>();
            StatResultItem        item         = null;

            foreach (string name in aoi.Keys)
            {
                item = MatchItemInResults(name, results);
                if (item != null)
                {
                    primaryItems.Add(item);
                }
            }
            if (primaryItems.Count == 0)
            {
                return(null);
            }
            return(primaryItems.ToArray());
        }
Пример #3
0
 private StatResultItem[] CountByLandRaster(IRasterDataProvider raster)
 {
     using (IRasterDictionaryTemplate <byte> temp = RasterDictionaryTemplateFactory.CreateLandRasterTemplate())
     {
         Dictionary <byte, string> paris = temp.CodeNameParis;
         if (paris == null)
         {
             return(null);
         }
         List <StatResultItem> items = new List <StatResultItem>();
         int[]  aoi;
         double totalArea;
         foreach (string value in paris.Values)
         {
             aoi = temp.GetAOI(value, raster.CoordEnvelope.MinX, raster.CoordEnvelope.MaxX, raster.CoordEnvelope.MinY, raster.CoordEnvelope.MaxY, new Size(raster.Width, raster.Height));
             if (aoi == null)
             {
                 continue;
             }
             totalArea = GetTotalArea(raster, aoi);
             if (totalArea == 0)
             {
                 continue;
             }
             StatResultItem it = new StatResultItem();
             it.Name  = value;
             it.Value = totalArea / _dayCount;
             items.Add(it);
         }
         return(items != null?items.ToArray() : null);
     }
 }
        private StatResultItem[] AddPercent(StatResultItem[] areaResult, double percent)
        {
            List <StatResultItem> items = new List <StatResultItem>();

            items.AddRange(areaResult);
            StatResultItem sri = new StatResultItem();

            sri.Name  = "百分比(%)";
            sri.Value = percent;
            items.Add(sri);
            return(items.ToArray());
        }
Пример #5
0
        private StatResultItem[] AreaStat(object aoiObj, Func <Int16, bool> filter, string[] files)
        {
            if (files == null || files.Length == 0)
            {
                return(null);
            }
            IStatAnalysisEngine <Int16> exe = new StatAnalysisEngine <Int16>();

            if (aoiObj as Dictionary <string, int[]> != null)
            {
                Dictionary <string, int[]> aoi   = aoiObj as Dictionary <string, int[]>;
                List <StatResultItem>      items = new List <StatResultItem>();
                IRasterDataProvider        prd   = null;
                try
                {
                    prd = GeoDataDriver.Open(files[0]) as IRasterDataProvider;
                    if (aoi == null || aoi.Count == 0)
                    {
                        return(null);
                    }
                    StatResultItem[] item = exe.StatAreaCustom(prd, aoi, filter);
                    if (item != null && item.Length > 0)
                    {
                        items.AddRange(item);
                    }
                    //
                    RasterOperator <Int16> oper = new RasterOperator <Int16>();
                    int            count        = oper.Count(prd, null, filter);
                    StatResultItem sri          = new StatResultItem();
                    sri.Name  = "整个湖区";
                    sri.Value = Math.Round(count * BAGStatisticHelper.CalPixelArea(prd.ResolutionX), 3);
                    items.Add(sri);
                    return(items.ToArray());
                }
                catch
                {
                    throw new ArgumentException("选择的文件:“" + Path.GetFileName(files[0]) + "”无法进行自定义面积统计。");
                }
                finally
                {
                    if (prd != null)
                    {
                        prd.Dispose();
                        prd = null;
                    }
                }
            }
            else
            {
                return(null);
            }
        }
Пример #6
0
        private StatResultItem MatchItemInResults(string name, StatResultItem[] results)
        {
            StatResultItem result = null;

            foreach (StatResultItem item in results)
            {
                if (name == item.Name)
                {
                    return(item);
                }
            }
            result       = new StatResultItem();
            result.Name  = name;
            result.Value = 0;
            return(result);
        }
Пример #7
0
        private StatResultItem[] DegreeStatCurrentRegion(IRasterDataProvider prd, string title)
        {
            double totalArea = 0;

            using (IArgumentProvider argPrd = new ArgumentProvider(prd, null))
            {
                using (IRasterPixelsVisitor <double> visitor = new RasterPixelsVisitor <double>(argPrd))
                {
                    visitor.VisitPixel(new int[] { 1 },
                                       (index, values) =>
                    {
                        totalArea += values[0];
                    });
                    StatResultItem sri = new StatResultItem();
                    sri.Name  = "当前区域";
                    sri.Value = (totalArea / _dayCount);
                    return(new StatResultItem[] { sri });
                }
            }
        }
        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));
        }
Пример #9
0
        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));
            }
            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);
            }
            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] {
                                "0", "0", "0"
                            });
                            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.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, "SNW", outputIdentify, title, null, 1, true, 1);
            string filename = StatResultToFile(files, fresult, "SNW", outputIdentify, title, null, 1, true, 1);

            return(new FileExtractResult(outputIdentify, filename));
        }
Пример #10
0
        private StatResultItem[] ApplyStatByVectorTemplate(IRasterDataProvider raster, string shpTemplateName, string primaryFieldName)
        {
            string shpFullname = VectorAOITemplate.FindVectorFullname(shpTemplateName);

            if (String.IsNullOrEmpty(shpFullname))
            {
                return(null);
            }
            CodeCell.AgileMap.Core.Feature[] features = null;
            //step2:读取矢量
            try
            {
                features = GetFeatures(shpFullname);
                if (features == null || features.Length == 0)
                {
                    return(null);
                }
                //step3:矢量栅格化
                Dictionary <string, Color> nameColors = new Dictionary <string, Color>();
                using (Bitmap bitmap = VectorsToBitmap(raster, features, primaryFieldName, out nameColors))
                {
                    int[]  aoi;
                    Color  color;
                    double totalArea;
                    string name;
                    List <StatResultItem> items = new List <StatResultItem>();
                    foreach (Feature fea in features)
                    {
                        name = fea.GetFieldValue(primaryFieldName);
                        if (String.IsNullOrEmpty(name))
                        {
                            continue;
                        }
                        color = nameColors[name];
                        aoi   = GetAOIByFeature(bitmap, color);
                        if (aoi == null)
                        {
                            totalArea = 0;
                        }
                        else
                        {
                            totalArea = GetTotalArea(raster, aoi);
                        }
                        StatResultItem it = new StatResultItem();
                        it.Name  = name;
                        it.Code  = fea.OID.ToString();
                        it.Value = totalArea / _dayCount;
                        items.Add(it);
                    }
                    return(items != null?items.ToArray() : null);
                }
            }
            finally
            {
                if (features != null && features.Length > 0)
                {
                    foreach (Feature item in features)
                    {
                        item.Dispose();
                    }
                }
            }
        }