示例#1
0
        private IRasterDataProvider GetRasterDataProviderMODIS()
        {
            string fname = @"E:\data\dst\TERRA_2010_03_25_03_09_GZ.MOD021KM_PRJ_DXX_Clip.LDF";

            return(GeoDataDriver.Open(fname) as IRasterDataProvider);
        }
示例#2
0
        private void 沙尘能见度_Click(object sender, EventArgs e)
        {
            //首先进行沙尘判识,得出判识出的沙尘区域
            string fname = @"E:\第二张盘\01_沙尘\2011年04月30日\FY3A_VIRRX_GBAL_L1_20110430_0305_1000M_MS_PRJ_DXX.LDF";
            //Dictionary<string, object> args = new Dictionary<string, object>();
            //args.Add("a", 28);
            //args.Add("b", 78);
            //args.Add("c", 245);
            //args.Add("d", 293);
            //args.Add("f", 0);
            //args.Add("g", 20);
            //args.Add("h", 15);
            //args.Add("i", 250);
            IRasterDataProvider prd = GeoDataDriver.Open(fname) as IRasterDataProvider;
            //ArgumentsProvider argprd = new ArgumentsProvider(prd, args);
            //string extractExpress = "((band2/10f) > var_a) && (band2/10f < var_b) && (band5/10f > var_c) && (band5/10f < var_d) && "
            //                      + "(band6/10f > var_a) && ((band6 - band2)>var_f)  && ((band6/10f - band5/10f + var_i)>var_h)";
            //band2:可见光,0.525~0.575(波长范围)
            //band5:远红外,10.3~11.55
            //band6:短波红外,1.60~1.69
            //int[] exBandNos = new int[] { 2, 5, 6 };
            //IThresholdExtracter<UInt16> thrExtracter = new SimpleThresholdExtracter<UInt16>();
            //thrExtracter.Reset(argprd, exBandNos, extractExpress);
            //extractResult = new MemPixelIndexMapper("SAND", 1000);
            //thrExtracter.Extract(extractResult);
            //idxs = extractResult.Indexes.ToArray(); //获取到判识结果

            //将判识结果作为AOI传入进行能见度计算
            string express = "(UInt16)Math.Round(1000 * Math.Pow(Math.E,(var_visibleA + var_visibleB * band1/10f + var_visibleC * band2/10f + var_visibleD * band6/10f + var_visibleE * band4/10f + var_visibleF *(band6/10f - band4/10f + var_shortFar))),0)";
            //express = " 80 ";
            //string express = "1000*Math.Pow(Math.E,(44.7603 +0.181571 * band2/10f -0.332972 * band4/10f + 0.122736 * band6/10f -0.144287 * band5/10f -0.114465 *(band6/10f - band5/10f + 253)))";
            Dictionary <string, object> args = new Dictionary <string, object>();

            args.Add("visibleA", 44.7603);
            args.Add("visibleB", 0.181571);
            args.Add("visibleC", -0.332972);
            args.Add("visibleD", 0.122736);
            args.Add("visibleE", -0.144287);
            args.Add("visibleF", -0.114465);
            args.Add("shortFar", 253);
            int[]            bandNos     = new int[] { 1, 2, 6, 4 };
            ArgumentProvider argProvider = new ArgumentProvider(prd, args);
            //argProvider.AOI = idxs;
            IRasterExtracter <UInt16, UInt16> extracter = new SimpleRasterExtracter <UInt16, UInt16>();

            extracter.Reset(argProvider, bandNos, express);
            result = new MemPixelFeatureMapper <UInt16>("Visibility", 1000, new Size(prd.Width, prd.Height), prd.CoordEnvelope, prd.SpatialRef);
            Stopwatch sw = new Stopwatch();

            sw.Start();
            extracter.Extract(result);
            RasterIdentify id = new RasterIdentify();

            id.ThemeIdentify      = "CMA";
            id.ProductIdentify    = "SAND";
            id.SubProductIdentify = "VISIBILITY";
            id.Satellite          = "FY3A";
            id.Sensor             = "VIRRX";
            id.Resolution         = "1000M";
            id.OrbitDateTime      = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0, 0));
            id.GenerateDateTime   = DateTime.Now;
            IInterestedRaster <UInt16> iir = new InterestedRaster <UInt16>(id, new Size(prd.Width, prd.Height), prd.CoordEnvelope.Clone());

            iir.Put(result);
            iir.Dispose();
            sw.Stop();
            Text = sw.ElapsedMilliseconds.ToString();
        }
示例#3
0
        private IExtractResult CalcEVIAlgorithm1(string inputFile, int[] bandNos, float zoom, double[] bandZoom, float[] cloudyArgs, Int16 defCloudy, bool isFitterCloud, string aoiTemplate, Action <int, string> progressTracker)
        {
            string cloudFileName = FindCloudExtractResult(inputFile);
            float  g, c1, c2, l;

            try
            {
                g  = (float)_argumentProvider.GetArg("G");
                c1 = (float)_argumentProvider.GetArg("C1");
                c2 = (float)_argumentProvider.GetArg("C2");
                l  = (float)_argumentProvider.GetArg("L");
            }
            catch (Exception)
            {
                PrintInfo("计算参数获取失败,请重新设置!");
                return(null);
            }
            bool isAppCloud;

            if (!bool.TryParse(_argumentProvider.GetArg("isAppCloud").ToString(), out isAppCloud))
            {
                PrintInfo("合并交互云参数设置不正确!");
                return(null);
            }
            IRasterDataProvider clmPrd            = null;
            RasterProcessModel <short, short> rfr = null;
            List <RasterMaper> fileIns            = new List <RasterMaper>();

            RasterMaper[] fileOuts = null;
            try
            {
                //输入数据(LDF)
                IRasterDataProvider inRaster = RasterDataDriver.Open(inputFile) as IRasterDataProvider;
                if (inRaster == null)
                {
                    PrintInfo("读取栅格文件失败:" + inRaster);
                    return(null);
                }
                //输出数据(EVI)
                string            outFileName = GetFileName(new string[] { inRaster.fileName }, _subProductDef.ProductDef.Identify, _identify, ".dat", null);
                IRasterDataDriver dd          = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver;
                string            mapInfo     = inRaster.CoordEnvelope.ToMapInfoString(new Size(inRaster.Width, inRaster.Height));
                string[]          opts        = new string[] {
                    "INTERLEAVE=BSQ",
                    "VERSION=MEM",
                    "WITHHDR=TRUE",
                    "SPATIALREF=" + inRaster.SpatialRef.ToProj4String(),
                    mapInfo
                };
                RasterDataProvider outRaster = dd.Create(outFileName, inRaster.Width, inRaster.Height, 1, enumDataType.Int16, opts) as RasterDataProvider;
                string             clmFile   = GetClmFile(inputFile);
                int cloudCH = GetCloudCHNO();
                //栅格数据映射
                fileIns.Add(new RasterMaper(inRaster, bandNos));
                if (isAppCloud)
                {
                    if (!string.IsNullOrEmpty(clmFile) && File.Exists(clmFile))
                    {
                        clmPrd = GeoDataDriver.Open(clmFile) as IRasterDataProvider;
                        if (clmPrd.BandCount < cloudCH)
                        {
                            PrintInfo("请选择正确的云数据通道进行计算.");
                            isAppCloud = false;
                        }
                        else
                        {
                            fileIns.Add(new RasterMaper(clmPrd, new int[] { cloudCH }));
                        }
                    }
                    else
                    {
                        isAppCloud = false;
                    }
                }

                RasterMaper fileOut = new RasterMaper(outRaster, new int[] { 1 });
                fileOuts = new RasterMaper[] { fileOut };
                //创建处理模型
                rfr = new RasterProcessModel <short, short>(progressTracker);
                rfr.SetRaster(fileIns.ToArray(), fileOuts);
                rfr.SetTemplateAOI(aoiTemplate);
                rfr.RegisterCalcModel(new RasterCalcHandler <short, short>((rvInVistor, rvOutVistor, aoi) =>
                {
                    if (rvInVistor[0].RasterBandsData != null)
                    {
                        if (rvInVistor == null)
                        {
                            return;
                        }
                        short[] inBand0 = rvInVistor[0].RasterBandsData[0];                     //第1个输入文件的第1个波段的各像素值
                        short[] inBand1 = rvInVistor[0].RasterBandsData[1];                     //第1个输入文件的第2个波段的各像素值
                        short[] inBand2 = rvInVistor[0].RasterBandsData[2];                     //第1个输入文件的第3个波段的各像素值
                        short[] inBand3 = rvInVistor[0].RasterBandsData[3];                     //第1个输入文件的第4个波段的各像素值
                        short[] inBand4 = rvInVistor[0].RasterBandsData[4];                     //第1个输入文件的第5个波段的各像素值
                        short[] inBand5 = isAppCloud ? rvInVistor[1].RasterBandsData[0] : null; //第2个输入文件的第1个波段的各像素值
                        short[] ndvi    = new short[inBand0.Length];
                        if (string.IsNullOrWhiteSpace(aoiTemplate))
                        {
                            for (int index = 0; index < inBand0.Length; index++)
                            {
                                if ((isAppCloud && inBand5[index] == 1) || (isFitterCloud && inBand1[index] / bandZoom[1] > cloudyArgs[0] && inBand4[index] / bandZoom[4] < cloudyArgs[1] && Math.Abs(inBand3[index] / bandZoom[3] - inBand4[index] / bandZoom[4]) > cloudyArgs[2]))
                                {
                                    rvOutVistor[0].RasterBandsData[0][index] = defCloudy;
                                    continue;
                                }
                                //第1个输出文件的第1个波段存储EVI值
                                rvOutVistor[0].RasterBandsData[0][index] = (short)(g * (float)(inBand1[index] / bandZoom[1] - inBand0[index] / bandZoom[0]) / (inBand1[index] / bandZoom[1] + c1
                                                                                                                                                               * inBand0[index] / bandZoom[0] - c2 * inBand2[index] / bandZoom[2] + l) * zoom);
                            }
                        }
                        else if (aoi != null && aoi.Length != 0)
                        {
                            int index;
                            for (int i = 0; i < aoi.Length; i++)
                            {
                                index = aoi[i];
                                if ((isAppCloud && inBand5[index] == 1) || (isFitterCloud && inBand1[index] / bandZoom[1] > cloudyArgs[0] && inBand4[index] / bandZoom[4] < cloudyArgs[1] && Math.Abs(inBand3[index] / bandZoom[3] - inBand4[index] / bandZoom[4]) > cloudyArgs[2]))
                                {
                                    rvOutVistor[0].RasterBandsData[0][index] = defCloudy;
                                    continue;
                                }
                                //第1个输出文件的第1个波段存储EVI值
                                rvOutVistor[0].RasterBandsData[0][index] = (short)(g * (float)(inBand1[index] / bandZoom[1] - inBand0[index] / bandZoom[0]) / (inBand1[index] / bandZoom[1] + c1
                                                                                                                                                               * inBand0[index] / bandZoom[0] - c2 * inBand2[index] / bandZoom[2] + l) * zoom);
                            }
                        }
                    }
                }));
                //执行
                rfr.Excute();
                FileExtractResult res = new FileExtractResult(_subProductDef.Identify, outFileName, true);
                res.SetDispaly(false);
                return(res);
            }
            finally
            {
                if (fileIns != null)
                {
                    for (int i = 0; i < fileIns.Count; i++)
                    {
                        fileIns[i].Raster.Dispose();
                    }
                }
                if (fileOuts != null)
                {
                    for (int i = 0; i < fileOuts.Length; i++)
                    {
                        fileOuts[i].Raster.Dispose();
                    }
                }
                if (clmPrd != null)
                {
                    clmPrd.Dispose();
                }
            }
        }
