コード例 #1
0
        private Dictionary <string, int[]> GetAOIForRaster(IRasterDataProvider dataProvider)
        {
            Dictionary <string, string> templates = BAGStatisticHelper.GetAOITemplateList();

            if (templates == null || templates.Count == 0)
            {
                return(null);
            }
            Dictionary <string, int[]> aoiValues = new Dictionary <string, int[]>();

            foreach (string templateName in templates.Keys)
            {
                //分湖区
                Dictionary <string, int[]> aois = VectorTemplateToAOIConvertor.GetFeatureAOIIndex(templates[templateName],
                                                                                                  "NAME", dataProvider.CoordEnvelope, new Size(dataProvider.Width, dataProvider.Height));
                if (aois != null && aois.Count != 0)
                {
                    foreach (string key in aois.Keys)
                    {
                        aoiValues.Add(key, aois[key]);
                    }
                }
            }
            return(aoiValues);
        }
コード例 #2
0
        public override IExtractResult Make(Action <int, string> progressTracker)
        {
            if (_argumentProvider == null)
            {
                return(null);
            }
            List <string> covertDegreeRegions = _argumentProvider.GetArg("CovertDegreeRegion") as List <string>;

            if (_argumentProvider.GetArg("AlgorithmName") == null || covertDegreeRegions == null || covertDegreeRegions.Count == 0)
            {
                return(null);
            }
            if (_argumentProvider.GetArg("AlgorithmName").ToString() == "BCDF")
            {
                int count = covertDegreeRegions.Count;
                ExtractResultArray results = new ExtractResultArray("BAG_BCDF");
                for (int i = 0; i < count; i++)
                {
                    float[]           minmax = BAGStatisticHelper.GetCovertDegreeValue(covertDegreeRegions[i]);
                    FileExtractResult result = FREQAlgorithm(minmax[0], minmax[1]) as FileExtractResult;
                    results.Add(result);
                }
                return(results);
            }
            return(null);
        }
コード例 #3
0
ファイル: SubProductSTATBAG.cs プロジェクト: windygu/hispeed
        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);
            }
        }
