예제 #1
0
        public IExtractResult GetCloudBAG()
        {
            double niBandRoom = (double)_argumentProvider.GetArg("NearInfrared_Zoom");
            bool   needcloud  = (bool)_argumentProvider.GetArg("isAppCloud");

            UCSetNearTool uccontrl = _argumentProvider.GetArg("UCSetNearTool") as UCSetNearTool;

            if (uccontrl.ckbone.Checked)
            {
                uccontrl.btnGetAOIIndex(null, null);
            }
            string cloudfile    = GetClmFile(_argumentProvider.DataProvider);
            bool   isexistcloud = File.Exists(cloudfile);

            MinNear = double.Parse(uccontrl.txtnearmin.Text) * 100;//放大调节 跟界面参数设置有关
            IRasterDataProvider prd = _argumentProvider.DataProvider;

            if (prd == null)
            {
                PrintInfo("未能获取当前影像数据。");
                return(null);
            }
            IBandNameRaster bandNameRaster = prd as IBandNameRaster;
            int             niBandNo       = TryGetBandNo(bandNameRaster, "NearInfrared");

            if (niBandNo == -1 || niBandRoom == -1)
            {
                PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                return(null);
            }
            List <RasterMaper> rms = new List <RasterMaper>();

            rms.Add(new RasterMaper(_argumentProvider.DataProvider, new int[] { niBandNo }));
            if (isexistcloud)
            {
                rms.Add(new RasterMaper(GeoDataDriver.Open(cloudfile) as IRasterDataProvider, new int[] { 1 }));
            }
            RasterIdentify rid = new RasterIdentify(_argumentProvider.DataProvider);

            rid.ProductIdentify    = "BAG";
            rid.SubProductIdentify = "DBLV";
            string outfile = rid.ToPrjWksFullFileName(".dat");
            IRasterDataProvider outRaster = null;

            outRaster = CreateOutRaster(outfile, rms.ToArray(), enumDataType.Int16);
            IPixelIndexMapper result = PixelIndexMapperFactory.CreatePixelIndexMapper("BAG", _argumentProvider.DataProvider.Width, _argumentProvider.DataProvider.Height,
                                                                                      _argumentProvider.DataProvider.CoordEnvelope, _argumentProvider.DataProvider.SpatialRef);

            try
            {
                RasterProcessModel <Int16, Int16> rfr = null;
                RasterMaper[] fileIns  = rms.ToArray();
                RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                rfr = new RasterProcessModel <Int16, Int16>();
                int totalindex = 0;
                rfr.SetRaster(fileIns, fileOuts);
                rfr.SetArgumentProviderAOI(_argumentProvider.AOI);
                rfr.RegisterCalcModel(new RasterCalcHandlerFun <Int16, Int16>((rvInVistor, rvOutVistor, aoi) =>
                {
                    if (rvInVistor[0].RasterBandsData[0] != null && rvInVistor[1].RasterBandsData[0] != null)
                    {
                        int dataLength = rvInVistor[0].SizeY * rvInVistor[0].SizeX;
                        for (int i = 0; i < aoi.Length; i++)
                        {
                            int index = aoi[i];
                            if (rvInVistor[0].RasterBandsData[0][index] / niBandRoom > MinNear)
                            {
                                if (needcloud)
                                {
                                    if (!isexistcloud)
                                    {
                                        result.Put(totalindex + index);
                                        continue;
                                    }
                                    else if (rvInVistor[1].RasterBandsData[0][index] == 0)//非云
                                    {
                                        result.Put(totalindex + index);
                                    }
                                    else
                                    {
                                        //rvOutVistor[0].RasterBandsData[0][aoi[i]] = -9999;// 云 这里是否需要配置一下?
                                    }
                                }
                                else
                                {
                                    result.Put(totalindex + index);
                                    //rvOutVistor[0].RasterBandsData[0][aoi[i]] = 1;
                                }
                            }
                            else
                            {
                            }
                        }
                        totalindex = totalindex += dataLength;
                    }

                    return(false);
                }));
                rfr.Excute();
                return(result);
            }
            catch (Exception ex)
            {
                return(null);
            }
            finally
            {
                outRaster.Dispose();
            }
        }
예제 #2
0
        public IExtractResult GetBAG()
        {
            double        visiBandRoom = (double)_argumentProvider.GetArg("Visible_Zoom");
            double        niBandRoom   = (double)_argumentProvider.GetArg("NearInfrared_Zoom");
            bool          needcloud    = (bool)_argumentProvider.GetArg("isAppCloud");
            UCSetNearTool uccontrl     = _argumentProvider.GetArg("UCSetNearTool") as UCSetNearTool;

            if (uccontrl.ckbone.Checked)
            {
                uccontrl.btnGetAOIIndex(null, null);
            }
            MinNear = double.Parse(uccontrl.txtnearmin.Text) * 100;//放大调节 跟界面参数设置有关
            IRasterDataProvider prd = _argumentProvider.DataProvider;

            if (prd == null)
            {
                PrintInfo("未能获取当前影像数据。");
                return(null);
            }
            IBandNameRaster bandNameRaster = prd as IBandNameRaster;
            int             visiBandNo     = TryGetBandNo(bandNameRaster, "Visible");
            int             niBandNo       = TryGetBandNo(bandNameRaster, "NearInfrared");
            int             shortBandNo    = TryGetBandNo(bandNameRaster, "ShortInfrared");

            if (visiBandNo == -1 || niBandNo == -1 || visiBandRoom == -1 || niBandRoom == -1)
            {
                PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                return(null);
            }
            string express      = string.Format("band{0}/{1}f" + " >= " + MinNear, niBandNo, niBandRoom);
            string cloudexpress = GetCloudExpress();

            if (needcloud)
            {
                express = string.Format("{0} && ({1})", express, cloudexpress);
            }
            int[] bandNos = new int[] { visiBandNo, niBandNo, shortBandNo };
            IThresholdExtracter <UInt16> extracter = new SimpleThresholdExtracter <UInt16>();

            extracter.Reset(_argumentProvider, bandNos, express);
            int width  = prd.Width;
            int height = prd.Height;
            IPixelIndexMapper memResult = PixelIndexMapperFactory.CreatePixelIndexMapper("BAG", width, height, prd.CoordEnvelope, prd.SpatialRef);

            extracter.Extract(memResult);

            memResult.Tag = new BagFeatureCollection("蓝藻辅助信息", GetDisplayInfo(memResult, visiBandNo, niBandNo));
            //计算NDVI文件
            IPixelFeatureMapper <float> ndvi = null;

            try
            {
                ndvi = ComputeNDVIResult(_argumentProvider.DataProvider, memResult, visiBandNo, niBandNo);
                IExtractResultBase bPCDResult = CreatPixelCoverRate(ndvi);
                ExtractResultArray results    = new ExtractResultArray("BAG_BINS");
                results.Add(memResult);
                //results.Add(ndvi);
                results.Add(bPCDResult);
                return(results);
            }
            finally
            {
                if (ndvi != null)
                {
                    ndvi.Dispose();
                }
            }
        }