示例#4
0
        /// <summary>
        /// 融合微波雪深文件 和 可见光雪云辨识文件更新雪深
        /// </summary>
        /// <param name="sdfilname"></param>
        /// <param name="visfilename"></param>
        /// <returns></returns>
        private IFileExtractResult ComputeSD(string sdfilename, string visfilename)
        {
            List <RasterMaper>  rms            = null;
            IRasterDataProvider outRaster      = null;
            IRasterDataProvider outClassRaster = null;//融合分类

            rms = new List <RasterMaper>();
            IRasterDataProvider inRaster1 = GeoDataDriver.Open(sdfilename) as IRasterDataProvider; //微波雪深数据
            RasterMaper         fileIn1   = new RasterMaper(inRaster1, new int[] { 1 });

            rms.Add(fileIn1);
            IRasterDataProvider inRaster2 = GeoDataDriver.Open(visfilename) as IRasterDataProvider;//可见云和雪判识结果
            RasterMaper         fileIn2   = new RasterMaper(inRaster2, new int[] { 1 });

            rms.Add(fileIn2);
            //林地覆盖率
            string forestFile             = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemData\\ProductArgs\\MWS\\SnowArgFile\\china_forest._frac.dat");
            IRasterDataProvider inRaster3 = GeoDataDriver.Open(forestFile) as IRasterDataProvider;
            RasterMaper         fileIn3   = new RasterMaper(inRaster3, new int[] { 1 });

            rms.Add(fileIn3);
            if (inRaster1.ResolutionX != inRaster3.ResolutionX)
            {
                PrintInfo("雪深数据分辨率与辅助数据分辨率0.1度不同!");
                return(null);
            }
            string visFileName = GetFileName(new string[] { sdfilename }, _subProductDef.ProductDef.Identify, "MWVI", ".dat", null);

            outRaster = CreateOutRaster(visFileName, enumDataType.Float, rms.ToArray(), inRaster2.ResolutionX);
            //融合分类数据
            string classFileName = GetFileName(new string[] { sdfilename }, _subProductDef.ProductDef.Identify, "MCVI", ".dat", null);

            outClassRaster = CreateOutRaster(classFileName, enumDataType.Float, rms.ToArray(), inRaster2.ResolutionX);
            double minX   = outRaster.CoordEnvelope.MinX;
            double minY   = outRaster.CoordEnvelope.MinY;
            double maxX   = outRaster.CoordEnvelope.MaxX;
            double maxY   = outRaster.CoordEnvelope.MaxY;
            int    xLeft  = (int)((minX - inRaster1.CoordEnvelope.MinX) / inRaster1.ResolutionX);
            int    yUp    = (int)((inRaster1.CoordEnvelope.MaxY - maxY) / inRaster1.ResolutionY);
            int    xRight = (int)((maxX - inRaster1.CoordEnvelope.MinX) / inRaster1.ResolutionX);
            int    yDown  = (int)((inRaster1.CoordEnvelope.MaxY - minY) / inRaster1.ResolutionX);
            int    xSize  = xRight - xLeft;
            int    ySize  = yDown - yUp;

            float[]     buffer        = new float[xSize * ySize];
            IRasterBand bandinRaster1 = inRaster1.GetRasterBand(1);

            float[] sd = new float[xSize * ySize];
            //float[] snowClass = new float[xSize * ySize];
            unsafe
            {
                fixed(float *pointer = buffer)
                {
                    IntPtr ptr = new IntPtr(pointer);

                    bandinRaster1.Read(xLeft, yUp, xSize, ySize, ptr, inRaster1.DataType, xSize, ySize);
                    for (int j = 0; j < xSize * ySize; j++)
                    {
                        sd[j] = buffer[j];
                    }
                }
            }
            int visLeftX  = (int)((minX - inRaster2.CoordEnvelope.MinX) / inRaster2.ResolutionX);
            int visLeftY  = (int)((inRaster2.CoordEnvelope.MaxY - maxY) / inRaster2.ResolutionY);
            int visRightX = (int)((maxX - inRaster2.CoordEnvelope.MinX) / inRaster2.ResolutionX);
            int visRightY = (int)((inRaster2.CoordEnvelope.MaxY - minY) / inRaster2.ResolutionX);
            int visxSize  = visRightX - visLeftX;
            int visySize  = visRightY - visLeftY;

            Int16[]     visbuffer     = new Int16[visxSize * visySize];
            IRasterBand bandinRaster2 = inRaster2.GetRasterBand(1);

            Int16[] visSNW = new Int16[visxSize * visySize];
            // float[] sdSnow = new float[outRaster.Width * outRaster.Height];
            float[ ,] sdSnow = new float[2, outRaster.Width *outRaster.Height];//一维放融合雪深,二维放融合分类
            unsafe
            {
                fixed(Int16 *pointer = visbuffer)
                {
                    IntPtr ptr = new IntPtr(pointer);

                    bandinRaster2.Read(visLeftX, visLeftY, visxSize, visySize, ptr, inRaster2.DataType, visxSize, visySize);
                    for (int j = 0; j < visxSize * visySize; j++)
                    {
                        visSNW[j] = visbuffer[j];
                    }
                }
            }
            //读取森林覆盖率;
            int xforestLeft  = (int)((minX - inRaster3.CoordEnvelope.MinX) / inRaster3.ResolutionX);
            int yforestUp    = (int)((inRaster3.CoordEnvelope.MaxY - maxY) / inRaster3.ResolutionY);
            int xforestRight = (int)((maxX - inRaster3.CoordEnvelope.MinX) / inRaster3.ResolutionX);
            int yforestDown  = (int)((inRaster3.CoordEnvelope.MaxY - minY) / inRaster3.ResolutionX);
            int xforestSize  = xforestRight - xforestLeft;
            int yforestSize  = yforestDown - yforestUp;

            Int16[]     forestbuffer  = new Int16[xforestSize * yforestSize];
            IRasterBand bandinRaster3 = inRaster3.GetRasterBand(1);

            Int16[] forestFrac = new Int16[xforestSize * yforestSize];
            unsafe
            {
                fixed(Int16 *pointer = forestbuffer)
                {
                    IntPtr ptr = new IntPtr(pointer);

                    bandinRaster3.Read(xforestLeft, yforestUp, xforestSize, yforestSize, ptr, inRaster3.DataType, xforestSize, yforestSize);
                    for (int j = 0; j < xforestSize * yforestSize; j++)
                    {
                        forestFrac[j] = forestbuffer[j];
                    }
                }
            }
            int zoom = (int)(inRaster1.ResolutionX / inRaster2.ResolutionX);

            try
            {
                for (int j = 0; j < xSize * ySize; j++)                     //低分的格子
                {
                    if (((j + 1) % xSize == 0) && (j != xSize * ySize - 1)) //最后一列并且不是低分最后一个格子
                    {
                        int     zoomcha = xSize * zoom - visxSize;
                        Int32[] index   = new Int32[zoom * (zoom - zoomcha)];
                        for (int row = 0; row < zoom; row++)               //行还是原来的zoom行
                        {
                            for (int col = 0; col < zoom - zoomcha; col++) //列比原来少 zoomcha 列
                            {
                                index[col + row * (zoom - zoomcha)] = (j / xSize * zoom * visxSize + j % xSize * zoom) + (row * visxSize) + col;
                            }
                        }
                        sdSnow = SDsnow(zoom - zoomcha, zoom, index, visSNW, sd[j], sdSnow, forestFrac[j]);
                    }
                    else
                    {
                        if ((j >= xSize * ySize - xSize) && (j != xSize * ySize - 1))    //最后一行并且不是低分最后一个格子
                        {
                            int     zoomcha = ySize * zoom - visySize;
                            Int32[] index   = new Int32[(zoom - zoomcha) * zoom];
                            for (int row = 0; row < zoom - zoomcha; row++) //行比原来少 zoomcha行
                            {
                                for (int col = 0; col < zoom; col++)       //列还是原来列
                                {
                                    index[col + row * zoom] = (j / xSize * zoom * visxSize + j % xSize * zoom) + (row * visxSize) + col;
                                }
                            }
                            sdSnow = SDsnow(zoom, zoom - zoomcha, index, visSNW, sd[j], sdSnow, forestFrac[j]);
                        }
                        else
                        {
                            if (j == xSize * ySize - 1)  //低分的最后一个格子
                            {
                                int     zoomcha = ySize * zoom - visySize;
                                Int32[] index   = new Int32[(zoom - zoomcha) * (zoom - zoomcha)];
                                for (int row = 0; row < zoom - zoomcha; row++)     //行比原来少 zoomcha行
                                {
                                    for (int col = 0; col < zoom - zoomcha; col++) //列列比原来少 zoomcha 列
                                    {
                                        index[col + row * (zoom - zoomcha)] = (j / xSize * zoom * visxSize + j % xSize * zoom) + (row * visxSize) + col;
                                    }
                                }
                                sdSnow = SDsnow(zoom - zoomcha, zoom - zoomcha, index, visSNW, sd[j], sdSnow, forestFrac[j]);
                            }
                            else
                            {
                                Int32[] index = new Int32[zoom * zoom];
                                for (int row = 0; row < zoom; row++)
                                {
                                    for (int col = 0; col < zoom; col++)
                                    {
                                        index[col + row * zoom] = (j / xSize * zoom * visxSize + j % xSize * zoom) + (row * visxSize) + col;
                                    }
                                }
                                sdSnow = SDsnow(zoom, zoom, index, visSNW, sd[j], sdSnow, forestFrac[j]);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                PrintInfo(ex.Message);
            }
            float[]             sdSnow1 = new float[outRaster.Width * outRaster.Height];
            float[]             sdclass = new float[outRaster.Width * outRaster.Height];
            IExtractResultArray array   = new ExtractResultArray("融合雪深分类");

            for (int index = 0; index < outRaster.Width * outRaster.Height; index++)
            {
                sdSnow1[index] = sdSnow[0, index];
                sdclass[index] = sdSnow[1, index];
            }
            try
            {
                unsafe
                {
                    fixed(float *ptr = sdSnow1)
                    {
                        IntPtr      sdSnowPtr     = new IntPtr(ptr);
                        IRasterBand bandoutRaster = outRaster.GetRasterBand(1);

                        bandoutRaster.Write(0, 0, outRaster.Width, outRaster.Height, sdSnowPtr, outRaster.DataType, outRaster.Width, outRaster.Height);
                    }
                    fixed(float *ptr = sdclass)
                    {
                        IntPtr      sdclassPtr    = new IntPtr(ptr);
                        IRasterBand bandoutRaster = outClassRaster.GetRasterBand(1);

                        bandoutRaster.Write(0, 0, outClassRaster.Width, outClassRaster.Height, sdclassPtr, outClassRaster.DataType, outClassRaster.Width, outClassRaster.Height);
                    }
                }
                IFileExtractResult res = new FileExtractResult(_subProductDef.Identify, visFileName, true);
                array.Add(res);
                IFileExtractResult res2 = new FileExtractResult(_subProductDef.Identify, classFileName, true);
                array.Add(res2);
                return(res);
            }
            finally
            {
                if (outRaster != null)
                {
                    outRaster.Dispose();
                }
                if (outClassRaster != null)
                {
                    outClassRaster.Dispose();
                }
                if (rms != null && rms.Count > 0)
                {
                    foreach (RasterMaper rm in rms)
                    {
                        if (rm.Raster != null)
                        {
                            rm.Raster.Dispose();
                        }
                    }
                }
            }
        }
示例#5
0
        /// <summary>
        /// 可见光雪和云合成一个文件
        /// </summary>
        /// <param name="visSNWfilename"></param>
        /// <param name="cldfilename"></param>
        /// <returns></returns>
        private IFileExtractResult ComputeVIS(string visSNWfilename, string cldfilename)
        {
            List <RasterMaper>  rms               = null;
            IRasterDataProvider outRaster         = null;
            RasterProcessModel <Int16, Int16> rfr = null;

            try
            {
                rms = new List <RasterMaper>();
                IRasterDataProvider inRaster1 = GeoDataDriver.Open(visSNWfilename) as IRasterDataProvider;
                RasterMaper         fileIn1   = new RasterMaper(inRaster1, new int[] { 1 });
                rms.Add(fileIn1);
                IRasterDataProvider inRaster2 = GeoDataDriver.Open(cldfilename) as IRasterDataProvider;
                RasterMaper         fileIn2   = new RasterMaper(inRaster2, new int[] { 1 });
                rms.Add(fileIn2);
                //中国区掩膜文件
                string chinarasterFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemData\\ProductArgs\\MWS\\SnowArgFile\\china_raster.dat");
                if (string.IsNullOrEmpty(chinarasterFile) || !File.Exists(chinarasterFile))
                {
                    PrintInfo("缺少系统中国区栅格文件");
                    return(null);
                }
                IRasterDataProvider inRaster3 = GeoDataDriver.Open(chinarasterFile) as IRasterDataProvider;
                RasterMaper         fileIn3   = new RasterMaper(inRaster3, new int[] { 1 });
                rms.Add(fileIn3);

                string visFileName = GetFileName(new string[] { visSNWfilename }, _subProductDef.ProductDef.Identify, "SVIS", ".dat", null);
                outRaster = CreateOutRaster(visFileName, enumDataType.Int16, rms.ToArray(), inRaster1.ResolutionX);
                RasterMaper   fileOut  = new RasterMaper(outRaster, new int[] { 1 });
                RasterMaper[] fileIns  = rms.ToArray();
                RasterMaper[] fileOuts = new RasterMaper[] { fileOut };
                rfr = new RasterProcessModel <Int16, Int16>();
                rfr.SetRaster(fileIns, fileOuts);
                rfr.RegisterCalcModel(new RasterCalcHandler <Int16, Int16>((rvInVistor, rvOutVistor, aoi) =>
                {
                    if (rvInVistor[0].RasterBandsData[0] != null && rvInVistor[1].RasterBandsData[0] != null && rvInVistor[2].RasterBandsData[0] != null)
                    {
                        int dataLength = rvInVistor[2].RasterBandsData[0].Length;
                        int[] type     = new int[dataLength];
                        float[] sdtmp  = new float[dataLength];
                        for (int i = 0; i < dataLength; i++)
                        {
                            if (rvInVistor[0].RasterBandsData[0][i] == 1 && (rvInVistor[1].RasterBandsData[0][i] == 0 || rvInVistor[1].RasterBandsData[0][i] == 1))
                            {
                                if (rvInVistor[2].RasterBandsData[0][i] == 1) //如果两个文件都判识出既是云,又是雪就按雪来处理。
                                {
                                    rvOutVistor[0].RasterBandsData[0][i] = 1; // 1 表示雪
                                }
                                else
                                {
                                    rvOutVistor[0].RasterBandsData[0][i] = 0;
                                }
                            }
                            else
                            {
                                if (rvInVistor[0].RasterBandsData[0][i] == 0 && rvInVistor[1].RasterBandsData[0][i] == 1)
                                {
                                    if (rvInVistor[2].RasterBandsData[0][i] == 1)
                                    {
                                        rvOutVistor[0].RasterBandsData[0][i] = 2;  // 2 表示云
                                    }
                                    else
                                    {
                                        rvOutVistor[0].RasterBandsData[0][i] = 0;
                                    }
                                }
                                else
                                {
                                    rvOutVistor[0].RasterBandsData[0][i] = 0;    // 0 表示裸地
                                }
                            }
                        }
                    }
                }));
                rfr.Excute();
                IFileExtractResult res = new FileExtractResult(_subProductDef.Identify, visFileName, true);
                res.SetDispaly(false);
                return(res);
            }
            finally
            {
                if (outRaster != null)
                {
                    outRaster.Dispose();
                }
                if (rms != null && rms.Count > 0)
                {
                    foreach (RasterMaper rm in rms)
                    {
                        if (rm.Raster != null)
                        {
                            rm.Raster.Dispose();
                        }
                    }
                }
            }
        }
示例#6
0
        public override IExtractResult Make(Action <int, string> progressTracker)
        {
            if (!CheckArguments())
            {
                return(null);
            }
            Dictionary <DateTime, List <string> > orderedFiles = GroupByOrbitDate();

            if (orderedFiles.Count == 0)
            {
                return(null);
            }
            object obj = _argumentProvider.GetArg("ThemeGraphyGenerator");

            if (obj == null)
            {
                return(null);
            }
            IThemeGraphGenerator tgg     = obj as IThemeGraphGenerator;
            List <string>        rdpList = new List <string>();//按照日期生成的多个日最大合成数据

            //每天生成一个最大日合成图

            foreach (DateTime time in orderedFiles.Keys)
            {
                RasterMoasicProcesser      processer = new RasterMoasicProcesser();
                List <IRasterDataProvider> srcdata   = new List <IRasterDataProvider>();
                try
                {
                    foreach (string item in orderedFiles[time])
                    {
                        IRasterDataProvider rdp = GeoDataDriver.Open(item) as IRasterDataProvider;
                        if (rdp != null)
                        {
                            srcdata.Add(rdp);
                        }
                    }
                    string             fileName  = null;
                    IFileNameGenerator generator = GetFileNameGenerator();
                    if (generator == null)
                    {
                        fileName = string.Empty;
                    }
                    else
                    {
                        fileName = generator.NewFileName(CreatRasterIndetifyId(orderedFiles[time].ToArray(), "SNW", "MAXI", GetDataIdentify(), ".LDF", null));
                    }
                    using (IRasterDataProvider dstPrd = processer.Moasic <Int16>(srcdata.ToArray(), "LDF", fileName, false, null, "MAX", null, (srcValue, dstValue) => { return(srcValue > dstValue ? srcValue : dstValue); }))
                    {
                        if (dstPrd != null)
                        {
                            rdpList.Add(dstPrd.fileName);
                        }
                    }
                }
                finally
                {
                    foreach (IRasterDataProvider rdp in srcdata)
                    {
                        rdp.Dispose();
                    }
                    srcdata.Clear();
                }
            }
            string templatName              = GetStringArgument("ThemeGraphTemplateName");
            string colorTabelName           = GetColorTableName("colortablename");
            IExtractResultArray resultArray = new ExtractResultArray("MAXI");

            foreach (string file in rdpList)
            {
                tgg.Generate(file, templatName, null, null, "MAXI", colorTabelName);
                string resultFilename = tgg.Save();
                if (string.IsNullOrEmpty(resultFilename))
                {
                    continue;
                }
                resultArray.Add(new FileExtractResult("MAXI", resultFilename));
            }
            if (resultArray != null)
            {
                return(resultArray);
            }
            return(null);
        }
示例#7
0
        private void TestProj()
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            Size srSize = Size.Empty;

            Double[] lats  = null;
            Double[] longs = null;
            using (IRasterDataProvider srcPrd = GeoDataDriver.Open(@"D:\mas数据\FY3A_VIRRX_GBAL_L1_20110322_0525_1000M_MS.HDF") as IRasterDataProvider)
            {
                IBandProvider srcbandpro = srcPrd.BandProvider as IBandProvider;
                {
                    srSize = new System.Drawing.Size(srcPrd.Width, srcPrd.Height);
                    lats   = new Double[srcPrd.Width * srcPrd.Height];
                    longs  = new Double[srcPrd.Width * srcPrd.Height];
                    using (IRasterBand latBand = srcbandpro.GetBands("Latitude")[0])
                    {
                        using (IRasterBand lonsBand = srcbandpro.GetBands("Longitude")[0])
                        {
                            unsafe
                            {
                                fixed(Double *ptrLat = lats)
                                {
                                    fixed(Double *ptrLong = longs)
                                    {
                                        IntPtr bufferPtrLat  = new IntPtr(ptrLat);
                                        IntPtr bufferPtrLong = new IntPtr(ptrLong);

                                        latBand.Read(0, 0, srcPrd.Width, srcPrd.Height, bufferPtrLat, enumDataType.Double, srcPrd.Width, srcPrd.Height);
                                        lonsBand.Read(0, 0, srcPrd.Width, srcPrd.Height, bufferPtrLong, enumDataType.Double, srcPrd.Width, srcPrd.Height);
                                    }
                                }
                            }
                        }
                    }
                    stopwatch.Stop();
                    WriteLine("读取经纬度{0}ms", stopwatch.ElapsedMilliseconds);
                    stopwatch.Restart();
                    IRasterProjector     raster = new RasterProjector();
                    PrjEnvelope          destEnvelope;
                    Action <int, string> progressCallback = new Action <int, string>(OutProgress);
                    //progressCallback = null;  //测试不用进度条的情况
                    ISpatialReference srcSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("WGS 1984.prj");
                    ISpatialReference dstSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("ChinaBoundary.prj");
                    raster.ComputeDstEnvelope(srcSpatialRef, longs, lats, srSize, dstSpatialRef, out destEnvelope, progressCallback);
                    stopwatch.Stop();
                    WriteLine("计算范围{0}ms", stopwatch.ElapsedMilliseconds);
                    WriteLine("范围{0}", destEnvelope.ToString());

                    Size     dstSize           = new Size((int)(destEnvelope.Width / 0.01), (int)(destEnvelope.Height / 0.01));
                    UInt16[] dstRowLookUpTable = new UInt16[dstSize.Width * dstSize.Height];
                    UInt16[] dstColLookUpTable = new UInt16[dstSize.Width * dstSize.Height];
                    raster.ComputeIndexMapTable(srcSpatialRef, longs, lats, srSize, dstSpatialRef, dstSize, destEnvelope,
                                                out dstRowLookUpTable, out dstColLookUpTable, progressCallback);

                    stopwatch.Stop();
                    WriteLine("计算投影查找表{0}ms", stopwatch.ElapsedMilliseconds);
                    stopwatch.Restart();

                    int srcBandCount = srcPrd.BandCount;
                    using (IRasterDataDriver drv = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver)
                    {
                        string proj4 = dstSpatialRef.ToProj4String();
                        using (IRasterDataProvider prdWriter = drv.Create(@"d:\Myproj4LutX.ldf", dstSize.Width, dstSize.Height, srcBandCount,
                                                                          enumDataType.UInt16, "INTERLEAVE=BSQ", "VERSION=LDF", "SPATIALREF=" + proj4) as IRasterDataProvider)
                        {
                            UInt16[] dstData = new UInt16[dstSize.Width * dstSize.Height];
                            UInt16[] srcData = new UInt16[srSize.Width * srSize.Height];
                            //int perProgress = 0;
                            //int curProgress = 0;
                            for (int i = 0; i < srcBandCount; i++)
                            {
                                using (IRasterBand latBand = srcPrd.GetRasterBand(i + 1))
                                {
                                    unsafe
                                    {
                                        fixed(UInt16 *ptr = srcData)
                                        {
                                            IntPtr bufferptr = new IntPtr(ptr);

                                            latBand.Read(0, 0, srSize.Width, srSize.Height, bufferptr, enumDataType.UInt16, srSize.Width, srSize.Height);
                                        }
                                    }
                                }
                                //stopwatch.Stop();
                                //WriteLine("读取一个通道{0}ms,通道索引{1}", stopwatch.ElapsedMilliseconds, i + 1);
                                //stopwatch.Restart();
                                raster.Project <UInt16>(srcData, srSize, dstRowLookUpTable, dstColLookUpTable, dstSize, dstData, 0, progressCallback);
                                //stopwatch.Stop();
                                //WriteLine("投影一个通道{0}ms,通道索引{1}", stopwatch.ElapsedMilliseconds, i + 1);
                                //stopwatch.Restart();

                                using (IRasterBand band = prdWriter.GetRasterBand(i + 1))
                                {
                                    unsafe
                                    {
                                        fixed(UInt16 *ptr = dstData)
                                        {
                                            IntPtr bufferPtr = new IntPtr(ptr);

                                            band.Write(0, 0, band.Width, band.Height, bufferPtr, enumDataType.UInt16, band.Width, band.Height);
                                        }
                                    }
                                }
                                //curProgress = (i+1) * 100 / srcBandCount;
                                //if (progressCallback != null && curProgress > perProgress)
                                //{
                                //    progressCallback(curProgress, "");
                                //    perProgress = curProgress;
                                //}
                                //stopwatch.Stop();
                                //WriteLine("写出一个通道{0}ms", stopwatch.ElapsedMilliseconds);
                                //stopwatch.Restart();
                            }
                        }
                    }
                    stopwatch.Stop();
                    WriteLine("投影完所有通道{0}ms", stopwatch.ElapsedMilliseconds);
                    stopwatch.Restart();
                }
            }
        }
示例#8
0
        protected T[] GetHistArrayAOI <T>(string[] filesL, int bandNumL, int width, int height, enumDataType datatype, int[] aoi, string[] fillValuesStr, out int count)
        {
            count = 0;
            int totalwidth = aoi.Length;

            switch (datatype)
            {
            case enumDataType.Float:
            {
                float[] marixl     = new float[totalwidth * filesL.Length];
                float[] fillValues = GetFillValues <float>(fillValuesStr, enumDataType.Float);
                float[] oriData;
                for (int i = 0; i < filesL.Length; i++)
                {
                    using (IRasterDataProvider dataPrd = GeoDataDriver.Open(filesL[i]) as IRasterDataProvider)
                    {
                        oriData = GetDataValue <float>(dataPrd, bandNumL, width, height, 0, 0);
                        for (int j = 0; j < totalwidth; j++)
                        {
                            float data = oriData[aoi[j]];
                            if (fillValues != null && fillValues.LongLength > 0 && fillValues.Contains(data))
                            {
                                continue;
                            }
                            marixl[count++] = data;
                        }
                    }
                }
                return(marixl as T[]);
            }

            case enumDataType.Int16:
            {
                short[] marixl     = new short[totalwidth * filesL.Length];
                short[] fillValues = GetFillValues <short>(fillValuesStr, enumDataType.Int16);
                short[] oriData;
                for (int i = 0; i < filesL.Length; i++)
                {
                    using (IRasterDataProvider dataPrd = GeoDataDriver.Open(filesL[i]) as IRasterDataProvider)
                    {
                        oriData = GetDataValue <short>(dataPrd, bandNumL, width, height, 0, 0);
                        for (int j = 0; j < totalwidth; j++)
                        {
                            short data = oriData[aoi[j]];
                            if (fillValues != null && fillValues.LongLength > 0 && fillValues.Contains(data))
                            {
                                continue;
                            }
                            marixl[count++] = data;
                        }
                    }
                }
                return(marixl as T[]);
            }

            case enumDataType.Byte:
            {
                Byte[] marixl     = new Byte[totalwidth * filesL.Length];
                Byte[] fillValues = GetFillValues <Byte>(fillValuesStr, enumDataType.Byte);
                Byte[] oriData;
                for (int i = 0; i < filesL.Length; i++)
                {
                    using (IRasterDataProvider dataPrd = GeoDataDriver.Open(filesL[i]) as IRasterDataProvider)
                    {
                        oriData = GetDataValue <Byte>(dataPrd, bandNumL, width, height, 0, 0);
                        for (int j = 0; j < totalwidth; j++)
                        {
                            Byte data = oriData[aoi[j]];
                            if (fillValues != null && fillValues.LongLength > 0 && fillValues.Contains(data))
                            {
                                continue;
                            }
                            marixl[count++] = data;
                        }
                    }
                }
                return(marixl as T[]);
            }

            default:
                return(null);
            }
        }
示例#9
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);
 }
示例#10
0
        public bool ProcessCSD(string outDir, string[] filenames, int[] modelCalcBands, int[] orderCalcBands, Dictionary <int, int> outBands, string calcModel)
        {
            List <RasterMaper> rms         = new List <RasterMaper>();
            List <int>         outbandsSrc = new List <int>();

            outbandsSrc.AddRange(orderCalcBands);
            foreach (int key in outBands.Keys)
            {
                outbandsSrc.Add(outBands[key]);
            }
            try
            {
                enumDataType        datatype = enumDataType.Atypism;
                IRasterDataProvider rdp      = null;
                RasterMaper         rdpRm    = null;
                for (int i = 0; i < filenames.Length; i++)
                {
                    rdp = GeoDataDriver.Open(filenames[i]) as IRasterDataProvider;
                    if (rdp != null)
                    {
                        datatype = rdp.DataType;
                        rdpRm    = new RasterMaper(rdp, outbandsSrc.ToArray());
                        rms.Add(rdpRm);
                    }
                }
                string outFileName = outDir + "\\" + GetFileName(filenames, ".ldf");

                IExtractFuncProvider <T> prd = ExtractFuncProviderFactory.CreateExtractFuncProvider <T>(modelCalcBands, calcModel, null);
                _boolFunc = prd.GetBoolFunc();
                int inVisitorCount    = rms.Count;
                int inVisitorBand     = orderCalcBands.Length;
                int resultInFileIndex = 0;
                using (IRasterDataProvider outRaster = CreateOutRaster(outFileName, rms.ToArray(), datatype, outBands.Count))
                {
                    RasterMaper[] fileIns  = rms.ToArray();
                    RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, outBands.Keys.ToArray()) };
                    //创建处理模型
                    RasterProcessModel <T, T> rfr = null;
                    rfr = new RasterProcessModel <T, T>(ConsoleWrite);
                    rfr.SetRaster(fileIns, fileOuts);
                    List <T> curValues   = new List <T>();
                    List <T> nextValues  = new List <T>();
                    List <T> indexValues = new List <T>();
                    rfr.RegisterCalcModel(new RasterCalcHandler <T, T>((rvInVistor, rvOutVistor, aoi) =>
                    {
                        int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX;

                        if (rvInVistor[0].RasterBandsData == null)
                        {
                            return;
                        }
                        for (int index = 0; index < dataLength; index++)
                        {
                            curValues.Clear();
                            for (int inBnad = 0; inBnad < inVisitorBand; inBnad++)
                            {
                                if (rvInVistor[0].RasterBandsData[inBnad] == null)
                                {
                                    return;
                                }
                                curValues.Add(rvInVistor[0].RasterBandsData[inBnad][index]);
                            }
                            resultInFileIndex = 0;

                            for (int inFile = 1; inFile < inVisitorCount; inFile++)
                            {
                                try
                                {
                                    if (rvInVistor[inFile].RasterBandsData == null)
                                    {
                                        return;
                                    }
                                    for (int inBnad = 0; inBnad < inVisitorBand; inBnad++)
                                    {
                                        if (rvInVistor[inFile].RasterBandsData[inBnad] == null)
                                        {
                                            return;
                                        }
                                        nextValues.Add(rvInVistor[inFile].RasterBandsData[inBnad][index]);
                                    }
                                    indexValues.AddRange(curValues);
                                    indexValues.AddRange(nextValues);
                                    if (_boolFunc != null)
                                    {
                                        if (!_boolFunc(index, indexValues.ToArray()))
                                        {
                                            resultInFileIndex = inFile;
                                            curValues.Clear();
                                            curValues.AddRange(nextValues);
                                        }
                                    }
                                }
                                finally
                                {
                                    indexValues.Clear();
                                    nextValues.Clear();
                                }
                            }
                            for (int outBand = 0; outBand < outBands.Count; outBand++)
                            {
                                rvOutVistor[0].RasterBandsData[outBand][index] = rvInVistor[resultInFileIndex].RasterBandsData[inVisitorBand + outBand][index];
                            }
                        }
                    }));
                    //执行
                    rfr.Excute();
                    Console.WriteLine("已完成!");
                }
            }
            finally
            {
            }
            return(true);
        }
