コード例 #1
0
 public string[] FilesSeriesMeanStatAOI(string[] filesL, int bandNumL, string[] fillvalueL, string outDir, Action <int, string> progressCallback)
 {
     if (StatRegionSet.UseVectorAOIRegion)
     {
         string   prdName = "";
         string[] parts   = Path.GetFileNameWithoutExtension(filesL[0]).Split('_');
         if (parts.Length > 1)
         {
             prdName = parts[0];
         }
         PrjEnvelope RegionEnv = StatRegionSet.AOIPrjEnvelope;
         _aoiContainer  = StatRegionSet.AoiContainer;
         _VectorAOIName = StatRegionSet.AOIName;
         if (RegionEnv == null || RegionEnv.Height <= 0 || RegionEnv.Width <= 0)
         {
             throw new ArgumentException("矢量AOI区域设置无效或范围不合法!");
         }
         if (progressCallback != null)
         {
             progressCallback(-1, "利用AOI区域,开始长时间序列均值统计...");
         }
         Dictionary <DateTime, string> filedate = null;
         List <string[]> resultList             = SeriesStaticAOI(filesL, bandNumL, fillvalueL, out filedate, progressCallback);
         return(OutputExcels(resultList, filedate, _VectorAOIName, outDir, prdName));
     }
     else
     {
         return(null);
     }
 }
コード例 #2
0
        public string[] FilesEOFStatAOI(string[] files, int bandNum, string bandname, string[] fillvalue, string outDir, Action <int, string> progressCallback, double leftRatio = 1)
        {
            string      regionName = "all";
            PrjEnvelope envelope = null;
            PrjEnvelope dstleftPrj = null;
            int         outaoiwidth, outaoiheight;

            int[] outaoiIndex;
            if (StatRegionSet.UseVectorAOIRegion)
            {
                if (leftRatio < 1)
                {
                    leftRatio = 1;
                }
                envelope      = StatRegionSet.AOIPrjEnvelope;
                _aoiContainer = StatRegionSet.AoiContainer;
                regionName    = StatRegionSet.AOIName;
                if (leftRatio >= 1)  //将原始文件降采样,然后再计算aoi,再取点;输出分辨率采用原始文件分辨率;
                {
                    int[] dataPosL;
                    float rawReslxL = 1, rawReslyL = 1;//,outReslx,outResly;
                    if (!CheckRegionIntersect(files[0], envelope, out dstleftPrj, out rawReslxL, out rawReslyL, out dataPosL))
                    {
                        throw new ArgumentException("重采样AOI区域为空!");
                    }
                    CoordEnvelope subFileEnv = new CoordEnvelope(dstleftPrj.MinX, dstleftPrj.MaxX, dstleftPrj.MinY, dstleftPrj.MaxY);
                    StatRegionSet.SubRegionEnv = subFileEnv;
                    Size subAOISize = new Size(dataPosL[2], dataPosL[3]);
                    outaoiwidth  = (int)(subAOISize.Width / leftRatio);
                    outaoiheight = (int)(subAOISize.Height / leftRatio);
                    //outReslx = rawReslxL * (float)leftRatio;
                    //outResly = rawReslyL * (float)leftRatio;
                    Size outAOISize = new Size(outaoiwidth, outaoiheight);
                    outaoiIndex = GetAOI(subFileEnv, _aoiContainer, outAOISize);
                    if (outaoiIndex == null || outaoiIndex.Length <= 0)
                    {
                        throw new ArgumentException("重采样AOI区域为空!");
                    }
                    StatRegionSet.SubRegionOutSize  = outAOISize;
                    StatRegionSet.SubRegionOutIndex = outaoiIndex;
                    double[,] marix = GetTimeSeriesResampledDataFromSubRegionOutIndex(files, bandNum, fillvalue, outaoiIndex, dataPosL, outAOISize);
                    //string[] result = SaveSVDAnaResult(marix, outDir,  subFileEnv,outAOISize, outaoiIndex, 1, false);
                    if (progressCallback != null)
                    {
                        progressCallback(15, "完成数据采样及标准化,开始EOF分解计算...");
                    }
                    CloudParaStat stat = new CloudParaStat();
                    return(stat.AlglibEOF(marix, outDir, bandname, progressCallback, false, null));
                }
                else    //采样率==1,不需要抽样,直接使用AOIindex获取数据进行分析
                {
                    return(null);
                }
            }
            return(null);
        }