コード例 #4
0
ファイル: SubProductSTATBAG.cs プロジェクト: windygu/hispeed
        private IExtractResult STATAlgorithm(string[] files)
        {
            string outFileIdentify = _argumentProvider.GetArg("OutFileIdentify").ToString();

            if (outFileIdentify == "CCCA")
            {
                return(base.AreaStatResult <Int16>("蓝藻", "BAG", (v) => { return v == 1; }));
            }
            Dictionary <string, string> templates = BAGStatisticHelper.GetAOITemplateList();

            if (templates == null || templates.Count == 0)
            {
                return(AreaStatResult <Int16>("蓝藻", "BAG", (v) => { return v == 1; }));
            }
            else
            {
                Dictionary <string, int[]> aoiValues = new Dictionary <string, int[]>();
                Size          size;
                CoordEnvelope envelope;
                GetArgument(out size, out envelope, files);
                foreach (string templateName in templates.Keys)
                {
                    //分湖区
                    Dictionary <string, int[]> aois = VectorTemplateToAOIConvertor.GetFeatureAOIIndex(templates[templateName], "NAME", envelope, size);
                    //整个湖区
                    if (aois != null && aois.Count != 0)
                    {
                        foreach (string key in aois.Keys)
                        {
                            aoiValues.Add(key, aois[key]);
                        }
                    }
                }
                if (aoiValues.Count > 0)
                {
                    _argumentProvider.SetArg("AOI", aoiValues);
                    return(AreaStatResult((v) => { return v == 1; }, files));
                }
                else
                {
                    return(AreaStatResult <Int16>("蓝藻", "BAG", (v) => { return v == 1; }));
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// 计算指定等级的总覆盖面积
        /// 例如:重度(60%-100%)
        /// 比较条件为:minConvertDegree< x && x<=  maxConvertDegree
        /// </summary>
        /// <param name="minConvertDegree"></param>
        /// <param name="maxConvertDegree"></param>
        /// <returns></returns>
        public double CalcTotalConvertArea(IRasterDataProvider dataProvider, int[] aoi, float minCovertDegree, float maxCovertDegree)
        {
            double convertArea = 0;
            IRasterOperator <float> rasterOper = new RasterOperator <float>();
            int count = rasterOper.Count(dataProvider, aoi, (value) =>
            {
                if (minCovertDegree < value && value <= maxCovertDegree)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            });
            double pixelArea = BAGStatisticHelper.CalPixelArea(dataProvider.ResolutionX);

            convertArea = count * pixelArea;
            return(convertArea);
        }
コード例 #6
0
        /// <summary>
        /// 计算云覆盖面积
        /// </summary>
        /// <returns></returns>
        public double CalcCloudConvertArea(IRasterDataProvider dataProvider, int[] aoi)
        {
            double cloudArea = 0;
            IRasterOperator <Int16> rasterOper = new RasterOperator <Int16>();
            int count = rasterOper.Count(dataProvider, aoi, (value) =>
            {
                if (value == 1)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            });
            double pixelArea = BAGStatisticHelper.CalPixelArea(dataProvider.ResolutionX);

            cloudArea = count * pixelArea;
            return(cloudArea);
        }
コード例 #7
0
        private Dictionary <string, int[]> GetAOIForRaster(IRasterDataProvider dataProvider)
        {
            Dictionary <string, string> templates = BAGStatisticHelper.GetAOITemplateList();

            if (templates == null || templates.Count == 0)
            {
                return(null);
            }
            Dictionary <string, int[]> aoiValues = new Dictionary <string, int[]>();

            foreach (string templateName in templates.Keys)
            {
                //分湖区
                Dictionary <string, int[]> aois = VectorTemplateToAOIConvertor.GetFeatureAOIIndex(templates[templateName],
                                                                                                  "NAME", dataProvider.CoordEnvelope, new Size(dataProvider.Width, dataProvider.Height));
                if (aois != null && aois.Count != 0)
                {
                    //List<int> indexForOneLake=new List<int>();
                    foreach (string key in aois.Keys)
                    {
                        aoiValues.Add(key, aois[key]);
                        //if (indexForOneLake.Count == 0)
                        //{
                        //    indexForOneLake.AddRange(aois[key]);
                        //}
                        //else
                        //{
                        //    for (int i = 0; i < aois[key].Length; i++)
                        //    {
                        //        if (indexForOneLake.Contains(aois[key][i]))
                        //            continue;
                        //        else
                        //            indexForOneLake.Add(aois[key][i]);
                        //    }
                        //}
                    }
                    //aoiValues.Add(templateName, indexForOneLake.ToArray());
                }
            }
            return(aoiValues);
        }
コード例 #8
0
        private List <string[]> StaticAreaByRegions(List <string> covertDegreeRegions, IRasterDataProvider cloudProvider, IRasterDataProvider coverDegreeProvider, int[] aoi, string regionName)
        {
            if (covertDegreeRegions == null || covertDegreeRegions.Count == 0)
            {
                return(null);
            }
            List <string[]> resultList  = new List <string[]>();
            double          cloudArea   = StatCloudConvertArea(cloudProvider, aoi);
            double          totalAreas  = 0;
            double          actualAreas = 0;

            for (int i = 0; i < covertDegreeRegions.Count; i++)
            {
                List <string> statresult = new List <string>();
                float[]       minmax     = BAGStatisticHelper.GetCovertDegreeValue(covertDegreeRegions[i]);
                //累计指定等级的总覆盖面积
                double totalArea = StatAccumulativeTotalArea(coverDegreeProvider, aoi, minmax[0], minmax[1]);
                //累计计算指定等级的实际覆盖面积
                double actualArea = StatAccumulativeActualArea(coverDegreeProvider, aoi, minmax[0], minmax[1]);
                totalAreas  += totalArea;
                actualAreas += actualArea;
                if (i == 0)
                {
                    statresult.Add(regionName);
                }
                else
                {
                    statresult.Add("");
                }
                statresult.Add(covertDegreeRegions[i]);
                statresult.Add(Math.Round(totalArea, 2).ToString());
                statresult.Add(Math.Round(actualArea, 2).ToString());
                statresult.Add(Math.Round(cloudArea, 2).ToString());
                resultList.Add(statresult.ToArray());
            }
            resultList.Add(new string[] { "", "合计", totalAreas.ToString(), actualAreas.ToString(), cloudArea.ToString() });
            return(resultList);
        }
コード例 #9
0
        /// <summary>
        /// 计算指定等级的总实际覆盖面积
        /// 比较条件为:minConvertDegree< x && x<=  maxConvertDegree
        /// </summary>
        /// <param name="dataProvider">像元覆盖度文件DataProvider</param>
        /// <param name="minConvertDegree"></param>
        /// <param name="maxConvertDegree"></param>
        /// <returns></returns>
        public double CalcActualConvertArea(IRasterDataProvider dataProvider, int[] aoi, float minConvertDegree, float maxConvertDegree)
        {
            if (dataProvider == null || minConvertDegree > maxConvertDegree)
            {
                return(0);
            }
            double                      convertArea = 0;
            double                      pixelArea   = BAGStatisticHelper.CalPixelArea(dataProvider.ResolutionX);
            ArgumentProvider            ap          = new ArgumentProvider(dataProvider, null);
            Size                        size        = new Size(dataProvider.Width, dataProvider.Height);
            Rectangle                   rect        = AOIHelper.ComputeAOIRect(aoi, size);
            RasterPixelsVisitor <float> visitor     = new RasterPixelsVisitor <float>(ap);

            visitor.VisitPixel(rect, aoi, new int[] { 1 },
                               (index, values) =>
            {
                if (values[0] <= maxConvertDegree && values[0] > minConvertDegree)
                {
                    convertArea += (pixelArea * values[0]);
                }
            });
            return(convertArea);
        }
コード例 #10
0
        public override IExtractResult Make(Action <int, string> progressTracker)
        {
            if (_argumentProvider == null || _argumentProvider.GetArg("BPCDFile") == null)
            {
                return(null);
            }
            string bPCDFName = _argumentProvider.GetArg("BPCDFile").ToString();
            string algName   = _argumentProvider.GetArg("AlgorithmName").ToString();
            string extinfo   = GetStringArgument("extinfo");

            if (string.IsNullOrEmpty(bPCDFName) || !File.Exists(bPCDFName) || string.IsNullOrEmpty(algName))
            {
                return(null);
            }
            if (_argumentProvider.AOI == null)
            {
                return(null);
            }
            //若云判识文件未给出或者文件不存在,则不计算云覆盖度
            string cloudName = string.Empty;

            if (_argumentProvider.GetArg("CLMFile") != null)
            {
                cloudName = _argumentProvider.GetArg("CLMFile").ToString();
                if (!string.IsNullOrEmpty(cloudName) && File.Exists(cloudName))
                {
                    _isComputCloudCD = true;
                }
            }
            if (algName == "BACD")
            {
                IRasterDataProvider bPCDDataProvider  = null;
                IRasterDataProvider cloudDataProvider = null;
                try
                {
                    bPCDDataProvider = GeoDataDriver.Open(bPCDFName) as IRasterDataProvider;
                    if (bPCDDataProvider == null)
                    {
                        return(null);
                    }
                    if (_isComputCloudCD)
                    {
                        cloudDataProvider = GeoDataDriver.Open(cloudName) as IRasterDataProvider;
                    }
                    //_pixelArea = new BAGStatisticHelper().CalPixelArea(bPCDDataProvider.ResolutionX);
                    //总覆盖度
                    float totalCD = StatTotalConvertDegree(bPCDDataProvider, _argumentProvider.AOI);
                    //计算实际覆盖度
                    float actualCD = CalcActualConvertDegree(bPCDDataProvider, _argumentProvider.AOI);
                    //计算相对覆盖度
                    float absoluteCD = CalcAbsoluteConvertDegree(bPCDDataProvider, _argumentProvider.AOI);
                    //计算云覆盖度(参数:云判识结果文件)
                    float           cloudCD    = CalcCloudConvertDegree(cloudDataProvider, _argumentProvider.AOI);
                    List <string[]> valueItems = new List <string[]>();
                    List <string>   valueRow   = new List <string>();
                    valueRow.Add("整个湖区");
                    valueRow.Add(Math.Round((totalCD * 100), 2).ToString() + "%");
                    valueRow.Add(Math.Round((actualCD * 100), 2).ToString() + "%");
                    valueRow.Add(Math.Round((absoluteCD * 100), 2).ToString() + "%");
                    valueRow.Add(Math.Round((cloudCD * 100), 2).ToString() + "%");
                    valueItems.Add(valueRow.ToArray());
                    Dictionary <string, string> templates = BAGStatisticHelper.GetAOITemplateList();
                    if (templates != null && templates.Count > 0)
                    {
                        Dictionary <string, int[]> aoiValues = new Dictionary <string, int[]>();
                        foreach (string templateName in templates.Keys)
                        {
                            Dictionary <string, int[]> aois = VectorTemplateToAOIConvertor.GetFeatureAOIIndex(templates[templateName], "NAME",
                                                                                                              bPCDDataProvider.CoordEnvelope, new Size(bPCDDataProvider.Width, bPCDDataProvider.Height));
                            if (aois != null && aois.Count != 0)
                            {
                                foreach (string key in aois.Keys)
                                {
                                    aoiValues.Add(key, aois[key]);
                                }
                            }
                        }
                        if (aoiValues.Count > 0)
                        {
                            foreach (string name in aoiValues.Keys)
                            {
                                //总覆盖度
                                float total = StatTotalConvertDegree(bPCDDataProvider, aoiValues[name]);
                                //计算实际覆盖度
                                float actual = CalcActualConvertDegree(bPCDDataProvider, aoiValues[name]);
                                //计算相对覆盖度
                                float absolute = CalcAbsoluteConvertDegree(bPCDDataProvider, aoiValues[name]);
                                //计算云覆盖度(参数:云判识结果文件)
                                float         cloud = CalcCloudConvertDegree(cloudDataProvider, aoiValues[name]);
                                List <string> row   = new List <string>();
                                row.Add(name);
                                row.Add(Math.Round((total * 100), 2).ToString() + "%");
                                row.Add(Math.Round((actual * 100), 2).ToString() + "%");
                                row.Add(Math.Round((absolute * 100), 2).ToString() + "%");
                                row.Add(Math.Round((cloud * 100), 2).ToString() + "%");
                                valueItems.Add(row.ToArray());
                            }
                        }
                    }
                    if (valueItems != null && valueItems.Count > 0)
                    {
                        //float resolution = bPCDDataProvider.ResolutionX;
                        string      title    = "统计日期:" + DateTime.Now.ToShortDateString();
                        string[]    columns  = new string[] { "区域名称", "总覆盖度", "实际覆盖度", "相对覆盖度", "云覆盖度" };
                        IStatResult result   = new StatResult(title, columns, valueItems.ToArray());
                        string      filename = StatResultToFile(new string[] { bPCDFName }, result, "BAG", "BACD", "蓝藻覆盖度统计", extinfo, 1, false);
                        return(new FileExtractResult("BACD", filename));
                    }
                }
                finally
                {
                    if (bPCDDataProvider != null)
                    {
                        bPCDDataProvider.Dispose();
                    }
                    if (cloudDataProvider != null)
                    {
                        cloudDataProvider.Dispose();
                    }
                }
            }
            return(null);
        }
コード例 #11
0
        public override IExtractResult Make(Action <int, string> progressTracker)
        {
            if (_argumentProvider == null)
            {
                return(null);
            }
            if (_argumentProvider.GetArg("AlgorithmName") == null)
            {
                return(null);
            }
            string[] covertAreaRegions = _argumentProvider.GetArg("CovertAreaRegion") as string[];
            string[] files             = _argumentProvider.GetArg("SelectedPrimaryFiles") as string[];
            string   extinfo           = GetStringArgument("extinfo");

            if (covertAreaRegions == null || covertAreaRegions.Length == 0 || files == null)
            {
                return(null);
            }
            IRasterDataProvider[] statRasters = null;
            if (_argumentProvider.GetArg("AlgorithmName").ToString() == "BCAF")
            {
                int             count   = covertAreaRegions.Count();
                List <string[]> results = new List <string[]>();
                try
                {
                    statRasters = new IRasterDataProvider[files.Length];
                    for (int i = 0; i < statRasters.Length; i++)
                    {
                        statRasters[i] = GeoDataDriver.Open(files[i]) as IRasterDataProvider;
                    }
                    double pixelArea = BAGStatisticHelper.CalPixelArea(statRasters[0].ResolutionX);
                    for (int i = 0; i < count; i++)
                    {
                        float[]         minmax = BAGStatisticHelper.GetCovertAreaValue(covertAreaRegions[i]);
                        List <string[]> result = FREQAlgorithm(minmax[0], minmax[1], statRasters, pixelArea);
                        if (result != null && result.Count >= 1)
                        {
                            results.AddRange(result);
                        }
                    }
                    FileExtractResult fileResult = null;
                    if (results != null && results.Count() > 0)
                    {
                        string         title = "统计日期:" + DateTime.Now.ToShortDateString();
                        RasterIdentify id    = new RasterIdentify(files);
                        if (id.OrbitDateTime != null)
                        {
                            title += "    轨道日期:" + id.OrbitDateTime.ToShortDateString();
                        }
                        string[]    columns  = new string[] { "统计范围", "发生频数(次)" };
                        IStatResult result   = new StatResult(title, columns, results.ToArray());
                        string      filename = StatResultToFile(files, result, "BAG", "BCAF", "蓝藻按覆盖面积统计频次", extinfo, 1, false);
                        fileResult = new FileExtractResult("BCAF", filename);
                    }
                    return(fileResult);
                }
                finally
                {
                    if (statRasters != null)
                    {
                        foreach (IRasterDataProvider prd in statRasters)
                        {
                            prd.Dispose();
                        }
                    }
                }
            }
            return(null);
        }