Esempio n. 1
0
        private IExtractResult DemAlgorithm()
        {
            int    DNTBandCH   = (int)_curArguments.GetArg("DNTBand");
            double DNTZoom     = (float)_curArguments.GetArg("DNTZoom");
            float  DNTVaildMin = (float)_curArguments.GetArg("DNTVaildMin");
            float  DNTVaildMax = (float)_curArguments.GetArg("DNTVaildMax");

            Int16 DemMin     = (Int16)_curArguments.GetArg("DemMin");
            float DemCorrect = (float)_curArguments.GetArg("DemCorrect");

            double SWIZoom = (float)_curArguments.GetArg("SWIZoom");
            DRTExpCoefficientCollection ExpCoefficient = _curArguments.GetArg("ExpCoefficient") as DRTExpCoefficientCollection;
            string errorStr = null;

            if (DNTBandCH == -1 || _curArguments.GetArg("DNTFile") == null || _curArguments.GetArg("DemFile") == null || ExpCoefficient == null)
            {
                errorStr = "SWI生产所用文件或通道未设置完全,请检查!";
                return(null);
            }
            string DNTFile = _curArguments.GetArg("DNTFile").ToString();
            string DemFile = _curArguments.GetArg("DemFile").ToString();

            if (string.IsNullOrEmpty(ExpCoefficient.EgdesFilename) || !File.Exists(ExpCoefficient.EgdesFilename))
            {
                string fileanme = AppDomain.CurrentDomain.BaseDirectory + @"\SystemData\RasterTemplate\\China_Province.dat";
                if (File.Exists(fileanme))
                {
                    ExpCoefficient.EgdesFilename = fileanme;
                }
                else
                {
                    errorStr = "SWI生产所用的经验系数边界文件不存在,请检查!";
                    return(null);
                }
            }
            ;
            string EdgesFile = ExpCoefficient.EgdesFilename;

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

            filePrdMap.Add("DNTFile", new FilePrdMap(DNTFile, DNTZoom, new VaildPra(DNTVaildMin, DNTVaildMax), new int[] { DNTBandCH }));
            filePrdMap.Add("DemFile", new FilePrdMap(DemFile, 1, new VaildPra(DemMin, float.MaxValue), new int[] { 1 }));
            filePrdMap.Add("EdgesFile", new FilePrdMap(EdgesFile, 1, new VaildPra(float.MinValue, float.MaxValue), new int[] { 1 }));

            ITryCreateVirtualPrd       tryVPrd = new TryCreateVirtualPrdByMultiFile();
            DRTExpCoefficientItem      item    = null;
            IVirtualRasterDataProvider vrd     = 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 <Int16> result    = new MemPixelFeatureMapper <Int16>("0SWI", 1000, new Size(vrd.Width, vrd.Height), vrd.CoordEnvelope, vrd.SpatialRef);
                double swiTemp = 0f;
                rpVisitor.VisitPixel(new int[] { filePrdMap["DNTFile"].StartBand,
                                                 filePrdMap["DemFile"].StartBand,
                                                 filePrdMap["EdgesFile"].StartBand },
                                     (index, values) =>
                {
                    if (values[0] < filePrdMap["DNTFile"].VaildValue.Min || values[0] > filePrdMap["DNTFile"].VaildValue.Max)
                    {
                        result.Put(index, 0);
                    }
                    else
                    {
                        item = ExpCoefficient.GetExpItemByNum((int)values[2]);
                        if (item == null)
                        {
                            result.Put(index, 0);
                        }
                        else
                        {
                            //计算SWI
                            swiTemp = item.APara * values[0] + item.BPara + item.CPara;
                            if (values[1] > filePrdMap["DemFile"].VaildValue.Min)
                            {
                                swiTemp += DemCorrect;
                            }
                            result.Put(index, (Int16)(swiTemp * SWIZoom));
                        }
                    }
                });
                return(result);
            }
            finally
            {
                if (vrd != null)
                {
                    vrd.Dispose();
                }
            }
        }
        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 != "0AVG")
            {
                PrintInfo("指定的算法\"" + algorith + "\"没有实现。");
                return(null);
            }
            string[] fileNames = GetStringArray("SelectedPrimaryFiles");
            if (fileNames == null || fileNames.Count() == 0)
            {
                PrintInfo("请选择参与平均值合成的数据。");
                return(null);
            }
            foreach (string f in fileNames)
            {
                if (!File.Exists(f))
                {
                    PrintInfo("所选择的数据:\"" + f + "\"不存在。");
                    return(null);
                }
            }

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

            for (int i = 0; i < fileNames.Length; i++)
            {
                //为防止用户选择的波段超出数据波段的界限
                FilePrdMap map = new FilePrdMap(fileNames[i], 1, new VaildPra(float.MinValue, float.MaxValue), new int[] { 1 });
                if (map.BandCount < 1)
                {
                    PrintInfo("请选择正确的数据进行平均值合成。");
                    return(null);
                }
                filePrdMap.Add("ndviFile" + i.ToString(), map);
            }

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

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

            List <int> bands = new List <int>();

            for (int i = 0; i < fileNames.Length; i++)
            {
                bands.Add(filePrdMap["ndviFile" + i.ToString()].StartBand);
            }
            IPixelFeatureMapper <Int16> result = new MemPixelFeatureMapper <Int16>("0AVG", prd.Width * prd.Height, new Size(prd.Width, prd.Height), prd.CoordEnvelope, prd.SpatialRef);

            visitor.VisitPixel(bands.ToArray(),
                               (idx, values) =>
            {
                result.Put(idx, (Int16)(values.Average(
                                            (value) =>
                {
                    return(value);
                }
                                            )));
            }
                               );
            return(result);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public override IExtractResult Make(Action <int, string> progressTracker, IContextMessage contextMessage)
        {
            if (_argumentProvider == null)
            {
                return(null);
            }
            if (_argumentProvider.GetArg("AlgorithmName") == null)
            {
                PrintInfo("参数\"AlgorithmName\"为空。");
                return(null);
            }
            string algorith = _argumentProvider.GetArg("AlgorithmName").ToString();

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

            if (!File.Exists(bjianshu))
            {
                PrintInfo("所选择的数据:\"" + bjianshu + "\"不存在。");
                return(null);
            }
            if (_argumentProvider.GetArg("jianshu") == null)
            {
                PrintInfo("请选择植被指数(减数)数据。");
                return(null);
            }
            string jianshu = _argumentProvider.GetArg("jianshu").ToString();

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

            int ch1 = (int)_argumentProvider.GetArg("NdviCH1");
            int ch2 = (int)_argumentProvider.GetArg("NdviCH2");

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

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

            filePrdMap.Add("beijianshu", new FilePrdMap(bjianshu, 1, new VaildPra(float.MinValue, float.MaxValue), new int[] { ch1 }));
            filePrdMap.Add("jianshu", new FilePrdMap(jianshu, 1, new VaildPra(float.MinValue, float.MaxValue), new int[] { ch2 }));

            //为防止用户选择的波段超出数据波段的界限
            if (filePrdMap["beijianshu"].BandCount < 1 || filePrdMap["jianshu"].BandCount < 1)
            {
                PrintInfo("请选择正确的栅格数据进行差值计算。");
                return(null);
            }
            if (filePrdMap["beijianshu"].BandCount < ch1 || filePrdMap["jianshu"].BandCount < ch2)
            {
                PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                return(null);
            }

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

            if (prd == null)
            {
                throw new Exception("数据间无相交部分,无法创建虚拟数据提供者!");
            }
            IRasterPixelsVisitor <float> visitor = new RasterPixelsVisitor <float>(new ArgumentProvider(prd, null));
            IPixelFeatureMapper <Int16>  result  = new MemPixelFeatureMapper <Int16>("CHAZ", prd.Width * prd.Height, new Size(prd.Width, prd.Height), prd.CoordEnvelope, prd.SpatialRef);

            visitor.VisitPixel(new int[] { filePrdMap["beijianshu"].StartBand, filePrdMap["jianshu"].StartBand },
                               (idx, values) =>
            {
                result.Put(idx, (Int16)(values[0] - values[1]));
            }
                               );
            return(result);
        }
Esempio n. 5
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();
            }
        }