コード例 #3
0
        public string[] FilesSVDStatAOI(string[] filesL, int bandNumL, string[] fillvalueL, string[] filesR, int bandNumR, string[] fillvalueR, double leftRatio, double rightRatio, string outDir, Action <int, string> progressCallback, bool LisMicaps = false, bool RisMicaps = false)
        {
            if (!Directory.Exists(outDir))
            {
                Directory.CreateDirectory(outDir);
            }
            if (StatRegionSet.UseVectorAOIRegion)//使用自定义区域
            {
                PrjEnvelope RegionEnv = null;
                string      regionName = "all";
                int         outaoiwidthL, outaoiheightL, outaoiwidthR, outaoiheightR;
                int[]       outaoiIndexL, outaoiIndexR;
                if (StatRegionSet.UseVectorAOIRegion)
                {
                    RegionEnv     = StatRegionSet.AOIPrjEnvelope;
                    _aoiContainer = StatRegionSet.AoiContainer;
                    regionName    = StatRegionSet.AOIName;
                }
                PrjEnvelope dstleftPrj, dstrightPrj, dstPrjEnv;
                float       reslxL, reslyL, reslxR, reslyR;
                int[]       dataPosL, dataPosR;
                if (!CheckRegionIntersect(filesL[0], RegionEnv, out dstleftPrj, out reslxL, out reslyL, out dataPosL))
                {
                    throw new ArgumentException("设置的区域没有可分析的左场数据!");
                }
                if (!CheckRegionIntersect(filesR[0], RegionEnv, out dstrightPrj, out reslxR, out reslyR, out dataPosR))
                {
                    throw new ArgumentException("设置的区域没有可分析的右场数据!");
                }
                dstPrjEnv = PrjEnvelope.Intersect(dstleftPrj, dstrightPrj);
                if (dstPrjEnv == null || dstPrjEnv.Height == 0 || dstPrjEnv.Width == 0)
                {
                    throw new ArgumentException("左右场的AOI区域无交集,无法进行统计分析!");
                }
                if (progressCallback != null)
                {
                    progressCallback(0, "开始读取左场数据...");
                }
                CoordEnvelope subFileEnv = new CoordEnvelope(dstleftPrj.MinX, dstleftPrj.MaxX, dstleftPrj.MinY, dstleftPrj.MaxY);
                StatRegionSet.SubRegionEnvLeft = subFileEnv;
                if (leftRatio < 1)
                {
                    leftRatio = 1;
                }
                Size subAOISize = new Size(dataPosL[2], dataPosL[3]);         //AOI外包矩形在file中的大小
                outaoiwidthL  = (int)(subAOISize.Width / leftRatio);          //AOI外包矩形的输出列数
                outaoiheightL = (int)(subAOISize.Height / leftRatio);         //AOI外包矩形的输出行数
                Size outAOISize = new Size(outaoiwidthL, outaoiheightL);      //输出文件的大小
                outaoiIndexL = GetAOI(subFileEnv, _aoiContainer, outAOISize); //AOI在输出文件中的Index
                if (outaoiIndexL == null || outaoiIndexL.Length <= 0)
                {
                    throw new ArgumentException("左场重采样AOI区域为空!");
                }
                StatRegionSet.SubRegionOutSizeLeft  = outAOISize;
                StatRegionSet.SubRegionOutIndexLeft = outaoiIndexL;
                double[,] marixL = GetTimeSeriesResampledDataFromSubRegionOutIndex(filesL, bandNumL, fillvalueL, outaoiIndexL, dataPosL, outAOISize);
                Size leftSize = new Size(marixL.GetLength(1), marixL.GetLength(0));  //左场数据大小
                if (progressCallback != null)
                {
                    progressCallback(5, "开始读取右场数据...");
                }
                subFileEnv = new CoordEnvelope(dstrightPrj.MinX, dstrightPrj.MaxX, dstrightPrj.MinY, dstrightPrj.MaxY);
                StatRegionSet.SubRegionEnvRight = subFileEnv;
                if (rightRatio < 1)
                {
                    rightRatio = 1;
                }
                subAOISize    = new Size(dataPosR[2], dataPosR[3]);            //AOI外包矩形在file中的大小
                outaoiwidthR  = (int)(subAOISize.Width / rightRatio);          //AOI外包矩形的输出列数
                outaoiheightR = (int)(subAOISize.Height / rightRatio);         //AOI外包矩形的输出行数
                outAOISize    = new Size(outaoiwidthR, outaoiheightR);         //输出文件的大小
                outaoiIndexR  = GetAOI(subFileEnv, _aoiContainer, outAOISize); //AOI在输出文件中的Index
                if (outaoiIndexR == null || outaoiIndexR.Length <= 0)
                {
                    throw new ArgumentException("右场重采样AOI区域为空!");
                }
                StatRegionSet.SubRegionOutSizeRight  = outAOISize;
                StatRegionSet.SubRegionOutIndexRight = outaoiIndexR;
                double[,] marixr = GetTimeSeriesResampledDataFromSubRegionOutIndex(filesL, bandNumL, fillvalueL, outaoiIndexL, dataPosL, outAOISize);
                Size rightSize = new Size(marixr.GetLength(1), marixr.GetLength(0)); //右场数据大小

                if (progressCallback != null)
                {
                    progressCallback(15, "完成数据采样及标准化,开始矩阵计算...");
                }
                CloudParaStat stat = new CloudParaStat();
                return(stat.AlglibSVDWithAOI(marixL, marixr, outDir, filesL[0], leftSize, rightSize, progressCallback));
            }
            return(null);
        }