示例#11
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();
                }
            }
        }
示例#12
0
        /// <summary>
        /// 修改原始方法-增加角度文件计算
        /// 修改说明:
        /// 修改创建输出文件:原输出一个文件,现输出包含角度多个文件
        /// 修改输出文件赋值部分
        /// </summary>
        /// <param name="isangle">是否假如角度文件进行计算</param>
        /// <param name="outDir">输出文件夹</param>
        /// <param name="filenames">输入文件-主ldf文件</param>
        /// <param name="modelCalcBands"></param>
        /// <param name="orderCalcBands"></param>
        /// <param name="outBands"></param>
        /// <param name="calcModel"></param>
        /// <returns></returns>
        public bool AngleProcessCSD(string outDir, string[] filenames, int[] modelCalcBands, int[] orderCalcBands, Dictionary <int, int> outBands, string calcModel)
        {
            IRasterDataProvider outRaster        = null;
            List <RasterMaper>  listoutrastermap = new List <RasterMaper>();
            enumDataType        angletype        = enumDataType.Int16;
            List <RasterMaper>  rms      = new List <RasterMaper>();
            List <RasterMaper>  rmsangle = new List <RasterMaper>();//角度输入文件rm

            List <int> outbandsSrc  = new List <int>();
            List <int> listoutindex = new List <int>();
            //输入文件角度对应键值对 分别为影像文件序号,影像文件对应的角度文件序号
            Dictionary <int, List <int> > _dicangle = new Dictionary <int, List <int> >();

            outbandsSrc.AddRange(orderCalcBands);
            foreach (int key in outBands.Keys)
            {
                outbandsSrc.Add(outBands[key]);
            }
            try
            {
                enumDataType        datatype = enumDataType.Atypism;
                IRasterDataProvider rdp      = null;
                RasterMaper         rdpRm    = null;
                //rmlist增加常规影像文件
                for (int i = 0; i < filenames.Length; i++)
                {
                    rdp = GeoDataDriver.Open(filenames[i]) as IRasterDataProvider;
                    if (rdp != null)
                    {
                        datatype = rdp.DataType;
                        rdpRm    = new RasterMaper(rdp, outbandsSrc.ToArray());
                        rms.Add(rdpRm);
                    }
                }
                IExtractFuncProvider <T> prd = ExtractFuncProviderFactory.CreateExtractFuncProvider <T>(modelCalcBands, calcModel, null);
                _boolFunc = prd.GetBoolFunc();
                int inVisitorCount    = rms.Count;
                int inVisitorBand     = orderCalcBands.Length;
                int resultInFileIndex = 0;
                #region 输出文件准备
                string outFileName = outDir + "\\" + GetFileName(filenames, ".ldf");
                outRaster = CreateOutRaster(outFileName, rms.ToArray(), datatype, outBands.Count);
                #endregion
                RasterMaper[] fileIns  = rms.ToArray();
                RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, outBands.Keys.ToArray()) };
                //创建处理模型
                RasterProcessModel <T, T> rfr = null;
                rfr = new RasterProcessModel <T, T>(ConsoleWrite);
                rfr.SetRaster(fileIns, fileOuts);
                List <T> curValues   = new List <T>();
                List <T> nextValues  = new List <T>();
                List <T> indexValues = new List <T>();
                rfr.RegisterCalcModel(new RasterCalcHandler <T, T>((rvInVistor, rvOutVistor, aoi) =>
                {
                    int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX;

                    if (rvInVistor[0].RasterBandsData == null)
                    {
                        return;
                    }
                    for (int index = 0; index < dataLength; index++)
                    {
                        curValues.Clear();
                        for (int inBnad = 0; inBnad < inVisitorBand; inBnad++)
                        {
                            if (rvInVistor[0].RasterBandsData[inBnad] == null)
                            {
                                return;
                            }
                            curValues.Add(rvInVistor[0].RasterBandsData[inBnad][index]);
                        }
                        resultInFileIndex = 0;

                        for (int inFile = 1; inFile < inVisitorCount; inFile++)
                        {
                            try
                            {
                                if (rvInVistor[inFile].RasterBandsData == null)
                                {
                                    return;
                                }
                                for (int inBnad = 0; inBnad < inVisitorBand; inBnad++)
                                {
                                    if (rvInVistor[inFile].RasterBandsData[inBnad] == null)
                                    {
                                        return;
                                    }
                                    nextValues.Add(rvInVistor[inFile].RasterBandsData[inBnad][index]);
                                }
                                indexValues.AddRange(curValues);
                                indexValues.AddRange(nextValues);
                                if (_boolFunc != null)
                                {
                                    if (!_boolFunc(index, indexValues.ToArray()))
                                    {
                                        resultInFileIndex = inFile;
                                        curValues.Clear();
                                        curValues.AddRange(nextValues);
                                    }
                                }
                            }
                            finally
                            {
                                indexValues.Clear();
                                nextValues.Clear();
                            }
                        }
                        for (int outBand = 0; outBand < outBands.Count; outBand++)
                        {
                            rvOutVistor[0].RasterBandsData[outBand][index] = rvInVistor[resultInFileIndex].RasterBandsData[inVisitorBand + outBand][index];
                        }
                        listoutindex.Add(resultInFileIndex);
                    }
                }));
                //执行
                rfr.Excute();

                #region 输入文件准备
                for (int i = 0; i < filenames.Length; i++)
                {
                    string[] anglefiles = GetAngleFilesByMainFile(filenames[i]);
                    for (int j = 0; j < anglefiles.Length; j++)
                    {
                        if (!File.Exists(anglefiles[j]))
                        {
                            continue;
                        }
                        IRasterDataProvider rdtemp = GeoDataDriver.Open(anglefiles[j]) as IRasterDataProvider;;
                        RasterMaper         rmtemp = new RasterMaper(rdtemp, new int[] { 1 });
                        rmsangle.Add(rmtemp);
                        List <int> itemangleindex = new List <int>();
                        itemangleindex.Add(rmsangle.Count - 1);
                        if (!_dicangle.Keys.Contains(i))//新增主键
                        {
                            _dicangle.Add(i, itemangleindex);
                        }
                        else//已经包含主键
                        {
                            _dicangle[i].Add(rmsangle.Count - 1);
                        }
                    }
                }
                #endregion
                #region 输出文件准备
                string[] outanglefiles = GetAngleFilesByMainFile(outFileName);
                for (int i = 0; i < outanglefiles.Length; i++)
                {
                    IRasterDataProvider itemraster = CreateOutRaster(outanglefiles[i], rmsangle.ToArray(), angletype, 1);//角度文件只有一个波段
                    listoutrastermap.Add(new RasterMaper(itemraster, new int[] { 1 }));
                }
                RasterMaper[] fileInsangle  = rmsangle.ToArray();
                RasterMaper[] fileOutsangle = listoutrastermap.ToArray();
                #endregion
                //创建处理模型
                RasterProcessModel <UInt16, UInt16> rfrangle = new RasterProcessModel <UInt16, UInt16>();;
                rfrangle.SetRaster(fileInsangle, fileOutsangle);
                int totalindex = 0;
                rfrangle.RegisterCalcModel(new RasterCalcHandler <UInt16, UInt16>((rvInVistor, rvOutVistor, aoi) =>
                {
                    int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX;
                    for (int i = 0; i < dataLength; i++)
                    {
                        int rasterindex            = listoutindex[totalindex + i];//当前点的合成数据所在文件序号
                        List <int> listangleindexs = _dicangle[rasterindex];
                        for (int outangleindex = 0; outangleindex < listangleindexs.Count; outangleindex++)
                        {
                            int _angleindex = listangleindexs[outangleindex];
                            rvOutVistor[outangleindex].RasterBandsData[0][i] = rvInVistor[_angleindex].RasterBandsData[0][i];
                        }
                    }
                    totalindex += dataLength;
                }

                                                                                  ));
                rfrangle.Excute();
                Console.WriteLine("全部生成完成!");
            }
            finally
            {
                if (outRaster != null)
                {
                    outRaster.Dispose();
                }
                if (listoutrastermap.Count > 0)
                {
                    for (int i = 0; i < listoutrastermap.Count; i++)
                    {
                        listoutrastermap[i].Raster.Dispose();//是否可以这样释放
                    }
                }
            }
            return(true);
        }
