예제 #1
0
        public override IExtractResult Make(Action <int, string> progressTracker, IContextMessage contextMessage)
        {
            _contextMessage = contextMessage;
            if (_argumentProvider == null)
            {
                return(null);
            }
            if (_argumentProvider.GetArg("AlgorithmName") == null)
            {
                PrintInfo("参数\"AlgorithmName\"为空。");
                return(null);
            }
            string algorith = _argumentProvider.GetArg("AlgorithmName").ToString();

            if (algorith != "ANMI")
            {
                PrintInfo("指定的算法\"" + algorith + "\"没有实现。");
                return(null);
            }
            if (_argumentProvider.GetArg("NDVIFile") == null)
            {
                PrintInfo("请选择植被指数数据。");
                return(null);
            }
            string ndvi = _argumentProvider.GetArg("NDVIFile").ToString();

            if (!File.Exists(ndvi))
            {
                PrintInfo("所选择的数据:\"" + ndvi + "\"不存在。");
                return(null);
            }
            if (_argumentProvider.GetArg("NdviCH") == null)
            {
                PrintInfo("参数\"NdviCH\"为空。");
                return(null);
            }
            int ndviCh = (int)_argumentProvider.GetArg("NdviCH");

            if (_argumentProvider.GetArg("NDVIAvgFile") == null)
            {
                PrintInfo("请选择植被指数年均值数据。");
                return(null);
            }
            string avg = _argumentProvider.GetArg("NDVIAvgFile").ToString();

            if (!File.Exists(avg))
            {
                PrintInfo("所选择的数据:\"" + avg + "\"不存在。");
                return(null);
            }
            if (_argumentProvider.GetArg("NdviAvgCH") == null)
            {
                PrintInfo("参数\"NdviAvgCH\"为空。");
                return(null);
            }
            int avgCH = (int)_argumentProvider.GetArg("NdviAvgCH");

            if (ndviCh < 1 || avgCH < 1)
            {
                PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                return(null);
            }

            //Create virtualProvider
            Dictionary <string, FilePrdMap> filePrdMap = new Dictionary <string, FilePrdMap>();

            filePrdMap.Add("NDVIFile", new FilePrdMap(ndvi, 1000, new VaildPra(Int16.MinValue, Int16.MaxValue), new int[] { ndviCh }));
            filePrdMap.Add("NDVIAvgFile", new FilePrdMap(avg, 1000, new VaildPra(Int16.MinValue, Int16.MaxValue), new int[] { avgCH }));

            //为防止用户选择的波段超出数据波段的界限
            if (filePrdMap["NDVIFile"].BandCount < ndviCh || filePrdMap["NDVIAvgFile"].BandCount < avgCH)
            {
                PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                return(null);
            }

            ITryCreateVirtualPrd       tryVPrd = new TryCreateVirtualPrdByMultiFile();
            IVirtualRasterDataProvider prd     = tryVPrd.CreateVirtualRasterPRD(ref filePrdMap);

            if (prd == null)
            {
                throw new Exception("数据间无相交部分,无法创建虚拟数据提供者!");
            }

            IRasterPixelsVisitor <Int16> visitor = new RasterPixelsVisitor <Int16>(new ArgumentProvider(prd, null));
            IPixelFeatureMapper <Int16>  result  = new MemPixelFeatureMapper <Int16>("ANMI", prd.Width * prd.Height, new System.Drawing.Size(prd.Width, prd.Height), prd.CoordEnvelope, prd.SpatialRef);

            visitor.VisitPixel(new int[] { filePrdMap["NDVIFile"].StartBand,
                                           filePrdMap["NDVIAvgFile"].StartBand },
                               (idx, values) =>
            {
                result.Put(idx, (Int16)(values[0] - values[1]));
            }
                               );
            return(result);
        }