コード例 #4
0
 public double FilesCorrelateStatAOI(string[] filesL, int bandNumL, string[] fillvalueL, string[] filesR, int bandNumR, string[] fillvalueR, Action <int, string> progressCallback, out long scL, out long scR)
 {
     scR = 0; scL = 0;
     //int widthl = 0, heightl = 0, lengthl = filesL.Length;
     //int widthr = 0, heightr = 0, lengthr = filesR.Length;
     //int xoffsetl = 0, yoffsetl = 0, xoffsetr = 0, yoffsetr = 0;
     if (StatRegionSet.UseVectorAOIRegion)
     {
         PrjEnvelope RegionEnv = StatRegionSet.AOIPrjEnvelope;
         _aoiContainer  = StatRegionSet.AoiContainer;
         _VectorAOIName = StatRegionSet.AOIName;
         if (RegionEnv == null || RegionEnv.Height <= 0 || RegionEnv.Width <= 0)
         {
             throw new ArgumentException("矢量AOI区域设置无效或范围不合法!");
         }
         //int[] dataPosL, dataPosR;
         //PrjEnvelope dstmainPrjL = null,dstmainPrjR = null;
         //if (CheckRegionIntersect(filesL[0], RegionEnv, out dataPosL, out dstmainPrjL))
         //{
         //    xoffsetl = dataPosL[0];
         //    yoffsetl = dataPosL[1];
         //    widthl = dataPosL[2];
         //    heightl = dataPosL[3];
         //}
         //if (CheckRegionIntersect(filesR[0], RegionEnv, out dataPosR, out dstmainPrjR))
         //{
         //    xoffsetr = dataPosR[0];
         //    yoffsetr = dataPosR[1];
         //    widthr = dataPosR[2];
         //    heightr = dataPosR[3];
         //}
     }
     if (progressCallback != null)
     {
         progressCallback(3, "开始读取波段数据...");
     }
     #region 获取左场数据
     enumDataType  datatype = enumDataType.Unknow;
     CoordEnvelope FileEnvL, FileEnvR = null;
     Size          fileSizeL, fileSizeR;
     int[]         aoiL, aoiR;
     using (IRasterDataProvider dataPrd = GeoDataDriver.Open(filesL[0]) as IRasterDataProvider)
     {
         if (dataPrd == null)
         {
             throw new FileLoadException(filesL[0] + "打开失败!");
         }
         datatype  = dataPrd.DataType;
         FileEnvL  = dataPrd.CoordEnvelope;
         fileSizeL = new Size(dataPrd.Width, dataPrd.Height);
     }
     aoiL = GetAOI(FileEnvL, _aoiContainer, fileSizeL);
     if (aoiL == null || aoiL.Length <= 0)
     {
         throw new ArgumentException("矢量AOI区域设置无效或范围不合法,左场AOI区域内点数为0!");
     }
     double[] marixl = GetCorrelateArrayAOI(filesL, bandNumL, fileSizeL, fillvalueL, datatype, aoiL, out scL);
     #endregion
     #region 获取右场数据
     using (IRasterDataProvider dataPrd = GeoDataDriver.Open(filesR[0]) as IRasterDataProvider)
     {
         if (dataPrd == null)
         {
             throw new FileLoadException(filesR[0] + "打开失败!");
         }
         datatype  = dataPrd.DataType;
         FileEnvR  = dataPrd.CoordEnvelope;
         fileSizeR = new Size(dataPrd.Width, dataPrd.Height);
     }
     aoiR = GetAOI(FileEnvR, _aoiContainer, fileSizeR);
     if (aoiR == null || aoiL.Length <= 0)
     {
         throw new ArgumentException("矢量AOI区域设置无效或范围不合法!");
     }
     double[] marixr = GetCorrelateArrayAOI(filesR, bandNumR, fileSizeR, fillvalueR, datatype, aoiR, out scR);
     #endregion
     //计算相关系数
     CloudParaStat stat = new CloudParaStat();
     if (progressCallback != null)
     {
         progressCallback(50, "开始计算相关系数...");
     }
     double cor = stat.CalculateCorrelationCoefficient(marixl, marixr, scL, scR);//取样本数最小
     if (progressCallback != null)
     {
         progressCallback(100, "相关系数计算完成!");
     }
     return(cor);
 }