示例#13
0
        /// <summary>
        /// 地理数据拼接:地理坐标,投影坐标
        /// 拼接输出ldf
        /// 支持按高度角数据拼接,高度角数据为后缀为".SolarZenith.ldf"的附加文件,值为扩大了100倍的short类型的高度角值。
        /// 本拼接程序会判断是否有高度角数据:“.SolarZenith.ldf”,如果有,则拼接时候会依据高度角的大小关系执行是否覆盖操作,如果没有,则按照有无数据执行拼接。
        /// </summary>
        /// <param name="rasterFiles"></param>
        /// <param name="outRasterFile"></param>
        /// <param name="geoHeader"></param>
        /// <param name="bandMaps"></param>
        /// <param name="progress"></param>
        public void Mosaic(string[] rasterFiles, string outRasterFile, GeoInfo geoHeader, string[] bandMaps, Action <int, string> progress)
        {
            int[] bandMap = null;
            if (!GetBandMap(bandMaps, out bandMap))
            {
                if (progress != null)
                {
                    progress(0, "输入参数错误,参数[要拼接的波段]不正确");
                }
                return;
            }
            if (bandMap == null || bandMap.Length == 0)
            {
                if (progress != null)
                {
                    progress(0, "输入参数错误,[要拼接的波段]为空或不正确");
                }
                return;
            }
            int bandCount = bandMap.Length;
            ISpatialReference spatialRef = TryFindSpatialRef(rasterFiles);

            using (IRasterDataProvider outraster = CreateMosaicRaster(outRasterFile, geoHeader, bandCount, spatialRef))
            {
                string filename                       = null;
                IRasterDataProvider raster            = null;
                string solarZenithFilename            = null;
                IRasterDataProvider solarZenithRaster = null;

                RasterMaper         outSolarZenithMap   = null;// new RasterMaper(solarZenithRaster, new int[] { 1 });
                string              outSolarZenithFile  = Path.ChangeExtension(outRasterFile, ".SolarZenith.ldf");
                IRasterDataProvider outSolarZenithRster = null;
                try
                {
                    for (int f = 0; f < rasterFiles.Length; f++)
                    {
                        filename            = rasterFiles[f];
                        solarZenithFilename = Path.ChangeExtension(filename, ".SolarZenith.ldf");
                        if (progress != null)
                        {
                            progress((int)((f + 1) * 100f / rasterFiles.Length), string.Format("{0}/{1}", f + 1, rasterFiles.Length));
                        }
                        try
                        {
                            raster = GeoDataDriver.Open(filename) as IRasterDataProvider;
                            if (raster == null)
                            {
                                continue;
                            }
                            //if (raster is ILdfDataProvider)
                            //{
                            //    Ldf1Header header = (raster as ILdfDataProvider).Header as Ldf1Header;
                            //    if (!header.IsDay)
                            //    {
                            //        Console.WriteLine("跳过晚上数据" + Path.GetFileName(filename));
                            //        continue;
                            //    }
                            //}
                            if (File.Exists(outSolarZenithFile))
                            {
                                outSolarZenithRster = GeoDataDriver.Open(outSolarZenithFile, enumDataProviderAccess.Update, null) as IRasterDataProvider;
                                outSolarZenithMap   = new RasterMaper(outSolarZenithRster, new int[] { 1 });
                            }

                            RasterMaper rmSz = null;
                            if (File.Exists(solarZenithFilename))
                            {
                                solarZenithRaster = GeoDataDriver.Open(solarZenithFilename) as IRasterDataProvider;
                                rmSz = new RasterMaper(solarZenithRaster, new int[] { 1 });
                            }
                            RasterMaper rmin  = new RasterMaper(raster, bandMap);
                            RasterMaper rmout = new RasterMaper(outraster, bandMap);
                            RasterProcessModel <short, short> rp = new RasterProcessModel <short, short>();
                            RasterMaper[] rmIns, rmOuts;
                            if (rmSz != null)
                            {
                                rmIns = new RasterMaper[] { rmin, rmSz }
                            }
                            ;
                            else
                            {
                                rmIns = new RasterMaper[] { rmin }
                            };
                            if (outSolarZenithMap != null)
                            {
                                rmOuts = new RasterMaper[] { rmout, outSolarZenithMap }
                            }
                            ;
                            else
                            {
                                rmOuts = new RasterMaper[] { rmout }
                            };
                            rp.SetRaster(rmIns, rmOuts);
                            rp.RegisterCalcModel(new RasterCalcHandlerFun <short, short>((rasterVistor, target, map) =>
                            {
                                if (rasterVistor[0] == null || rasterVistor[0].RasterBandsData.Length == 0)
                                {
                                    return(false);
                                }
                                if (target[0] == null || target[0].RasterBandsData[0].Length == 0)
                                {
                                    return(false);
                                }
                                if (rasterVistor[0].RasterBandsData[0] == null)
                                {
                                    return(false);
                                }
                                //目标角度数据存在,源角度数据不存在,不做拼接
                                if (target.Length != 1 && rasterVistor.Length == 1)
                                {
                                    return(false);
                                }
                                bool isUpdate = false;
                                //不使用天顶角数据,补数据
                                if (target.Length == 1 || rasterVistor.Length == 1)
                                {
                                    for (int i = 0; i < target[0].RasterBandsData[0].Length; i++)
                                    {
                                        if (rasterVistor[0].RasterBandsData[0][i] == 0)//空值
                                        {
                                            continue;
                                        }
                                        if (target[0].RasterBandsData[0][i] == 0)
                                        {
                                            isUpdate = true;
                                            for (int b = 0; b < bandCount; b++)
                                            {
                                                target[0].RasterBandsData[b][i] = rasterVistor[0].RasterBandsData[b][i];
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    for (int i = 0; i < target[0].RasterBandsData[0].Length; i++)
                                    {
                                        if (rasterVistor[0].RasterBandsData[0][i] == 0)//空值
                                        {
                                            continue;
                                        }

                                        /*
                                         * 太阳高度表示昼夜状态
                                         * 在晨昏线上的各地太阳高度为0 °,表示正经历昼夜更替;
                                         * 在昼半球上的各地太阳高度大于0°,表示白昼;
                                         * 在夜半球上的各地太阳高度小于0°,表示黑夜。
                                         * 日出、日落时,太阳高度为0
                                         * 即:
                                         * 0°附近在日落或日出
                                         * -90°和0°之间在晚上
                                         * 上午太阳高度逐渐增大,最大时为太阳上中天,即是正午,午后太阳高度又逐渐缩小。
                                         */
                                        //(高度角 = 90 - 天顶角)

                                        //高度角有效范围:
                                        //这里读取的是SolarZenith太阳天顶,有效范围0-180。
                                        //天顶角0-90为白天,小值为接近中午
                                        if (rasterVistor.Length == 1 || rasterVistor[1] == null || rasterVistor[1].RasterBandsData[0] == null ||
                                            target.Length == 1 || target[1] == null)
                                        {
                                            if (target[0].RasterBandsData[0][i] == 0)//如果没有角度数据,则采取补数据的方式(即不覆盖已有数据)
                                            {
                                                isUpdate = true;
                                                for (int b = 0; b < bandCount; b++)//拼接所有通道数据
                                                {
                                                    target[0].RasterBandsData[b][i] = rasterVistor[0].RasterBandsData[b][i];
                                                }
                                            }
                                        }
                                        else if (rasterVistor[1].RasterBandsData[0][i] > 9000 || rasterVistor[1].RasterBandsData[0][i] < 0)//原高度角为夜晚或者不合理
                                        {
                                            continue;
                                        }
                                        else if (target[1].RasterBandsData[0][i] == 0)
                                        {
                                            isUpdate = true;
                                            for (int b = 0; b < bandCount; b++)
                                            {
                                                target[0].RasterBandsData[b][i] = rasterVistor[0].RasterBandsData[b][i];
                                            }
                                            //更新目标高度角数据
                                            target[1].RasterBandsData[0][i] = rasterVistor[1].RasterBandsData[0][i];
                                        }
                                        else if (rasterVistor[1].RasterBandsData[0][i] < target[1].RasterBandsData[0][i])//取高度角小的
                                        {
                                            isUpdate = true;
                                            for (int b = 0; b < bandCount; b++)
                                            {
                                                target[0].RasterBandsData[b][i] = rasterVistor[0].RasterBandsData[b][i];
                                            }
                                            //更新目标高度角数据
                                            target[1].RasterBandsData[0][i] = rasterVistor[1].RasterBandsData[0][i];
                                        }
                                    }
                                }
                                if (isUpdate)
                                {
                                    return(true);
                                }
                                else
                                {
                                    return(false);
                                }
                            }
                                                                                         ));
                            int rowCount = rp.CalcRowCount();
                            rp.Excute(0, rowCount);
                        }
                        finally
                        {
                            if (raster != null)
                            {
                                raster.Dispose();
                                raster = null;
                            }
                            if (outSolarZenithRster != null)
                            {
                                outSolarZenithRster.Dispose();
                                outSolarZenithRster = null;
                            }
                        }
                    }
                }
                finally
                {
                    if (outSolarZenithRster != null)
                    {
                        outSolarZenithRster.Dispose();
                        outSolarZenithRster = null;
                    }
                }
            }
        }
示例#14
0
        private IRasterDataProvider GetRasterDataProviderMESI()
        {
            string fname = @"E:\data\dst\FY3A_MERSI_GBAL_L1_20110513_0220_1000M_MS_PRJ_DXX.LDF";

            return(GeoDataDriver.Open(fname) as IRasterDataProvider);
        }
示例#15
0
        public void Do(InputArg inArg)
        {
            CheckAtg(inArg);
            string    projectionIdentify = inArg.ProjectionIdentify;
            OutputArg outArg             = new OutputArg();

            try
            {
                using (IRasterDataProvider inputRaster = GeoDataDriver.Open(inArg.InputFilename) as IRasterDataProvider)
                {
                    DataIdentify dataIdentify = inputRaster.DataIdentify;
                    outArg.OrbitFilename      = Path.GetFileName(inArg.InputFilename);
                    outArg.Satellite          = dataIdentify.Satellite;
                    outArg.Sensor             = dataIdentify.Sensor;
                    outArg.Level              = "L1";
                    outArg.ProjectionIdentify = projectionIdentify;
                    outArg.ObservationDate    = dataIdentify.OrbitDateTime.ToString("yyyyMMdd");
                    outArg.ObservationTime    = dataIdentify.OrbitDateTime.ToString("HHmm");
                    outArg.Station            = ParseStation(Path.GetFileName(inArg.InputFilename));
                    outArg.DayOrNight         = DayOrNight(inputRaster);
                    outArg.OrbitIdentify      = CalcOrbitIdentify(dataIdentify.OrbitDateTime, inArg.PervObservationDate, inArg.PervObservationTime, inArg.OrbitIdentify);
                    outArg.Length             = new FileInfo(inArg.InputFilename).Length;
                    string validEnvelopeMsg = "";
                    if (!string.IsNullOrWhiteSpace(inArg.DayNight))
                    {
                        if (inArg.DayNight != "daynight" && outArg.DayOrNight == "X")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "未设定处理白天和晚上数据,白天晚上标记未知:X";
                        }
                        else if (inArg.DayNight == "day" && outArg.DayOrNight != "D")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为只处理白天数据,当前数据标记为晚上";
                        }
                        else if (inArg.DayNight == "night" && outArg.DayOrNight != "N")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为只处理晚上数据,当前数据标记为白天";
                        }
                        else if (inArg.DayNight == "notnight" && outArg.DayOrNight == "N")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为不处理晚上数据,当前数据标记为晚上";
                        }
                        else if (inArg.DayNight == "notday" && outArg.DayOrNight == "D")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为不处理白天数据,当前数据标记为白天";
                        }
                    }
                    if (inArg.ValidEnvelopes == null || inArg.ValidEnvelopes.Length == 0)
                    {
                        outArg.LogLevel = "error";
                        outArg.LogInfo  = "参数错误:未正确设置ValidEnvelopes";
                    }
                    else if (!ValidEnvelope(inputRaster, inArg.ValidEnvelopes, out validEnvelopeMsg))
                    {
                        outArg.LogLevel = "info";
                        outArg.LogInfo  = validEnvelopeMsg;
                    }
                    else
                    {
                        GenericFilename genFilenmae = new GenericFilename();
                        PrjOutArg       prjArg;
                        if (inArg.Envelopes == null || inArg.Envelopes.Length == 0)
                        {
                            prjArg = new PrjOutArg(projectionIdentify, null, inArg.ResolutionX, inArg.ResolutionY, inArg.OutputDir);
                        }
                        else
                        {
                            prjArg = new PrjOutArg(projectionIdentify, inArg.Envelopes, inArg.ResolutionX, inArg.ResolutionY, inArg.OutputDir);
                        }
                        //prjArg.Args = new string[] { "SolarZenith"};
                        if (inArg.Bands != null && inArg.Bands.Length != 0)
                        {
                            prjArg.SelectedBands = inArg.Bands;
                            Console.WriteLine("SelectedBands:" + string.Join(",", prjArg.SelectedBands));
                        }
                        //扩展参数
                        List <string> extArgs = new List <string>();
                        extArgs.Add("IsClearPrjCache");
                        if (inArg.ExtArgs != null)
                        {
                            extArgs.AddRange(inArg.ExtArgs);
                        }
                        prjArg.Args = extArgs.ToArray();
                        ProjectionFactory prjFactory = new ProjectionFactory();
                        string            retMessage = "";
                        string[]          files      = prjFactory.Project(inputRaster, prjArg, new Action <int, string>(OnProgress), out retMessage);
                        prjFactory = null;
                        //投影结束,执行拼接,如果有拼接节点
                        List <OutFileArg> fileArgs = new List <OutFileArg>();
                        for (int i = 0; i < files.Length; i++)
                        {
                            string file = files[i];
                            if (string.IsNullOrWhiteSpace(file) || !File.Exists(file))
                            {
                                continue;
                            }
                            OutFileArg    fileArg = new OutFileArg();
                            CoordEnvelope env     = null;
                            float         resolutionX;
                            float         resolutionY;
                            string        overViewFilename = "";
                            using (IRasterDataProvider outfileRaster = GeoDataDriver.Open(file) as IRasterDataProvider)
                            {
                                overViewFilename = OverViewHelper.OverView(outfileRaster, _prjPngSize);
                                env         = outfileRaster.CoordEnvelope;
                                resolutionX = outfileRaster.ResolutionX;
                                resolutionY = outfileRaster.ResolutionY;
                                TryMosaicFile(inArg, outfileRaster, dataIdentify, outArg.DayOrNight);
                            }
                            fileArg.OutputFilename = Path.GetFileName(file);
                            fileArg.Thumbnail      = (string.IsNullOrWhiteSpace(overViewFilename) && File.Exists(overViewFilename) ? "" : Path.GetFileName(overViewFilename));
                            string solarZenithFile    = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".SolarZenith.ldf");
                            string solarZenithHdrFile = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".SolarZenith.hdr");
                            fileArg.ExtendFiles = Path.ChangeExtension(Path.GetFileName(file), "hdr") +
                                                  (string.IsNullOrWhiteSpace(solarZenithFile) && File.Exists(solarZenithFile) ? "" : "," + Path.GetFileName(solarZenithFile)) +
                                                  (string.IsNullOrWhiteSpace(solarZenithHdrFile) && File.Exists(solarZenithHdrFile) ? "" : "," + Path.GetFileName(solarZenithHdrFile));
                            fileArg.Envelope    = new PrjEnvelopeItem("GBAL", env == null ? null : new RasterProject.PrjEnvelope(env.MinX, env.MaxX, env.MinY, env.MaxY));
                            fileArg.ResolutionX = resolutionX.ToString();
                            fileArg.ResolutionY = resolutionY.ToString();
                            fileArg.Length      = new FileInfo(file).Length;
                            fileArgs.Add(fileArg);
                            if (inArg.IsOnlySaveMosaicFile)
                            {
                                TryDeleteFile(file);
                            }
                        }
                        outArg.OutputFiles = fileArgs.ToArray();
                        outArg.LogLevel    = "info";
                        if (string.IsNullOrWhiteSpace(retMessage))
                        {
                            outArg.LogInfo = "投影成功";
                        }
                        else
                        {
                            outArg.LogInfo = retMessage;
                        }
                        if (string.IsNullOrWhiteSpace(validEnvelopeMsg))
                        {
                            outArg.LogInfo = outArg.LogInfo + validEnvelopeMsg;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                outArg.LogLevel = "error";
                outArg.LogInfo  = ex.Message;
                LogFactory.WriteLine(ex);
            }
            finally
            {
                string outXmlFilename = Path.Combine(inArg.OutputDir, Path.GetFileName(inArg.InputFilename) + ".xml");
                OutputArg.WriteXml(outArg, outXmlFilename);
            }
        }