예제 #2
0
        public static bool DoElevationCorrections(TVDIUCArgs ucArgs, ref string error)
        {
            if (string.IsNullOrEmpty(ucArgs.LSTFile) || string.IsNullOrEmpty(ucArgs.DEMFile) || ucArgs.TVDIParas == null || ucArgs.TVDIParas.LstFile == null)
            {
                error = "陆表高温高程订正所需数据或参数设置不全.";
                return(false);
            }

            Dictionary <string, FilePrdMap> filePrdMap = new Dictionary <string, FilePrdMap>();

            filePrdMap.Add("LSTFile", new FilePrdMap(ucArgs.LSTFile, ucArgs.TVDIParas.LstFile.Zoom, new VaildPra(ucArgs.TVDIParas.LstFile.Min, ucArgs.TVDIParas.LstFile.Max), new int[] { ucArgs.TVDIParas.LstFile.Band }));
            filePrdMap.Add("DemFile", new FilePrdMap(ucArgs.DEMFile, 1, new VaildPra(float.MinValue, float.MaxValue), new int[] { 1 }));

            ITryCreateVirtualPrd       tryVPrd = new TryCreateVirtualPrdByMultiFile();
            IVirtualRasterDataProvider vrd     = null;

            IInterestedRaster <float> iir = null;

            try
            {
                vrd = tryVPrd.CreateVirtualRasterPRD(ref filePrdMap);
                if (vrd == null)
                {
                    throw new Exception("数据间无相交部分,无法创建虚拟数据提供者!");
                }

                ArgumentProvider            ap        = new ArgumentProvider(vrd, null);
                RasterPixelsVisitor <float> rpVisitor = new RasterPixelsVisitor <float>(ap);
                IPixelFeatureMapper <float> _result   = new MemPixelFeatureMapper <float>("0LEC", 1000, new Size(vrd.Width, vrd.Height), vrd.CoordEnvelope, vrd.SpatialRef);
                ArgumentItem ai = ucArgs.TVDIParas.LstFile;
                rpVisitor.VisitPixel(new int[] { filePrdMap["LSTFile"].StartBand,
                                                 filePrdMap["DemFile"].StartBand },
                                     (index, values) =>
                {
                    if (values[1] == -9999)
                    {
                        _result.Put(index, 9999);    //海洋
                    }
                    else if (values[1] == -9000)
                    {
                        _result.Put(index, 9000);    //非中国区域陆地
                    }
                    else if (values[1] >= 6000)
                    {
                        _result.Put(index, 0);     //6000之内的LST数据
                    }
                    else if (values[0] == ucArgs.TVDIParas.LstFile.Cloudy)
                    {
                        _result.Put(index, 9998);     //云区
                    }
                    else if (values[0] == 12)
                    {
                        _result.Put(index, 9997);    //无数据区域
                    }
                    else if (values[0] == 0)
                    {
                        _result.Put(index, 0);
                    }
                    else if (values[1] == 0)
                    {
                        _result.Put(index, 0);
                    }
                    else
                    {
                        _result.Put(index, (float)(Math.Round((values[0] - 273f + 0.006f * values[1]) * ai.Zoom, 0)));
                    }
                });
                iir = new InterestedRaster <float>(CreateRID(ucArgs.LSTFile), new Size(vrd.Width, vrd.Height), vrd.CoordEnvelope, vrd.SpatialRef);
                iir.Put(_result);
                ucArgs.ECLstFile = iir.FileName;
                return(true);
            }
            finally
            {
                if (iir != null)
                {
                    iir.Dispose();
                }
                vrd.Dispose();
            }
        }
예제 #3
0
        private IExtractResult UHPIAlgorithmCompute(Action <int, string> progressTracker)
        {
            MemPixelFeatureMapper <UInt16> resultTemp = null;
            int    UHEBandCH   = (int)_argumentProvider.GetArg("UHEBand");
            int    NormalLevel = (int)_argumentProvider.GetArg("NormalLevel");
            int    HILevel     = (int)_argumentProvider.GetArg("HILevel");
            double UHEBandZoom = (double)_argumentProvider.GetArg("UHEBand_Zoom");

            UInt16[] nanValues   = GetNanValues("CloudyValue");
            UInt16[] waterValues = GetNanValues("WaterValue");

            string[] files = null;
            Dictionary <string, string[]> pathDic = _argumentProvider.GetArg("FileSelectType") as Dictionary <string, string[]>;

            if (pathDic == null || pathDic.Count == 0)
            {
                PrintInfo("请点击\"确定\"按钮,以确定文件参数设置完毕!");
                return(null);
            }
            if (pathDic.Keys.Contains("DirectoryPath")) //选择局地文件夹路径
            {
                files = GetFiles(pathDic["DirectoryPath"][0]);
            }
            else if (pathDic.Keys.Contains("FileNames")) //选择多个文件进行计算
            {
                files = pathDic["FileNames"];
            }
            if (files == null || files.Length == 0)
            {
                PrintInfo("待计算的数据文件不存在,请检查路径或文件设置!");
                return(null);
            }
            SortedDictionary <float, float> UHERegions = _argumentProvider.GetArg("LevelRegion") as SortedDictionary <float, float>;

            if (UHERegions == null || UHERegions.Count == 0 || UHERegions.Count != HILevel)
            {
                return(null);
            }
            List <UInt16> hiLevelList = new List <ushort>();

            for (int i = NormalLevel, j = 0; j < HILevel; i--, j++)
            {
                hiLevelList.Add((UInt16)i);
            }
            hiLevelList.Sort();
            Dictionary <string, StatInfo> result = new Dictionary <string, StatInfo>();
            float step       = 80 / files.Length;
            int   stepLength = 0;

            foreach (string file in files)
            {
                if (progressTracker != null)
                {
                    progressTracker.Invoke((int)Math.Floor(step * stepLength), "正在计算比例指数,请稍后...");
                }
                stepLength++;
                result.Add(file, CalcUPHIByOneFile(file, UHEBandCH, UHERegions, hiLevelList.ToArray()));
            }
            if (result.Count != 0)
            {
                IExtractResultArray array = new ExtractResultArray("UHE");
                if (progressTracker != null)
                {
                    progressTracker.Invoke(90, "正在生成比例指数统计结果,请稍后...");
                }
                array.Add(StateUHPI(NormalLevel, files, result) as IFileExtractResult);
                if (progressTracker != null)
                {
                    progressTracker.Invoke(95, "正在生成热岛面积统计结果,请稍后...");
                }
                array.Add(StateAreaCol(NormalLevel, files, result, HILevel) as IFileExtractResult);
                return(array);
            }
            return(null);
        }