コード例 #5
0
        public Dictionary <int, RasterQuickStatResult> FilesHistoStatAOI(string[] files, int[] bands, string[] fillValues, string min = null, string max = null, Action <int, string> progressCallback = null)
        {
            foreach (int b in bands)
            {
                if (!CheckFiles(files, b))
                {
                    throw new ArgumentException("输入文件错误!band" + b + "大小或类型不一致!");
                }
            }
            if (StatRegionSet.UseVectorAOIRegion)
            {
                PrjEnvelope RegionEnv = StatRegionSet.AOIPrjEnvelope;
                _aoiContainer  = StatRegionSet.AoiContainer;
                _VectorAOIName = StatRegionSet.AOIName;
                if (RegionEnv == null || RegionEnv.Height <= 0 || RegionEnv.Width <= 0)
                {
                    throw new ArgumentException("矢量AOI区域设置无效或范围不合法!");
                }
            }
            CoordEnvelope outerEnv = null;
            Size          fileSize;
            enumDataType  datatype = enumDataType.Unknow;

            using (IRasterDataProvider dataPrd = GeoDataDriver.Open(files[0]) as IRasterDataProvider)
            {
                datatype = dataPrd.DataType;
                outerEnv = dataPrd.CoordEnvelope;
                fileSize = new Size(dataPrd.Width, dataPrd.Height);
            }
            //创建AOI(基于数据的地理范围)
            int[] aoi = GetAOI(outerEnv, _aoiContainer, fileSize);
            if (aoi == null || aoi.Length <= 0)
            {
                throw new ArgumentException("矢量AOI区域设置无效或范围不合法!");
            }
            if (progressCallback != null)
            {
                progressCallback(3, "开始读取波段数据...");
            }
            int aoilength = aoi.Length;
            int count     = 0;
            IRasterDataProvider arrayPrd = null;

            switch (datatype)
            {
            case enumDataType.Float:
                float[][] rasterbandsF = new float[bands.Max()][];
                if (min != null && max != null)
                {
                    foreach (int b in bands)
                    {
                        rasterbandsF[b - 1] = GetHistArrayBetweenAOI <float>(files, b, fileSize.Width, fileSize.Height, datatype, min, max, aoi, fillValues, out count);
                    }
                    arrayPrd = new ArrayRasterDataProvider <float>("Array", rasterbandsF, count, 1);
                }
                else
                {
                    foreach (int b in bands)
                    {
                        rasterbandsF[b - 1] = GetHistArrayAOI <float>(files, b, fileSize.Width, fileSize.Height, datatype, aoi, fillValues, out count);
                    }
                    arrayPrd = new ArrayRasterDataProvider <float>("Array", rasterbandsF, aoilength, 1);
                }
                break;

            case enumDataType.Int16:
                short[][] rasterbandsS = new short[bands.Max()][];
                if (min != null && max != null)
                {
                    foreach (int b in bands)
                    {
                        rasterbandsS[b - 1] = GetHistArrayBetweenAOI <short>(files, b, fileSize.Width, fileSize.Height, datatype, min, max, aoi, fillValues, out count);
                    }
                    arrayPrd = new ArrayRasterDataProvider <short>("Array", rasterbandsS, count, 1);
                }
                else
                {
                    foreach (int b in bands)
                    {
                        rasterbandsS[b - 1] = GetHistArrayAOI <short>(files, b, fileSize.Width, fileSize.Height, datatype, aoi, fillValues, out count);
                    }
                    arrayPrd = new ArrayRasterDataProvider <short>("Array", rasterbandsS, aoilength, 1);
                }
                break;

            case enumDataType.Byte:
                Byte[][] rasterbandsB = new Byte[bands.Max()][];
                if (min != null && max != null)
                {
                    foreach (int b in bands)
                    {
                        rasterbandsB[b - 1] = GetHistArrayBetweenAOI <Byte>(files, b, fileSize.Width, fileSize.Height, datatype, min, max, aoi, fillValues, out count);
                    }
                    arrayPrd = new ArrayRasterDataProvider <Byte>("Array", rasterbandsB, count, 1);
                }
                else
                {
                    foreach (int b in bands)
                    {
                        rasterbandsB[b - 1] = GetHistArrayAOI <Byte>(files, b, fileSize.Width, fileSize.Height, datatype, aoi, fillValues, out count);
                    }
                    arrayPrd = new ArrayRasterDataProvider <Byte>("Array", rasterbandsB, aoilength, 1);
                }
                break;

            default:
                throw new ArgumentException("暂不支持" + datatype.ToString() + "类型的统计!");
            }
            try
            {
                if (arrayPrd.Width == 0 || arrayPrd.Height == 0)
                {
                    throw new ArgumentException("创建待统计数据失败!");
                }
                if (progressCallback != null)
                {
                    progressCallback(5, "开始统计波段数据...");
                }
                return(DoStat(arrayPrd, bands, null, progressCallback));
            }
            finally
            {
                if (arrayPrd != null)
                {
                    arrayPrd.Dispose();
                }
            }
        }