示例#16
0
        public List <string[]> SeriesStaticAOI(string[] filesL, int bandNumL, string[] fillvalueL, out Dictionary <DateTime, string> filedate, Action <int, string> progressCallback)
        {
            int[] aoiIndex;
            Size  fileSize;
            int   aoilength;
            int   count = 0;
            IRasterDataProvider arrayPrd   = null;
            List <string[]>     resultList = new List <string[]>();

            filedate = new Dictionary <DateTime, string>();
            DateTime t = DateTime.MinValue;

            try
            {
                foreach (string file in filesL)
                {
                    enumDataType datatype = enumDataType.Unknow;
                    using (IRasterDataProvider dataPrd = GeoDataDriver.Open(file) as IRasterDataProvider)
                    {
                        datatype = dataPrd.DataType;
                        fileSize = new Size(dataPrd.Width, dataPrd.Height);
                        //创建AOI(基于数据的地理范围)
                        aoiIndex = GetAOI(dataPrd.CoordEnvelope, _aoiContainer, fileSize);
                        if (aoiIndex == null || aoiIndex.Length <= 0)
                        {
                            throw new ArgumentException("矢量AOI区域设置无效或范围不合法!");
                        }
                    }
                    aoilength = aoiIndex.Length;
                    count     = 0;
                    arrayPrd  = null;
                    switch (datatype)
                    {
                    case enumDataType.Float:
                        float[][] rasterbandsF = new float[1][];
                        {
                            rasterbandsF[0] = GetHistArrayAOI <float>(new string[] { file }, bandNumL, fileSize.Width, fileSize.Height, datatype, aoiIndex, fillvalueL, out count);
                            arrayPrd        = new ArrayRasterDataProvider <float>("Array", rasterbandsF, aoilength, 1);
                        }
                        break;

                    case enumDataType.Int16:
                        short[][] rasterbandsS = new short[1][];
                        {
                            rasterbandsS[0] = GetHistArrayAOI <short>(new string[] { file }, bandNumL, fileSize.Width, fileSize.Height, datatype, aoiIndex, fillvalueL, out count);
                            arrayPrd        = new ArrayRasterDataProvider <short>("Array", rasterbandsS, aoilength, 1);
                        }
                        break;

                    case enumDataType.Byte:
                        Byte[][] rasterbandsB = new Byte[1][];
                        {
                            rasterbandsB[0] = GetHistArrayAOI <Byte>(new string[] { file }, bandNumL, fileSize.Width, fileSize.Height, datatype, aoiIndex, fillvalueL, out count);
                            arrayPrd        = new ArrayRasterDataProvider <Byte>("Array", rasterbandsB, aoilength, 1);
                        }
                        break;

                    default:
                        throw new ArgumentException("暂不支持" + datatype.ToString() + "类型的统计!");
                    }
                    if (arrayPrd.Width == 0 || arrayPrd.Height == 0)
                    {
                        throw new ArgumentException("创建待统计数据失败!" + file);
                    }
                    double[] values;
                    if (CloudParaFileStatics.ComputeMinMaxAvg(arrayPrd, datatype, new int[] { bandNumL }, null, out values, progressCallback))
                    {
                        string date;
                        GetFileTime(file, out date, out t);
                        if (!filedate.ContainsKey(t))
                        {
                            filedate.Add(t, date);
                        }
                        resultList.Add(new string[] { date, values[1].ToString("f2") });
                        if (progressCallback != null)
                        {
                            progressCallback(-1, Path.GetFileName(file) + "统计完成!");
                        }
                    }
                }
                return(resultList);
            }
            finally
            {
                if (arrayPrd != null)
                {
                    arrayPrd.Dispose();
                }
            }
        }