예제 #4
0
        private IPixelFeatureMapper <float> CreatPixelCoverRate(IPixelFeatureMapper <float> ndviResult)
        {
            if (ndviResult == null)
            {
                return(null);
            }
            //生成NDVI结果文件
            IRasterDataProvider       ndviDataProvider = null;
            IInterestedRaster <float> iir = null;

            try
            {
                RasterIdentify id = new RasterIdentify();
                id.ThemeIdentify      = "CMA";
                id.ProductIdentify    = "BAG";
                id.SubProductIdentify = "BPCD";
                id.Sensor             = _argumentProvider.DataProvider.DataIdentify.Sensor;
                id.Satellite          = _argumentProvider.DataProvider.DataIdentify.Satellite;
                id.OrbitDateTime      = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0, 0));
                id.GenerateDateTime   = DateTime.Now;
                iir = new InterestedRaster <float>(id, new Size(_argumentProvider.DataProvider.Width, _argumentProvider.DataProvider.Height), _argumentProvider.DataProvider.CoordEnvelope.Clone());
                iir.Put(ndviResult);
                ndviDataProvider = iir.HostDataProvider;
                double dst;


                dst = MaxNDVI - MinNDVI;
                //判断是否使用端元值计算
                NDVISettingItem[] settings = _argumentProvider.GetArg("NDVISetting") as NDVISettingItem[];
                if (settings != null)
                {
                    ResetArgNDVIMaxMin(settings, ref MinNDVI, ref dst);
                }
                IPixelFeatureMapper <float> memresult = new MemPixelFeatureMapper <float>("BPCD", 1000, new Size(ndviDataProvider.Width, ndviDataProvider.Height), ndviDataProvider.CoordEnvelope, ndviDataProvider.SpatialRef);
                ArgumentProvider            ap        = new ArgumentProvider(ndviDataProvider, null);
                RasterPixelsVisitor <float> visitor   = new RasterPixelsVisitor <float>(ap);
                visitor.VisitPixel(new int[] { 1 }, (index, values) =>
                {
                    if (values[0] == -9999f)
                    {
                        memresult.Put(index, -9999);
                    }
                    else if (dst == 0)
                    {
                        memresult.Put(index, -9999);
                    }
                    else
                    {
                        memresult.Put(index, (float)((values[0] - MinNDVI) / dst));
                    }
                });
                iir.Dispose();
                return(memresult);
            }
            finally
            {
                if (ndviDataProvider != null)
                {
                    ndviDataProvider.Dispose();
                }
                if (File.Exists(iir.FileName))
                {
                    File.Delete(iir.FileName);
                }
            }
        }