示例#17
0
        private IExtractResult DemAlgorithm(Action <int, string> progressTracker)
        {
            TVDIUCArgs args = _argumentProvider.GetArg("ArgumentSetting") as TVDIUCArgs;

            if (args == null)
            {
                PrintInfo("请设置进行温度植被干旱指数计算的参数。");
                return(null);
            }
            string         ndviFile  = args.NDVIFile;
            string         lstFile   = args.ECLstFile;
            DryWetEdgeArgs dryWetArg = args.DryWetEdgesFitting;

            if (string.IsNullOrEmpty(ndviFile) || string.IsNullOrEmpty(lstFile))
            {
                PrintInfo("请选择进行温度植被干旱指数计算所需的文件。");
                return(null);
            }
            if (dryWetArg == null)
            {
                PrintInfo("请先进行干湿边拟合,计算拟合参数。");
                return(null);
            }
            double maxA = dryWetArg.MaxA, maxB = dryWetArg.MaxB, minA = dryWetArg.MinA, minB = dryWetArg.MinB;

            if (args.TVDIParas == null || args.TVDIParas.LstFile == null)
            {
                return(null);
            }
            int ndviBand = args.TVDIParas.NdviFile.Band;

            if (ndviBand == -1)
            {
                return(null);
            }
            int lstZoom = args.TVDIParas.Zoom; //args.TVDIParas.LstFile.Zoom;

            if (lstZoom == 0)
            {
                return(null);
            }
            int lstMin     = args.TVDIParas.LstFile.Min;
            int lstMax     = args.TVDIParas.LstFile.Max;
            int ndviCloudy = args.TVDIParas.NdviFile.Cloudy;
            //输入文件准备
            List <RasterMaper>  rms     = new List <RasterMaper>();
            IRasterDataProvider ndviPrd = null;
            IRasterDataProvider lstPrd  = null;

            try
            {
                ndviPrd = GeoDataDriver.Open(ndviFile) as IRasterDataProvider;
                if (ndviPrd.BandCount < ndviBand)
                {
                    PrintInfo("请选择正确的植被指数文件进行温度植被干旱指数计算。");
                    return(null);
                }
                RasterMaper ndviRm = new RasterMaper(ndviPrd, new int[] { ndviBand });
                rms.Add(ndviRm);

                lstPrd = GeoDataDriver.Open(lstFile) as IRasterDataProvider;
                if (lstPrd.BandCount < 1)
                {
                    PrintInfo("请选择正确的陆表高温文件进行温度植被干旱指数计算。");
                    return(null);
                }
                RasterMaper lstRm = new RasterMaper(lstPrd, new int[] { 1 });
                rms.Add(lstRm);

                //输出文件准备
                RasterIdentify ri          = GetRasterIdentifyID(new string[] { ndviFile, lstFile });
                string         outFileName = ri.ToWksFullFileName(".dat");
                //string outFileName = GetFileName(new string[] { ndviFile, lstFile }, _subProductDef.ProductDef.Identify, _identify, ".dat", null);
                using (IRasterDataProvider outRaster = CreateOutRaster(outFileName, rms.ToArray()))
                {
                    //栅格数据映射
                    RasterMaper[] fileIns  = rms.ToArray();
                    RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                    RasterProcessModel <short, short> rfr = new RasterProcessModel <short, short>(progressTracker);
                    rfr.SetRaster(fileIns, fileOuts);
                    double tmin = 0d, tmax = 0d;
                    short  value0 = 0, value1 = 0;
                    rfr.RegisterCalcModel(new RasterCalcHandler <short, short>((rvInVistor, rvOutVistor, aoi) =>
                    {
                        int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX;
                        if (rvInVistor[0].RasterBandsData == null || rvInVistor[1].RasterBandsData == null ||
                            rvInVistor[0].RasterBandsData[0] == null || rvInVistor[1].RasterBandsData[0] == null)
                        {
                            return;
                        }
                        for (int index = 0; index < dataLength; index++)
                        {
                            value0 = rvInVistor[0].RasterBandsData[0][index];
                            value1 = rvInVistor[1].RasterBandsData[0][index];

                            #region LST
                            if (value1 == 9000)
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = (Int16)(2 * lstZoom);    //非中国区域陆地
                                continue;
                            }
                            if (value1 == 9999)
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = (Int16)Math.Round((2.5 * lstZoom), 0);    //海区
                                continue;
                            }
                            if (value1 == 9998)
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = (Int16)Math.Round((2.55 * lstZoom), 0);    //云区
                                continue;
                            }
                            if (value1 == 9997)
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = (Int16)Math.Round((1.5 * lstZoom), 0);    //无数据区域
                                continue;
                            }
                            if (value1 < lstMin || value1 > lstMax)
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = (Int16)Math.Round((1.5 * lstZoom), 0);
                                continue;
                            }
                            #endregion

                            #region ndvi检查

                            if (value0 == ndviCloudy)                        //过滤无效值
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = (Int16)Math.Round((2.55 * lstZoom), 0);
                                continue;
                            }
                            if (value0 == 0)
                            {
                                continue;
                            }
                            #endregion

                            tmin = minA + minB * value0;
                            tmax = maxA + maxB * value0;
                            if (tmin == tmax)
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = 0;
                            }
                            else
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = (Int16)(((value1 - tmin) / (tmax - tmin)) * lstZoom);
                            }
                        }
                    }));
                    rfr.Excute();
                    FileExtractResult res = new FileExtractResult(_subProductDef.Identify, outFileName, true);
                    res.SetDispaly(false);
                    return(res);
                }
            }
            finally
            {
                if (ndviPrd != null)
                {
                    ndviPrd.Dispose();
                }
                if (lstPrd != null)
                {
                    lstPrd.Dispose();
                }
            }
        }
示例#18
0
        /// <summary>
        /// 提取单文件的AOI区域的数据
        /// </summary>
        /// <param name="file">输入文件</param>
        /// <param name="bandNum">波段</param>
        /// <param name="fillvalue">忽略值</param>
        /// <param name="outaoiIndex">AOI在采样后外包矩形中的Index</param>
        /// <param name="subAOISize">AOI外包矩形原始大小</param>
        /// <param name="outAOISize">AOI外包矩形采样后大小</param>
        /// <param name="xoffset">AOI外包矩形在文件中的xoffset</param>
        /// <param name="yoffset">AOI外包矩形在文件中的yoffset</param>
        /// <returns></returns>
        private double[] GetResampledDataFromSubRegionOutIndex(string file, int bandNum, string[] fillvalue, int[] outaoiIndex, Size subAOISize, Size outAOISize, int xoffset, int yoffset)
        {
            bool isNeedReSample = true;

            if (subAOISize == outAOISize)
            {
                isNeedReSample = false;
            }
            double[]     standardmxi;
            enumDataType datatype   = enumDataType.Unknow;
            int          totalwidth = outaoiIndex.Length;

            using (IRasterDataProvider dataPrd = GeoDataDriver.Open(file) as IRasterDataProvider)
            {
                if (dataPrd == null)
                {
                    return(null);
                }
                datatype = dataPrd.DataType;
                switch (datatype)
                {
                case enumDataType.Byte:
                {
                    Byte[]  outDataB    = null;
                    Byte [] leftoutData = new Byte [totalwidth];
                    Byte[]  fillValues  = GetFillValues <Byte>(fillvalue, enumDataType.Byte);
                    Byte [] oriData     = GetDataValue <Byte>(dataPrd, bandNum, subAOISize.Width, subAOISize.Height, xoffset, yoffset);
                    if (isNeedReSample)
                    {
                        AnaliysisDataPreprocess.MedianRead(oriData, subAOISize, outAOISize, out outDataB);
                    }
                    else
                    {
                        outDataB = oriData;
                    }
                    for (int i = 0; i < totalwidth; i++)
                    {
                        Byte data = outDataB[outaoiIndex[i]];
                        if (fillValues != null && fillValues.LongLength > 0 && fillValues.Contains(data))
                        {
                            continue;
                        }
                        leftoutData[i] = data;
                    }
                    AnaliysisDataPreprocess.StandardDeviation(leftoutData, out standardmxi);
                    return(standardmxi);
                }

                case enumDataType.Int16:
                {
                    short[] outDataB    = null;
                    short[] leftoutData = new short[totalwidth];
                    short[] fillValues  = GetFillValues <short>(fillvalue, enumDataType.Byte);
                    short[] oriData     = GetDataValue <short>(dataPrd, bandNum, subAOISize.Width, subAOISize.Height, xoffset, yoffset);
                    if (isNeedReSample)
                    {
                        AnaliysisDataPreprocess.MedianRead(oriData, subAOISize, outAOISize, out outDataB);
                    }
                    else
                    {
                        outDataB = oriData;
                    }
                    for (int i = 0; i < totalwidth; i++)
                    {
                        short data = outDataB[outaoiIndex[i]];
                        if (fillValues != null && fillValues.LongLength > 0 && fillValues.Contains(data))
                        {
                            continue;
                        }
                        leftoutData[i] = data;
                    }
                    AnaliysisDataPreprocess.StandardDeviation(leftoutData, out standardmxi);
                    return(standardmxi);
                }

                case enumDataType.Float:
                {
                    float[] outDataB    = null;
                    float[] leftoutData = new float[totalwidth];
                    float[] fillValues  = GetFillValues <float>(fillvalue, enumDataType.Float);
                    float[] oriData     = GetDataValue <float>(dataPrd, bandNum, subAOISize.Width, subAOISize.Height, xoffset, yoffset);
                    if (isNeedReSample)
                    {
                        AnaliysisDataPreprocess.MedianRead(oriData, subAOISize, outAOISize, out outDataB);
                    }
                    else
                    {
                        outDataB = oriData;
                    }
                    for (int i = 0; i < totalwidth; i++)
                    {
                        float data = outDataB[outaoiIndex[i]];
                        if (fillValues != null && fillValues.LongLength > 0 && fillValues.Contains(data))
                        {
                            continue;
                        }
                        leftoutData[i] = data;
                    }
                    AnaliysisDataPreprocess.StandardDeviation(leftoutData, out standardmxi);
                    return(standardmxi);
                }

                default:
                    return(null);
                }
            }
        }
示例#19
0
 private IRasterDataProvider GetSrcRaster(string filename)
 {
     return(GeoDataDriver.Open(filename) as IRasterDataProvider);
 }
示例#20
0
        public override void Execute(string argument)
        {
            if (string.IsNullOrWhiteSpace(argument) || !Directory.Exists(argument))
            {
                return;
            }
            string fullfilename;
            string maskpng = AppDomain.CurrentDomain.BaseDirectory + @"\SystemData\ProductArgs\CLD\Cloudsat_Overview_withcountry.png";

            fullfilename = argument;
            ICommand cmd = _smartSession.CommandEnvironment.Get(2000);

            if (cmd != null)
            {
                cmd.Execute(maskpng);
            }
            GeoDo.RSS.Core.DF.CoordEnvelope env = TryGetActiveViewerEnv();
            if (env == null)
            {
                env = new RSS.Core.DF.CoordEnvelope(65, 145, 10, 60);
            }
            //如果测试整个影像数据,则输出图像为:0,37081,37081
            int x1    = 0;
            int x2    = 37081;
            int outnx = 2000;
            int h1    = -1;      //# km
            int h2    = 21;      //# km
            int nz    = 400;     //# Number of pixels in the vertical.(这个偏移需要指定)
            int dtnx  = 0;       //125
            int dtny  = 0;       //13000
            int xn    = x2 - x1; //值从1700到2000,要读取的实际横轴方向数据。(最后这个偏移会通过地理范围,或者时间范围,计算出来)
            //return;
            CloudsatDataProvider raster = GeoDataDriver.Open(fullfilename) as CloudsatDataProvider;
            CloudSatRasterBand   band   = raster.GetRasterBand(1) as CloudSatRasterBand;

            dtnx = band.Width;  //层数
            dtny = band.Height; //点数
            sw.Start();
            float[] Latitude   = raster.ReadVdata("Latitude", null, x1, x2) as float[];
            float[] Longtitude = raster.ReadVdata("Longitude", null, x1, x2) as float[];
            sw.Stop();
            elapsed = sw.ElapsedMilliseconds;
            Console.WriteLine("ReadVdata" + elapsed + "毫秒");
            int cou      = 0;
            int minIndex = 0;
            int maxIndex = Latitude.Length;

            IntersectEnvelope(Latitude, Longtitude, env, ref cou, ref minIndex, ref maxIndex);

            Console.WriteLine(cou + "点在指定范围内");
            float[] times = raster.ReadVdata("Profile_time", null, x1, x2) as float[];
            if (cou > 0 && (x1 != minIndex || x2 != maxIndex))
            {
                x1 = minIndex;
                x2 = maxIndex;
                xn = x2 - x1 + 1;
                float[] lats  = new float[xn];
                float[] longs = new float[xn];
                float[] ts    = new float[xn];
                Buffer.BlockCopy(Latitude, x1 * 4, lats, 0, xn * 4);
                Buffer.BlockCopy(Longtitude, x1 * 4, longs, 0, xn * 4);
                Buffer.BlockCopy(times, x1 * 4, ts, 0, xn * 4);
                Latitude   = lats;
                Longtitude = longs;
                times      = ts;
            }
            string   start_time = raster.ReadAttribute("start_time") as string;
            DateTime dt_start_time;

            dt_start_time = DateTime.ParseExact(start_time, "yyyyMMddHHmmss", null);
            List <DateTime> dts = new List <DateTime>();

            foreach (float time in times)
            {
                dts.Add(dt_start_time.AddMinutes(time));                                              //应为AddSeconds()
            }
            short[] heights = readSDS("Height", new int[] { x1, 0 }, new int[] { xn, dtnx }, raster); //p1c1,p1c2,..,p1c125,p2c1,...
            short[] datas   = readData(new int[] { x1, 0 }, new int[] { xn, dtnx }, band);

            float[] X = new float[xn];//原始数据中的数据点号
            for (int i = 0; i < xn; i++)
            {
                X[i] = i + x1;
            }
            //heights数据是x=125,y=100=>Z[100,125]
            float[,] Z = new float[xn, dtnx];                 //每个点的高度xn = 100, dtnx =125;
            for (int i = 0; i < dtnx; i++)                    //heights的列,层数
            {
                for (int j = 0; j < xn; j++)                  //heights的行,点数
                {
                    Z[j, i] = heights[j * dtnx + i] * 0.001f; //m-->km
                }
            }

            short[,] newdata = new short[xn, dtnx];//点数,层数
            var dest = Marshal.UnsafeAddrOfPinnedArrayElement(newdata, 0);

            Marshal.Copy(datas, 0, dest, datas.Length);//将数据的一维数组变化为2维数组
            Marshal.Release(dest);

            short[,] dat = Rote <short>(newdata);//调换数组的行列,dat为层数×点数的数组;

            Bitmap bmp = null;
            IntPtr src;

            outnx             = xn < 4000 ? xn : 4000;
            float[,] dataf    = interp2d_12(newdata, X, Z, x1, x2, outnx, h2, h1, nz); //将数据进行插值
            float[,] newdataf = Rote <float>(dataf);                                   //调换数组的行列,dat为层数×点数的数组;
            int count = newdataf.Length;

            float[] datac = new float[count];
            src = Marshal.UnsafeAddrOfPinnedArrayElement(newdataf, 0);//
            Marshal.Copy(src, datac, 0, newdataf.Length);
            Marshal.Release(dest);
            DisplayLonLat(Latitude, Longtitude, fullfilename);
            //string[] dtimes = new string[dts.Count];
            //for(int i =0;i< dts.Count;i++)
            //{
            //    DateTime dt  = dts[i];
            //    dtimes[i] = dt.ToString("HH:mm:ss");
            //}
            //try
            //{
            //    bmp = ToBitmap(outnx, nz, datac);//点数(宽),层数(高)
            //    if (bmp != null)
            //    {
            //        string bmpfilename = MifEnvironment.GetFullFileName("2B-GEOPROF.Radar_Reflectivity.bmp");
            //        bmp.Save(bmpfilename);
            //        //OpenFileFactory.Open(bmpfilename);

            //        CloudsatPlotWnd wnd = _smartSession.SmartWindowManager.SmartToolWindowFactory.GetSmartToolWindow(_id) as CloudsatPlotWnd;
            //        if (wnd != null)
            //        {
            //            _smartSession.SmartWindowManager.DisplayWindow(wnd, new WindowPosition(System.Windows.Forms.DockStyle.Bottom, false));
            //            wnd.Reset(fullfilename, bmp, x1, x2, h1, h2, dtimes, null);
            //        }

            //        frmPlot frm = new frmPlot();
            //        ucCloudsatPlot plots = frm.plots;
            //        plots.AddYAxis(dtimes);
            //        plots.Reset(fullfilename, bmp, x1, x2, h1, h2, null);
            //        //plots.Rerender();
            //        //frm.Reset(fullfilename, bmp, x1, x2, h1, h2, dtimes, null);
            //        frm.Show();
            //    }
            //}
            //finally
            //{
            //    //if (bmp != null)
            //    //    bmp.Dispose();
            //}
        }
示例#21
0
        /// <summary>
        /// 中值滤波
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        private IFileExtractResult ComputerMid(string filename, Int16 smoothwindow)
        {
            List <RasterMaper>  rms               = null;
            IRasterDataProvider outRaster         = null;
            RasterProcessModel <float, float> rfr = null;
            //float outResloution = 0.01f;
            string identyString = "MFVI";

            try
            {
                rms = new List <RasterMaper>();
                IRasterDataProvider inRaster1 = GeoDataDriver.Open(filename) as IRasterDataProvider;
                RasterMaper         fileIn1   = new RasterMaper(inRaster1, new int[] { 1 });
                rms.Add(fileIn1);
                string middelFilterFileName = GetFileName(new string[] { filename }, _subProductDef.ProductDef.Identify, identyString, ".dat", null);
                outRaster = CreateOutRaster(middelFilterFileName, enumDataType.Float, rms.ToArray(), inRaster1.ResolutionX);
                RasterMaper   fileOut  = new RasterMaper(outRaster, new int[] { 1 });
                RasterMaper[] fileIns  = rms.ToArray();
                RasterMaper[] fileOuts = new RasterMaper[] { fileOut };
                rfr = new RasterProcessModel <float, float>();
                rfr.SetRaster(fileIns, fileOuts);
                rfr.RegisterCalcModel(new RasterCalcHandler <float, float>((rvInVistor, rvOutVistor, aoi) =>
                {
                    if (rvInVistor[0].RasterBandsData[0] != null)
                    {
                        int dataLength   = rvInVistor[0].SizeY * rvInVistor[0].SizeX;
                        float[] outpixel = new float[dataLength];
                        float[] temp     = new float[smoothwindow * smoothwindow];
                        int col          = rvInVistor[0].SizeX;
                        for (int i = 0; i < dataLength; i++)
                        {
                            if (i < 2 * col || i % col == 0 || (i - 1) % col == 0 || (i + 1) % col == 0 || (i + 2) % col == 0 || i > dataLength - 2 * col)
                            {
                                rvOutVistor[0].RasterBandsData[0][i] = rvInVistor[0].RasterBandsData[0][i];
                            }
                            else
                            {
                                temp[0]  = rvInVistor[0].RasterBandsData[0][i - 2 * col - 2];
                                temp[1]  = rvInVistor[0].RasterBandsData[0][i - 2 * col - 1];
                                temp[2]  = rvInVistor[0].RasterBandsData[0][i - 2 * col];
                                temp[3]  = rvInVistor[0].RasterBandsData[0][i - 2 * col + 1];
                                temp[4]  = rvInVistor[0].RasterBandsData[0][i - 2 * col + 2];
                                temp[5]  = rvInVistor[0].RasterBandsData[0][i - col - 2];
                                temp[6]  = rvInVistor[0].RasterBandsData[0][i - col - 1];
                                temp[7]  = rvInVistor[0].RasterBandsData[0][i - col];
                                temp[8]  = rvInVistor[0].RasterBandsData[0][i - col + 1];
                                temp[9]  = rvInVistor[0].RasterBandsData[0][i - col + 2];
                                temp[10] = rvInVistor[0].RasterBandsData[0][i - 2];
                                temp[11] = rvInVistor[0].RasterBandsData[0][i - 1];
                                temp[12] = rvInVistor[0].RasterBandsData[0][i];
                                temp[13] = rvInVistor[0].RasterBandsData[0][i + 1];
                                temp[14] = rvInVistor[0].RasterBandsData[0][i + 2];
                                temp[15] = rvInVistor[0].RasterBandsData[0][i + col - 2];
                                temp[16] = rvInVistor[0].RasterBandsData[0][i + col - 1];
                                temp[17] = rvInVistor[0].RasterBandsData[0][i + col];
                                temp[18] = rvInVistor[0].RasterBandsData[0][i + col + 1];
                                temp[19] = rvInVistor[0].RasterBandsData[0][i + col + 2];
                                temp[20] = rvInVistor[0].RasterBandsData[0][i + 2 * col - 2];
                                temp[21] = rvInVistor[0].RasterBandsData[0][i + 2 * col - 1];
                                temp[22] = rvInVistor[0].RasterBandsData[0][i + 2 * col];
                                temp[23] = rvInVistor[0].RasterBandsData[0][i + 2 * col + 1];
                                temp[24] = rvInVistor[0].RasterBandsData[0][i + 2 * col + 2];
                                Array.Sort(temp);
                                rvOutVistor[0].RasterBandsData[0][i] = temp[temp.Length / 2];
                            }
                        }
                    }
                }));
                rfr.Excute();
                IFileExtractResult res = new FileExtractResult(_subProductDef.Identify, middelFilterFileName, true);
                res.SetDispaly(false);
                return(res);
            }
            finally
            {
                if (outRaster != null)
                {
                    outRaster.Dispose();
                }
                if (rms != null && rms.Count > 0)
                {
                    foreach (RasterMaper rm in rms)
                    {
                        if (rm.Raster != null)
                        {
                            rm.Raster.Dispose();
                        }
                    }
                }
            }
        }
示例#22
0
        public static bool SetAOIArugment(string[] fnames, IMonitoringSubProduct msp, bool multiSelect, out CoordEnvelope selectedEnvelope)
        {
            float maxResultion           = 0f;
            IRasterDataProvider prd      = null;
            CoordEnvelope       envelope = new CoordEnvelope(double.MaxValue, double.MinValue, double.MaxValue, double.MinValue);

            GeoDo.Project.ISpatialReference prdSpatialRef = null;
            foreach (string item in fnames)
            {
                try
                {
                    prd          = GeoDataDriver.Open(item) as IRasterDataProvider;
                    maxResultion = Math.Max(maxResultion, prd.ResolutionX);
                    envelope     = envelope.Union(new CoordEnvelope(prd.CoordEnvelope.MinX, prd.CoordEnvelope.MinX + prd.ResolutionX * prd.Width,
                                                                    prd.CoordEnvelope.MinY, prd.CoordEnvelope.MinY + prd.ResolutionY * prd.Height));
                    prdSpatialRef = prd.SpatialRef;
                }
                catch
                {
                    throw new ArgumentException("选择的文件:“" + Path.GetFileName(item) + "”无法进行面积统计。");
                }
                finally
                {
                    if (prd != null)
                    {
                        prd.Dispose();
                        prd = null;
                    }
                }
            }
            Size size = new Size((int)(envelope.Width / maxResultion), (int)(envelope.Height / maxResultion));

            using (frmStatSubRegionTemplates frm = new frmStatSubRegionTemplates(size, envelope, maxResultion))
            {
                frm.listView1.MultiSelect = multiSelect;
                if (prdSpatialRef != null)
                {
                    frm.SpatialRef = prdSpatialRef;
                }
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    //Feature[] features = frm.GetSelectedFeatures();
                    //AOIProvider aoiProvider = new AOIProvider(null);
                    //aoiProvider.GetBitmapIndexes
                    msp.ArgumentProvider.SetArg("AOI", frm.GetFeatureAOIIndex());
                    msp.ArgumentProvider.SetArg("AOIFeatures", frm.GetSelectedFeatures());
                    CodeCell.AgileMap.Core.Envelope env = frm.GetSelectedEnvelope();
                    if (env != null)
                    {
                        selectedEnvelope = new CoordEnvelope(env.MinX, env.MaxX, env.MinY, env.MaxY);
                    }
                    else
                    {
                        selectedEnvelope = null;
                    }
                    return(true);
                }
                else
                {
                    selectedEnvelope = null;
                    return(false);
                }
            }
        }
示例#23
0
        /// <summary>
        /// 输入的可见光雪判识或云判识分别合成一个文件
        /// </summary>
        /// <param name="filenames"></param>
        /// <returns></returns>
        private IFileExtractResult ComposeVISSNW(string[] filenames, string identify)
        {
            List <RasterMaper> rms = new List <RasterMaper>();
            RasterProcessModel <Int16, Int16> rfr = null;
            IRasterDataProvider outRaster         = null;
            float resloution = 0.0f;

            try
            {
                for (int i = 0; i < filenames.Length; i++)
                {
                    IRasterDataProvider inRaster = GeoDataDriver.Open(filenames[i]) as IRasterDataProvider;
                    RasterMaper         rm       = new RasterMaper(inRaster, new int[] { 1 });
                    rms.Add(rm);
                    resloution = inRaster.ResolutionX;
                }
                string visSNWFile = GetFileName(new string[] { filenames[0] }, _subProductDef.ProductDef.Identify, identify, ".dat", null);
                outRaster = CreateOutRasterUnion(visSNWFile, enumDataType.Int16, rms.ToArray(), resloution);
                RasterMaper[] fileIns  = rms.ToArray();
                RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                rfr = new RasterProcessModel <Int16, Int16>();
                rfr.SetRaster(fileIns, fileOuts);
                rfr.RegisterCalcModel(new RasterCalcHandler <Int16, Int16>((rvInVistor, rvOutVistor, aoi) =>
                {
                    int dataLength  = rvOutVistor[0].RasterBandsData[0].Length;
                    int n           = rvInVistor.Count();
                    Int16[,] save   = new Int16[n, dataLength]; // 第一维是文件的顺序号,第二维是文件的数值
                    Int16[] sumData = new Int16[dataLength];
                    int j           = 0;                        //记录输入文件的序号,从0开始
                    //System.Windows.Forms.MessageBox.Show(Convert.ToString(n));
                    foreach (RasterVirtualVistor <Int16> rv in rvInVistor)
                    {
                        if (rv.RasterBandsData[0] == null)
                        {
                            continue;
                        }
                        for (int index = 0; index < dataLength; index++)
                        {
                            save[j, index] = rv.RasterBandsData[0][index];
                        }
                        j++;
                    }
                    //Int16[] sumData = new Int16[dataLength];
                    for (int m = 0; m < n; m++)                                    //文件号
                    {
                        for (int q = 0; q < dataLength; q++)                       //像元号
                        {
                            sumData[q] = Convert.ToInt16(sumData[q] + save[m, q]); //计算这些输文件的值和
                        }
                    }

                    for (int index = 0; index < dataLength; index++)
                    {
                        if (sumData[index] == 0)
                        {
                            rvOutVistor[0].RasterBandsData[0][index] = 0;
                        }
                        else
                        {
                            rvOutVistor[0].RasterBandsData[0][index] = 1;
                        }
                    }
                }));
                rfr.Excute();
                IFileExtractResult res = new FileExtractResult(_subProductDef.Identify, visSNWFile, true);
                res.SetDispaly(false);
                return(res);
            }
            finally
            {
                if (outRaster != null)
                {
                    outRaster.Dispose();
                }
                if (rms != null && rms.Count > 0)
                {
                    foreach (RasterMaper rm in rms)
                    {
                        if (rm.Raster != null)
                        {
                            rm.Raster.Dispose();
                        }
                    }
                }
            }
        }
示例#24
0
        private IExtractResult CompareSHPFile(string backWaterPath, FileExtractResult dayCountFile, Action <int, string> progressTracker)
        {
            string shpPrimaryField = null;

            Feature[] features = GetFeatures(backWaterPath, out shpPrimaryField);
            if (features == null || features.Length == 0)
            {
                return(null);
            }
            //矢量栅格化
            Dictionary <string, Color>  nameColors = new Dictionary <string, Color>();
            IRasterDataProvider         dataPrd    = GeoDataDriver.Open(backWaterPath) as IRasterDataProvider;
            IPixelFeatureMapper <Int16> result     = new MemPixelFeatureMapper <Int16>("FLOD", 1000, new Size(dataPrd.Width, dataPrd.Height), dataPrd.CoordEnvelope, dataPrd.SpatialRef);

            using (Bitmap bitmap = VectorsToBitmap(dataPrd, features, shpPrimaryField, out nameColors))
            {
                int[]      aoi;
                Color      color;
                string     name;
                List <int> items = new List <int>();
                foreach (Feature fea in features)
                {
                    name = fea.GetFieldValue(shpPrimaryField);
                    if (String.IsNullOrEmpty(name))
                    {
                        continue;
                    }
                    color = nameColors[name];
                    aoi   = GetAOIByFeature(bitmap, color);
                    if (aoi != null)
                    {
                        items.AddRange(aoi);
                    }
                }
                //分情况处理
                //无aoi区域
                if (items.Count == 0)
                {
                    ArgumentProvider            ap        = new ArgumentProvider(dataPrd, null);
                    RasterPixelsVisitor <Int16> rpVisitor = new RasterPixelsVisitor <Int16>(ap);
                    rpVisitor.VisitPixel(new int[] { 1 },
                                         (idx, values) =>
                    {
                        result.Put(idx, values[0]);
                    });
                }
                //有aoi区域
                else
                {
                    ArgumentProvider            ap        = new ArgumentProvider(dataPrd, null);
                    RasterPixelsVisitor <Int16> rpVisitor = new RasterPixelsVisitor <Int16>(ap);
                    rpVisitor.VisitPixel(new int[] { 1 },
                                         (idx, values) =>
                    {
                        result.Put(idx, values[0]);
                    });
                    Size      size    = new Size(dataPrd.Width, dataPrd.Height);
                    Rectangle aoiRect = AOIHelper.ComputeAOIRect(items.ToArray(), size);
                    rpVisitor.VisitPixel(aoiRect, items.ToArray(), new int[] { 1 },
                                         (idx, values) =>
                    {
                        if (values[0] == 0)
                        {
                            result.Put(idx, -2);
                        }
                    });
                }
            }
            return(result);
        }
示例#25
0
        private unsafe IRasterDataProvider GetDataProvider(IRasterDrawing drawing)
        {
            IRasterDataProvider prd = GeoDataDriver.Open(drawing.FileName) as IRasterDataProvider;

            return(prd);
        }