예제 #5
0
        private IExtractResult FIRFMack(Action <int, string> progressTracker)
        {
            IBandNameRaster bandNameRaster   = _argumentProvider.DataProvider as IBandNameRaster;
            int             NearInfrared     = TryGetBandNo(bandNameRaster, "NearInfrared");
            int             CoverageBand     = (int)_argumentProvider.GetArg("CoverageBand");
            double          NearInfraredZoom = (double)_argumentProvider.GetArg("NearInfrared_Zoom");
            double          CoverageZoom     = (double)_argumentProvider.GetArg("CoverageBand_Zoom");
            float           NearInfraredMax  = (float)_argumentProvider.GetArg("NearInfraredMax");
            float           CoverageMin      = (float)_argumentProvider.GetArg("CoverageMin");
            float           FIRLZoom         = (float)_argumentProvider.GetArg("FIRFZoom");

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

            string coverageFile = _argumentProvider.GetArg("coverageFile") == null ? null : _argumentProvider.GetArg("coverageFile").ToString();

            if (string.IsNullOrEmpty(coverageFile))
            {
                PrintInfo("请设置背景农田百分比数据!");
                return(null);
            }

            float maxAvgValue;
            float minAvgValue;

            string[] nearInfValues = _argumentProvider.GetArg("NearInfraredValues") as string[];
            if (nearInfValues == null || nearInfValues.Count() != 2)
            {
                return(null);
            }
            if (!float.TryParse(nearInfValues[0], out maxAvgValue) || !float.TryParse(nearInfValues[1], out minAvgValue))
            {
                return(null);
            }
            if (maxAvgValue == minAvgValue)
            {
                return(null);
            }
            float dltValue                  = maxAvgValue - minAvgValue;
            List <RasterMaper>  rms         = new List <RasterMaper>();
            IRasterDataProvider curPrd      = _argumentProvider.DataProvider;
            IRasterDataProvider coveragePrd = null;

            try
            {
                RasterMaper nearRm = new RasterMaper(curPrd, new int[] { NearInfrared });
                rms.Add(nearRm);

                coveragePrd = RasterDataDriver.Open(coverageFile) as IRasterDataProvider;
                if (coveragePrd.BandCount < CoverageBand)
                {
                    PrintInfo("请选择正确的农田百分比数据文件通道值!");
                    return(null);
                }
                RasterMaper coverageRm = new RasterMaper(coveragePrd, new int[] { CoverageBand });
                rms.Add(coverageRm);

                string                      outFileName = GetFileName(new string[] { curPrd.fileName }, _subProductDef.ProductDef.Identify, _identify, ".dat", null);
                IPixelIndexMapper           result      = null;
                IPixelFeatureMapper <Int16> resultTag   = null;
                int   totalDatalength = 0;
                float tempValue       = 0;
                using (IRasterDataProvider outRaster = CreateOutRaster(outFileName, rms.ToArray()))
                {
                    result = PixelIndexMapperFactory.CreatePixelIndexMapper("FIR", outRaster.Width, outRaster.Height, outRaster.CoordEnvelope, outRaster.SpatialRef);
                    if (this.Tag == null || (this.Tag as MemPixelFeatureMapper <Int16>) == null)
                    {
                        resultTag = new MemPixelFeatureMapper <Int16>("FIFLT", 1000, new Size(outRaster.Width, outRaster.Height), outRaster.CoordEnvelope, outRaster.SpatialRef);
                    }
                    else
                    {
                        resultTag = this.Tag as MemPixelFeatureMapper <Int16>;
                    }
                    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.SetFeatureAOI(_argumentProvider.AOIs);
                    rfr.RegisterCalcModel(new RasterCalcHandlerFun <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)
                        {
                            totalDatalength += dataLength;
                            return(false);
                        }
                        if (_argumentProvider.AOIs == null)
                        {
                            for (int index = 0; index < dataLength; index++)
                            {
                                if (IsFirA(rvInVistor, index, NearInfraredZoom, NearInfraredMax))
                                {
                                    result.Put(totalDatalength + index);

                                    tempValue = (maxAvgValue - rvInVistor[0].RasterBandsData[0][index]) / dltValue;
                                    if (tempValue < rvInVistor[1].RasterBandsData[0][index] / CoverageZoom)
                                    {
                                        resultTag.Put(totalDatalength + index, tempValue < 0 ? (Int16)0 : (tempValue > 1 ? (Int16)(FIRLZoom) : (Int16)(tempValue * FIRLZoom)));
                                    }
                                    else
                                    {
                                        resultTag.Put(totalDatalength + index, (Int16)(rvInVistor[1].RasterBandsData[0][index] / CoverageZoom * FIRLZoom));
                                    }
                                }
                            }
                        }
                        else if (_argumentProvider.AOIs != null && aoi != null && aoi.Length != 0)
                        {
                            int indexFromAOI = 0;
                            for (int i = 0; i < aoi.Length; i++)
                            {
                                indexFromAOI = aoi[i];
                                if (IsFirA(rvInVistor, indexFromAOI, NearInfraredZoom, NearInfraredMax))
                                {
                                    result.Put(totalDatalength + indexFromAOI);

                                    tempValue = (maxAvgValue - rvInVistor[0].RasterBandsData[0][aoi[i]]) / dltValue;
                                    if (tempValue < rvInVistor[1].RasterBandsData[0][aoi[i]] / CoverageZoom)
                                    {
                                        resultTag.Put(totalDatalength + indexFromAOI, tempValue < 0 ? (Int16)0 : (tempValue > 1 ? (Int16)(FIRLZoom) : (Int16)(tempValue * FIRLZoom)));
                                    }
                                    else
                                    {
                                        resultTag.Put(totalDatalength + indexFromAOI, (Int16)(rvInVistor[1].RasterBandsData[0][aoi[i]] / CoverageZoom * FIRLZoom));
                                    }
                                }
                            }
                        }
                        totalDatalength += dataLength;
                        return(false);
                    }));
                    //执行
                    rfr.Excute();
                    this.Tag = resultTag;
                    return(result);
                }
            }
            finally
            {
                if (coveragePrd != null)
                {
                    coveragePrd.Dispose();
                }
            }
        }