示例#26
0
        private string JuPinComputer(string CurrentFile, string HistoryFile, string savePath)
        {
            float resolution                      = 0.1f;
            List <RasterMaper>  rms               = new List <RasterMaper>();
            IRasterDataProvider outRaster         = null;
            RasterProcessModel <float, float> rfr = null;

            try
            {
                IRasterDataProvider cRaster = GeoDataDriver.Open(CurrentFile) as IRasterDataProvider;
                RasterMaper         rm1     = new RasterMaper(cRaster, new int[] { 1 });
                rms.Add(rm1);
                IRasterDataProvider hRaster = GeoDataDriver.Open(HistoryFile) as IRasterDataProvider;
                RasterMaper         rm2     = new RasterMaper(hRaster, new int[] { 1 });
                rms.Add(rm2);
                string reChars  = "";
                string addChars = "";
                if (Path.GetFileName(CurrentFile).Contains("MSWE"))
                {
                    reChars  = "MSWE";
                    addChars = "JPEA_MSWE";
                }
                if (Path.GetFileName(CurrentFile).Contains("MWSD"))
                {
                    reChars  = "MWSD";
                    addChars = "JPDA_MWSD";
                }
                string outfilename = savePath + "\\" + Path.GetFileName(HistoryFile).Replace(reChars, addChars);
                outRaster = CreateOutRaster(outfilename, enumDataType.Float, rms.ToArray(), resolution);

                //栅格数据映射
                RasterMaper[] fileIns  = rms.ToArray();
                RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                //创建处理模型
                rfr = new RasterProcessModel <float, float>();
                rfr.SetRaster(fileIns, fileOuts);

                rfr.RegisterCalcModel(new RasterCalcHandler <float, float>((rvInVistor, rvOutVistor, aoi) =>
                {
                    int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX;

                    for (int index = 0; index < dataLength; index++)
                    {
                        if (rvInVistor[0].RasterBandsData[0][index] == -999.0f)
                        {
                            rvOutVistor[0].RasterBandsData[0][index] = -999.0f; //考虑无效值
                        }
                        else
                        {
                            rvOutVistor[0].RasterBandsData[0][index] = rvInVistor[0].RasterBandsData[0][index] - rvInVistor[1].RasterBandsData[0][index];
                        }
                    }
                }));
                rfr.Excute();
                return(outfilename);
            }
            finally
            {
                foreach (RasterMaper rm in rms)
                {
                    rm.Raster.Dispose();
                }
                if (outRaster != null)
                {
                    outRaster.Dispose();
                }
            }
        }
示例#27
0
        private IExtractResult ComputeByCurrentRaster(IRasterDataProvider currPrd, Action <int, string> progressTracker)
        {
            currPrd = currPrd != null ? currPrd : _argumentProvider.DataProvider;
            if (currPrd == null)
            {
                return(null);
            }
            IBandNameRaster bandNameRaster    = _argumentProvider.DataProvider as IBandNameRaster;//
            int             VisibleCH         = TryGetBandNo(bandNameRaster, "RedBand");
            int             NearInfraredCH    = TryGetBandNo(bandNameRaster, "NirBand");
            int             FarInfrared11CH   = TryGetBandNo(bandNameRaster, "FarBand");
            double          VisibleZoom       = (double)_argumentProvider.GetArg("RedBand_Zoom");
            double          NearInfraredZoom  = (double)_argumentProvider.GetArg("NirBand_Zoom");
            double          FarInfrared11Zoom = (double)_argumentProvider.GetArg("FarBand_Zoom");
            bool            isAutoCloud       = (bool)_argumentProvider.GetArg("isAutoCloud");
            bool            isAppCloud        = (bool)_argumentProvider.GetArg("isAppCloud");

            if (VisibleCH == -1 || NearInfraredCH == -1 || (isAutoCloud && FarInfrared11CH == -1))
            {
                PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                return(null);
            }

            float pdiZoom      = (float)_argumentProvider.GetArg("PDIZoom");
            Int16 defCloudy    = (Int16)_argumentProvider.GetArg("defCloudy");
            Int16 defWater     = (Int16)_argumentProvider.GetArg("defWater");
            Int16 InvaildValue = (Int16)_argumentProvider.GetArg("InvaildValue");

            float NearInfraredCLMMin    = float.Parse(_argumentProvider.GetArg("NearInfraredCLMMin").ToString());
            float FarInfrared11CLMMax   = float.Parse(_argumentProvider.GetArg("FarInfrared11CLMMax").ToString());
            float FarInfrared11WaterMin = float.Parse(_argumentProvider.GetArg("FarInfrared11WaterMin").ToString());
            float NDVIWaterMax          = float.Parse(_argumentProvider.GetArg("NDVIWaterMax").ToString());

            int    cloudCH = (int)_argumentProvider.GetArg("CLMBand");
            string clmFile = GetClmFile(currPrd);

            float RegionExp1 = (float)_argumentProvider.GetArg("RegionExp1");
            float RegionExp2 = (float)_argumentProvider.GetArg("RegionExp2");

            DRTExpCoefficientCollection ExpCoefficient = _argumentProvider.GetArg("ExpCoefficient") as DRTExpCoefficientCollection;
            string EdgesFile = ExpCoefficient.EgdesFilename;
            int    bandNo    = TryGetBandNo(bandNameRaster, "DemBand");

            string[] aois        = _argumentProvider.GetArg("AOITemplate") as string[];
            string   aoiTemplate = (aois == null || aois.Length == 0) ? null : aois[0];

            //输入文件准备
            List <RasterMaper>  rms        = new List <RasterMaper>();
            IRasterDataProvider currRaster = null;
            IRasterDataProvider edgeRaster = null;
            IRasterDataProvider clmPrd     = null;

            try
            {
                currRaster = currPrd;
                if (currRaster.BandCount < VisibleCH || currRaster.BandCount < NearInfraredCH || (isAutoCloud && currRaster.BandCount < FarInfrared11CH))
                {
                    PrintInfo("请选择正确的数据进行垂直干旱指数计算。");
                    return(null);
                }
                RasterMaper rmCurr = new RasterMaper(currRaster, new int[] { VisibleCH, NearInfraredCH, FarInfrared11CH });
                rms.Add(rmCurr);

                bool isContainEdgesFile = false;
                if (!string.IsNullOrEmpty(EdgesFile) && File.Exists(EdgesFile))
                {
                    edgeRaster = RasterDataDriver.Open(EdgesFile) as IRasterDataProvider;
                    if (edgeRaster.BandCount < bandNo)
                    {
                        PrintInfo("请正确选择经验系数中的边界文件,波段数不足!");
                        return(null);
                    }
                    RasterMaper rmEdge = new RasterMaper(edgeRaster, new int[] { bandNo });
                    rms.Add(rmEdge);
                    isContainEdgesFile = true;
                }

                bool isContainClm = false;
                if (isAppCloud && !string.IsNullOrEmpty(clmFile) && File.Exists(clmFile))
                {
                    clmPrd = GeoDataDriver.Open(clmFile) as IRasterDataProvider;
                    if (clmPrd.BandCount < cloudCH)
                    {
                        PrintInfo("请选择正确的云数据进行计算,波段数不足!");
                        return(null);
                    }
                    RasterMaper clmRm = new RasterMaper(clmPrd, new int[] { cloudCH });
                    rms.Add(clmRm);
                    isContainClm = true;
                }
                float curNDVI = 0f;
                //输出文件准备(作为输入栅格并集处理)
                string outFileName = GetFileName(new string[] { currRaster.fileName }, _subProductDef.ProductDef.Identify, _identify, ".dat", null);
                using (IRasterDataProvider outRaster = CreateOutRaster(outFileName, rms.ToArray()))
                {
                    //栅格数据映射
                    RasterMaper[] fileIns  = rms.ToArray();
                    RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                    //创建处理模型
                    RasterProcessModel <Int16, Int16> rfr = null;
                    rfr = new RasterProcessModel <Int16, Int16>(progressTracker);
                    rfr.SetRaster(fileIns, fileOuts);
                    rfr.SetTemplateAOI(aoiTemplate);
                    DRTExpCoefficientItem item = null;
                    int demCode = -1;
                    rfr.RegisterCalcModel(new RasterCalcHandler <Int16, Int16>((rvInVistor, rvOutVistor, aoi) =>
                    {
                        if (rvInVistor[0] == null || rvInVistor[0].RasterBandsData[0] == null ||
                            (isContainEdgesFile && (rvInVistor[1] == null || rvInVistor[1].RasterBandsData[0] == null)) ||
                            (isContainClm && (rvInVistor[2 - (isContainEdgesFile ? 0 : 1)] == null || rvInVistor[2 - (isContainEdgesFile ? 0 : 1)].RasterBandsData[0] == null)))
                        {
                            return;
                        }
                        int dataLength = aoi == null || aoi.Length == 0 ? rvOutVistor[0].SizeY * rvOutVistor[0].SizeX : aoi.Length;
                        for (int i = 0; i < dataLength; i++)
                        {
                            int index               = aoi == null || aoi.Length == 0 ? i : aoi[i];
                            Int16 visiableValue     = rvInVistor[0].RasterBandsData[0][index];
                            Int16 nearInfraredValue = rvInVistor[0].RasterBandsData[1][index];
                            Int16 farInfraredVale   = rvInVistor[0].RasterBandsData[2][index];
                            if (isContainEdgesFile && rvInVistor[1].RasterBandsData[0] != null)
                            {
                                demCode = (int)rvInVistor[1].RasterBandsData[0][index];
                            }
                            else
                            {
                                demCode = -1;
                            }
                            curNDVI = GetNDVI(nearInfraredValue, visiableValue);
                            if (visiableValue == 0 && nearInfraredValue == 0)
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = InvaildValue;
                            }
                            else if (isContainClm && rvInVistor[2 - (isContainEdgesFile ? 0 : 1)].RasterBandsData[0][index] != 0)
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = defCloudy;
                            }
                            else if (isAutoCloud && (nearInfraredValue / NearInfraredZoom > NearInfraredCLMMin && farInfraredVale / FarInfrared11Zoom < FarInfrared11CLMMax))
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = defCloudy;
                            }
                            else
                            {
                                if (farInfraredVale / FarInfrared11Zoom > FarInfrared11WaterMin && curNDVI < NDVIWaterMax)
                                {
                                    rvOutVistor[0].RasterBandsData[0][index] = defWater;
                                }
                                else
                                {
                                    item = ExpCoefficient.GetExpItemByNum(demCode);
                                    if (item == null)
                                    {
                                        rvOutVistor[0].RasterBandsData[0][index] = (Int16)((visiableValue / VisibleZoom + RegionExp1 * nearInfraredValue / NearInfraredZoom) / Math.Sqrt(RegionExp2 * RegionExp2 + 1) * pdiZoom);
                                    }
                                    else
                                    {
                                        rvOutVistor[0].RasterBandsData[0][index] = (Int16)((visiableValue / VisibleZoom + item.APara * nearInfraredValue / NearInfraredZoom) / Math.Sqrt(item.BPara * item.BPara + 1) * pdiZoom);
                                    }
                                }
                            }
                        }
                    }));
                    //执行
                    rfr.Excute();
                    IFileExtractResult pdiFile = new FileExtractResult(_subProductDef.Identify, outFileName, true);
                    pdiFile.SetDispaly(false);
                    return(pdiFile);
                }
            }
            finally
            {
                if (clmPrd != null)
                {
                    clmPrd.Dispose();
                }
                if (edgeRaster != null)
                {
                    edgeRaster.Dispose();
                }
            }
        }
        public override IExtractResult Make(Action <int, string> progressTracker)
        {
            if (_argumentProvider == null || _argumentProvider.GetArg("BPCDFile") == null || _argumentProvider.GetArg("CovertDegreeRegion") == null)
            {
                return(null);
            }
            string bpcdFile = _argumentProvider.GetArg("BPCDFile").ToString();

            if (string.IsNullOrEmpty(bpcdFile) || !File.Exists(bpcdFile))
            {
                return(null);
            }
            List <string> covertDegreeRegions = _argumentProvider.GetArg("CovertDegreeRegion") as List <string>;

            if (covertDegreeRegions == null || covertDegreeRegions.Count == 0)
            {
                return(null);
            }
            if (_argumentProvider.GetArg("AlgorithmName").ToString() == "BCCA")
            {
                string clmFName = null;
                if (_argumentProvider.GetArg("CLMFile") != null)
                {
                    clmFName = _argumentProvider.GetArg("CLMFile").ToString();
                }
                if (!string.IsNullOrEmpty(clmFName) && File.Exists(clmFName))
                {
                    _isComputCloudArea = true;
                }
                IRasterDataProvider dataProvider  = null;
                IRasterDataProvider cloudProvider = null;
                List <string[]>     resultList    = new List <string[]>();
                try
                {
                    dataProvider = GeoDataDriver.Open(bpcdFile) as IRasterDataProvider;
                    //计算云覆盖面积
                    if (_isComputCloudArea)
                    {
                        cloudProvider = GeoDataDriver.Open(clmFName) as IRasterDataProvider;
                    }
                    //整个区域
                    List <string[]> statresult = StaticAreaByRegions(covertDegreeRegions, cloudProvider, dataProvider, null, "整个湖区");
                    if (statresult != null)
                    {
                        resultList.AddRange(statresult);
                    }
                    //获取分区AOI
                    Dictionary <string, int[]> aois = GetAOIForRaster(dataProvider);
                    if (aois != null && aois.Count > 0)
                    {
                        foreach (string region in aois.Keys)
                        {
                            List <string[]> result = StaticAreaByRegions(covertDegreeRegions, cloudProvider, dataProvider, aois[region], region);
                            if (result != null)
                            {
                                resultList.AddRange(result);
                            }
                        }
                    }
                    if (resultList != null && resultList.Count != 0)
                    {
                        float          resolution = dataProvider.ResolutionX;
                        string         title      = "统计日期:" + DateTime.Now.ToShortDateString();
                        RasterIdentify id         = new RasterIdentify(bpcdFile);
                        if (id.OrbitDateTime != null)
                        {
                            title += "    轨道日期:" + id.OrbitDateTime.ToShortDateString();
                        }
                        string[]    columns  = new string[] { "区域名称", "覆盖度范围", "总覆盖面积(平方公里)", "实际覆盖面积(平方公里)", "云覆盖面积(平方公里)" };
                        IStatResult result   = new StatResult(title, columns, resultList.ToArray());
                        string      filename = StatResultToFile(new string[] { bpcdFile }, result, "BAG", "BCCA", "蓝藻按覆盖度统计面积", null, 1, false, 0);
                        return(new FileExtractResult("BCCA", filename));
                    }
                }
                finally
                {
                    if (cloudProvider != null)
                    {
                        cloudProvider.Dispose();
                    }
                    if (dataProvider != null)
                    {
                        dataProvider.Dispose();
                    }
                }
            }
            return(null);
        }
示例#29
0
        private IRasterDataProvider GetLocationRaster()
        {
            string srcFilename = @"D:\mas数据\EOS\TERRA_2012_03_16_02_56_GZ.MOD03.hdf";

            return(GeoDataDriver.Open(srcFilename) as IRasterDataProvider);
        }
示例#30
0
        private IRasterDataProvider GetRasterDataProviderNOAA18()
        {
            string fname = @"E:\data\dst\NOAA18_AVHRR_CHINA_L1_20090806_N3_1000M_PRJ_Whole_Clip.LDF";

            return(GeoDataDriver.Open(fname) as IRasterDataProvider);
        }