Exemple #1
0
        private IPixelFeatureMapper <T> MakeCompareRaster <T1, T>(string productIdentify, string fstFileName, string sedFileName, Func <T1, T1, T> function)
        {
            Dictionary <string, FilePrdMap> filePrdMap = new Dictionary <string, FilePrdMap>();

            filePrdMap.Add("backWaterPath", new FilePrdMap(fstFileName, 1, new VaildPra(float.MinValue, float.MaxValue), new int[] { 1 }));
            filePrdMap.Add("binWater", new FilePrdMap(sedFileName, 1, new VaildPra(float.MinValue, float.MaxValue), new int[] { 1 }));
            ITryCreateVirtualPrd       tryVPrd = new TryCreateVirtualPrdByMultiFile();
            IVirtualRasterDataProvider vrd     = tryVPrd.CreateVirtualRasterPRD(ref filePrdMap);

            if (vrd == null)
            {
                throw new Exception("数据间无相交部分,无法创建虚拟数据提供者!");
            }
            try
            {
                ArgumentProvider         ap        = new ArgumentProvider(vrd, null);
                RasterPixelsVisitor <T1> rpVisitor = new RasterPixelsVisitor <T1>(ap);
                IPixelFeatureMapper <T>  result    = new MemPixelFeatureMapper <T>(productIdentify, 1000, new Size(vrd.Width, vrd.Height), vrd.CoordEnvelope, vrd.SpatialRef);
                rpVisitor.VisitPixel(new int[] { filePrdMap["backWaterPath"].StartBand, filePrdMap["binWater"].StartBand },
                                     (idx, values) =>
                {
                    result.Put(idx, function(values[0], values[1]));
                });
                return(result);
            }
            finally
            {
                vrd.Dispose();
            }
        }
Exemple #2
0
 private IExtractResult CalcOPTDByOneFile(Dictionary <string, FilePrdMap> filePrdMap, IVirtualRasterDataProvider vrd, float extinctionCoefficient, int visibleCH, double visibleZoom, double OptdZoom)
 {
     try
     {
         ArgumentProvider            ap        = new ArgumentProvider(vrd, null);
         RasterPixelsVisitor <float> rpVisitor = new RasterPixelsVisitor <float>(ap);
         IPixelFeatureMapper <Int16> curOPTD   = new MemPixelFeatureMapper <Int16>("OPTD", 1000, new Size(vrd.Width, vrd.Height), vrd.CoordEnvelope, vrd.SpatialRef);
         float upRef = 0f;
         rpVisitor.VisitPixel(new int[] { filePrdMap["CurrentRasterFile"].StartBand,
                                          filePrdMap["csrFile"].StartBand,
                                          filePrdMap["dvlbFile"].StartBand },
                              (index, values) =>
         {
             if (values[2] == 1f)
             {
                 upRef = values[0] - Convert.ToSingle(values[1] * Math.Pow((1 - (values[0] / visibleZoom)), 2));
                 curOPTD.Put(index, (Int16)(upRef * (1 / extinctionCoefficient) / ((visibleZoom - upRef) * 3) * OptdZoom));
             }
             else
             {
                 curOPTD.Put(index, 0);
             }
         });
         return(curOPTD);
     }
     finally
     {
         vrd.Dispose();
     }
 }
Exemple #3
0
        private IExtractResult CompareDATFile(string backWaterPath, string binWater)
        {
            Dictionary <string, FilePrdMap> filePrdMap = new Dictionary <string, FilePrdMap>();

            filePrdMap.Add("backWaterPath", new FilePrdMap(backWaterPath, 1, new VaildPra(Int16.MinValue, Int16.MaxValue), new int[] { 1 }));
            filePrdMap.Add("binWater", new FilePrdMap(binWater, 1, new VaildPra(Int16.MinValue, Int16.MaxValue), new int[] { 1 }));
            ITryCreateVirtualPrd       tryVPrd = new TryCreateVirtualPrdByMultiFile();
            IVirtualRasterDataProvider vrd     = tryVPrd.CreateVirtualRasterPRD(ref filePrdMap);

            if (vrd == null)
            {
                PrintInfo("数据间无相交部分,无法进行泛滥缩小水体计算!");
                if (filePrdMap != null && filePrdMap.Count > 0)
                {
                    foreach (FilePrdMap value in filePrdMap.Values)
                    {
                        if (value.Prd != null)
                        {
                            value.Prd.Dispose();
                        }
                    }
                }
                return(null);
            }
            try
            {
                ArgumentProvider            ap        = new ArgumentProvider(vrd, null);
                RasterPixelsVisitor <float> rpVisitor = new RasterPixelsVisitor <float>(ap);
                IPixelFeatureMapper <Int16> result    = new MemPixelFeatureMapper <Int16>("FLOD", 1000, new Size(vrd.Width, vrd.Height), vrd.CoordEnvelope, vrd.SpatialRef);
                rpVisitor.VisitPixel(new int[] { filePrdMap["backWaterPath"].StartBand,
                                                 filePrdMap["binWater"].StartBand },
                                     (idx, values) =>
                {
                    if (values[0] == 1 && values[1] == 1)
                    {
                        result.Put(idx, 1);
                    }
                    else if (values[0] == 1 && values[1] == 0)
                    {
                        result.Put(idx, 5);
                    }
                    else if (values[0] == 0 && values[1] == 1)
                    {
                        result.Put(idx, 4);
                    }
                });
                RasterIdentify rid = new RasterIdentify(new string[] { backWaterPath, binWater });
                rid.ProductIdentify       = _subProductDef.ProductDef.Identify;
                rid.SubProductIdentify    = _identify;
                rid.IsOutput2WorkspaceDir = true;
                IInterestedRaster <Int16> iir = new InterestedRaster <Int16>(rid, result.Size, result.CoordEnvelope, result.SpatialRef);
                iir.Put(result);
                iir.Dispose();
                return(new FileExtractResult("扩大缩小水体", iir.FileName));
            }
            finally
            {
                vrd.Dispose();
            }
        }
Exemple #4
0
        public static Dictionary <float, List <float> > NDVIHistograms(TVDIUCArgs ucArgs)
        {
            string error = string.Empty;

            if (!CheckHistograms(ucArgs, ref error))
            {
                return(null);
            }
            Dictionary <string, FilePrdMap> filePrdMap = new Dictionary <string, FilePrdMap>();

            filePrdMap.Add("NDVIFile", new FilePrdMap(ucArgs.NDVIFile, ucArgs.TVDIParas.NdviFile.Zoom, new VaildPra(ucArgs.TVDIParas.NdviFile.Min, ucArgs.TVDIParas.NdviFile.Max), new int[] { ucArgs.TVDIParas.NdviFile.Band }));
            filePrdMap.Add("LSTFile", new FilePrdMap(ucArgs.ECLstFile, ucArgs.TVDIParas.LstFile.Zoom, new VaildPra(ucArgs.TVDIParas.LstFile.Min, ucArgs.TVDIParas.LstFile.Max), new int[] { 1 }));

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

            try
            {
                vrd = tryVPrd.CreateVirtualRasterPRD(ref filePrdMap);
                if (vrd == null)
                {
                    throw new Exception("数据间无相交部分,无法创建虚拟数据提供者!");
                }
                Dictionary <float, List <float> > result = new Dictionary <float, List <float> >();
                ArgumentProvider            ap           = new ArgumentProvider(vrd, null);
                RasterPixelsVisitor <float> rpVisitor    = new RasterPixelsVisitor <float>(ap);
                TVDIParaClass tvdiP = ucArgs.TVDIParas;
                IPixelFeatureMapper <float> _result = new MemPixelFeatureMapper <float>("0DWE", 1000, new Size(vrd.Width, vrd.Height), vrd.CoordEnvelope, vrd.SpatialRef);
                float ndvizoom = tvdiP.NdviFile.Zoom;
                float lstZoom  = tvdiP.LstFile.Zoom;
                rpVisitor.VisitPixel(new int[] { filePrdMap["NDVIFile"].StartBand,
                                                 filePrdMap["LSTFile"].StartBand },
                                     (index, values) =>
                {
                    if (values[1] >= tvdiP.LstFile.Min / lstZoom && values[1] <= tvdiP.LstFile.Max / lstZoom &&
                        values[0] >= tvdiP.NdviFile.Min / ndvizoom && values[0] <= tvdiP.NdviFile.Max / ndvizoom)
                    {
                        if (!result.ContainsKey(values[0]))
                        {
                            result.Add(values[0], new List <float>());
                        }
                        result[values[0]].Add(values[1]);
                    }
                });
                return(result.Count == 0 ? null : result);
            }
            finally
            {
                vrd.Dispose();
            }
        }
Exemple #5
0
        private IExtractResult OPTDAlgorithm()
        {
            int    visibleCH             = (int)_argumentProvider.GetArg("Visible");
            double OptdZoom              = (float)_argumentProvider.GetArg("OptdZoom");
            double visibleZoom           = (double)_argumentProvider.GetArg("Visible_Zoom");
            float  extinctionCoefficient = (float)_argumentProvider.GetArg("ExtinctionCoefficient");

            if (_argumentProvider.GetArg("CSRFile") == null || _argumentProvider.GetArg("DBLVFile") == null || _argumentProvider.GetArg("CurrentRasterFile") == null)
            {
                return(null);
            }
            string csrFile           = _argumentProvider.GetArg("CSRFile").ToString();
            string dvlbFile          = _argumentProvider.GetArg("DBLVFile").ToString();
            string CurrentRasterFile = _argumentProvider.GetArg("CurrentRasterFile").ToString();

            using (IRasterDataProvider rasterProvider = RasterDataDriver.Open(CurrentRasterFile) as IRasterDataProvider)
            {
                if (rasterProvider != null)
                {
                    IBandNameRaster bandNameRaster = rasterProvider as IBandNameRaster;
                    visibleCH = TryGetBandNo(bandNameRaster, "Visible");
                }
            }

            string errorStr = null;

            if (visibleCH == -1 || !File.Exists(csrFile) || !File.Exists(CurrentRasterFile) || !File.Exists(dvlbFile))
            {
                errorStr = "光学厚度生产所用通道未设置完全,请检查!";
                return(null);
            }

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

            filePrdMap.Add("CurrentRasterFile", new FilePrdMap(CurrentRasterFile, 1, new VaildPra(UInt16.MinValue, UInt16.MaxValue), new int[] { visibleCH }));
            filePrdMap.Add("csrFile", new FilePrdMap(csrFile, 1, new VaildPra(UInt16.MinValue, UInt16.MaxValue), new int[] { 1 }));
            filePrdMap.Add("dvlbFile", new FilePrdMap(dvlbFile, 1, new VaildPra(UInt16.MinValue, UInt16.MaxValue), new int[] { 1 }));

            ITryCreateVirtualPrd tryVPrd = new TryCreateVirtualPrdByMultiFile();

            vrd = tryVPrd.CreateVirtualRasterPRD(ref filePrdMap);
            if (vrd == null)
            {
                if (filePrdMap != null && filePrdMap.Count() > 0)
                {
                    foreach (FilePrdMap value in filePrdMap.Values)
                    {
                        if (value.Prd != null)
                        {
                            value.Prd.Dispose();
                        }
                    }
                }
                return(null);
            }
            try
            {
                return(CalcOPTDByOneFile(filePrdMap, vrd, extinctionCoefficient, visibleCH, visibleZoom, OptdZoom));
            }
            finally
            {
                if (filePrdMap != null && filePrdMap.Count() > 0)
                {
                    foreach (FilePrdMap value in filePrdMap.Values)
                    {
                        if (value.Prd != null)
                        {
                            value.Prd.Dispose();
                        }
                    }
                }
                if (vrd != null)
                {
                    vrd.Dispose();
                }
            }
        }
Exemple #6
0
        private IExtractResult VTIAlgorithm()
        {
            int NDVIBandCH        = (int)_curArguments.GetArg("NDVIBand");
            int NDVIBackBandMinCH = (int)_curArguments.GetArg("NDVIBackBandMin");
            int NDVIBackBandMaxCH = (int)_curArguments.GetArg("NDVIBackBandMax");

            int LSTBandCH        = (int)_curArguments.GetArg("LSTBand");
            int LSTBackBandMinCH = (int)_curArguments.GetArg("LSTBackBandMin");
            int LSTBackBandMaxCH = (int)_curArguments.GetArg("LSTBackBandMax");

            double NDVIZoom     = (float)_curArguments.GetArg("NDVIZoom");
            double NDVIBackZoom = (float)_curArguments.GetArg("NDVIBackZoom");

            double LSTZoom     = (float)_curArguments.GetArg("LSTZoom");
            double LSTBackZoom = (float)_curArguments.GetArg("LSTBackZoom");

            float ndviVaildMin = (float)_curArguments.GetArg("ndviVaildMin");
            float ndviVaildMax = (float)_curArguments.GetArg("ndviVaildMax");

            float lstVaildMin = (float)_curArguments.GetArg("lstVaildMin");
            float lstVaildMax = (float)_curArguments.GetArg("lstVaildMax");

            double VTIZoom  = (float)_curArguments.GetArg("VTIZoom");
            string errorStr = null;

            if (NDVIBandCH == -1 || NDVIBackBandMinCH == -1 || NDVIBackBandMaxCH == -1 || LSTBandCH == -1 || LSTBackBandMinCH == -1 || LSTBackBandMaxCH == -1 ||
                _curArguments.GetArg("NDVIFile") == null || _curArguments.GetArg("NDVIBackFile") == null ||
                _curArguments.GetArg("LSTFile") == null || _curArguments.GetArg("LSTBackFile") == null)
            {
                errorStr = "VTI生产所用文件或通道未设置完全,请检查!";
                return(null);
            }
            string[] ndviFileNames = GetStringArray("NDVIFile");
            string[] lstFileNames  = GetStringArray("LSTFile");


            string NDVIFile = ndviFileNames == null || ndviFileNames.Length == 1 ? _curArguments.GetArg("NDVIFile").ToString() : MAxValue(ndviFileNames, NDVIBandCH, (float)NDVIZoom);

            if (ndviFileNames != null && ndviFileNames.Length != 1)
            {
                NDVIBandCH = 1;
            }
            string NDVIBackFile = _curArguments.GetArg("NDVIBackFile").ToString();
            string LSTFile      = lstFileNames == null || lstFileNames.Length == 1 ? _curArguments.GetArg("LSTFile").ToString() : MAxValue(lstFileNames, LSTBandCH, (float)LSTZoom);

            if (lstFileNames != null && lstFileNames.Length != 1)
            {
                LSTBandCH = 1;
            }
            string LSTBackFile = _curArguments.GetArg("LSTBackFile").ToString();

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

            filePrdMap.Add("NDVIFile", new FilePrdMap(NDVIFile, NDVIZoom, new VaildPra(ndviVaildMin, ndviVaildMax), new int[] { NDVIBandCH }));
            filePrdMap.Add("NDVIBackFile", new FilePrdMap(NDVIBackFile, NDVIBackZoom, new VaildPra(ndviVaildMin, ndviVaildMax), new int[] { NDVIBackBandMinCH, NDVIBackBandMaxCH }));
            filePrdMap.Add("LSTFile", new FilePrdMap(LSTFile, LSTZoom, new VaildPra(lstVaildMin, lstVaildMax), new int[] { LSTBandCH }));
            filePrdMap.Add("LSTBackFile", new FilePrdMap(LSTBackFile, LSTBackZoom, new VaildPra(lstVaildMin, lstVaildMax), new int[] { LSTBackBandMinCH, LSTBackBandMaxCH }));

            ITryCreateVirtualPrd       tryVPrd = new TryCreateVirtualPrdByMultiFile();
            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>("0VTI", 1000, new Size(vrd.Width, vrd.Height), vrd.CoordEnvelope, vrd.SpatialRef);
                float vci = 0f;
                float tci = 0f;
                rpVisitor.VisitPixel(new int[] { filePrdMap["NDVIFile"].StartBand,
                                                 filePrdMap["NDVIBackFile"].StartBand,
                                                 filePrdMap["NDVIBackFile"].StartBand + 1,
                                                 filePrdMap["LSTFile"].StartBand,
                                                 filePrdMap["LSTBackFile"].StartBand,
                                                 filePrdMap["LSTBackFile"].StartBand + 1 },
                                     (index, values) =>
                {
                    if (values[0] < filePrdMap["NDVIFile"].VaildValue.Min || values[0] > filePrdMap["NDVIFile"].VaildValue.Max ||
                        values[1] < filePrdMap["NDVIBackFile"].VaildValue.Min || values[1] > filePrdMap["NDVIBackFile"].VaildValue.Max ||
                        values[2] < filePrdMap["NDVIBackFile"].VaildValue.Min || values[2] > filePrdMap["NDVIBackFile"].VaildValue.Max ||
                        values[3] < filePrdMap["LSTFile"].VaildValue.Min || values[3] > filePrdMap["LSTFile"].VaildValue.Max ||
                        values[4] < filePrdMap["LSTBackFile"].VaildValue.Min || values[4] > filePrdMap["LSTBackFile"].VaildValue.Max ||
                        values[5] < filePrdMap["LSTBackFile"].VaildValue.Min || values[5] > filePrdMap["LSTBackFile"].VaildValue.Max)
                    {
                        result.Put(index, 0);
                    }
                    else
                    {
                        //计算VCI
                        vci = (values[0] - values[1]) / (values[2] - values[1]);
                        //计算TCI
                        tci = (values[3] - values[4]) / (values[5] - values[4]);
                        result.Put(index, (Int16)((0.5 * vci + 0.5 * tci) * VTIZoom));
                    }
                });
                return(result);
            }
            finally
            {
                if (vrd != null)
                {
                    vrd.Dispose();
                }
            }
        }
 private IPixelIndexMapper GenerateHistoryResultByAOI(IPixelIndexMapper pixelMapper, int[] drawedAOI)
 {
     if (drawedAOI == null || drawedAOI.Length < 1)
     {
         return(null);
     }
     if (lstFiles.Items.Count < 1)
     {
         return(null);
     }
     foreach (string file in lstFiles.Items)
     {
         if (!File.Exists(file))
         {
             return(null);
         }
     }
     using (IRasterDataProvider prd = GeoDataDriver.Open(_currentRasterFile) as IRasterDataProvider)
     {
         List <int> aoiList = new List <int>();
         aoiList.AddRange(drawedAOI);
         IPixelIndexMapper result = PixelIndexMapperFactory.CreatePixelIndexMapper("FLD", prd.Width, prd.Height, prd.CoordEnvelope, prd.SpatialRef);
         if (pixelMapper != null && pixelMapper.Indexes.Count() > 0)
         {
             foreach (int i in pixelMapper.Indexes)
             {
                 if (aoiList.Contains(i))
                 {
                     result.Put(i);
                 }
             }
         }
         //
         IInterestedRaster <Int16> iir = null;
         try
         {
             RasterIdentify id = new RasterIdentify();
             id.ThemeIdentify      = "CMA";
             id.ProductIdentify    = "FLD";
             id.SubProductIdentify = "DBLV";
             iir = new InterestedRaster <Int16>(id, new Size(prd.Width, prd.Height), prd.CoordEnvelope.Clone());
             int[] idxs = result.Indexes.ToArray();
             iir.Put(idxs, 1);
         }
         finally
         {
             iir.Dispose();
         }
         Dictionary <string, FilePrdMap> filePrdMap = new Dictionary <string, FilePrdMap>();
         filePrdMap.Add("currentDBLV", new FilePrdMap(iir.FileName, 1, new VaildPra(Int16.MinValue, Int16.MaxValue), new int[] { 1 }));
         int index = 0;
         foreach (string file in lstFiles.Items)
         {
             filePrdMap.Add("dblv" + index, new FilePrdMap(file, 1, new VaildPra(Int16.MinValue, Int16.MaxValue), new int[] { 1 }));
             index++;
         }
         ITryCreateVirtualPrd       tryVPrd = new TryCreateVirtualPrdByMultiFile();
         IVirtualRasterDataProvider vrd     = tryVPrd.CreateVirtualRasterPRD(ref filePrdMap);
         if (vrd == null)
         {
             if (filePrdMap != null && filePrdMap.Count > 0)
             {
                 foreach (FilePrdMap value in filePrdMap.Values)
                 {
                     if (value.Prd != null)
                     {
                         value.Prd.Dispose();
                     }
                 }
             }
             return(null);
         }
         try
         {
             ArgumentProvider            ap        = new ArgumentProvider(vrd, null);
             RasterPixelsVisitor <float> rpVisitor = new RasterPixelsVisitor <float>(ap);
             int   historyCount = lstFiles.Items.Count;
             int[] bandNos      = new int[historyCount + 1];
             for (int i = 0; i < bandNos.Length; i++)
             {
                 bandNos[i] = i + 1;
             }
             int[] difArray = new int[historyCount];
             rpVisitor.VisitPixel(new Rectangle(0, 0, prd.Width, prd.Height), drawedAOI, bandNos,
                                  (idx, values) =>
             {
                 for (int i = 0; i < historyCount; i++)
                 {
                     if (values[0] != values[i + 1])
                     {
                         difArray[i]++;
                     }
                 }
             });
             int min = difArray[0], minIndex = 0;
             for (int i = 1; i < difArray.Length; i++)
             {
                 if (min > difArray[i])
                 {
                     min      = difArray[i];
                     minIndex = i;
                 }
             }
             rpVisitor.VisitPixel(bandNos,
                                  (idx, values) =>
             {
                 if (values[minIndex + 1] == 1)
                 {
                     if (!aoiList.Contains(idx))
                     {
                         result.Put(idx);
                     }
                 }
             });
             return(result);
         }
         finally
         {
             vrd.Dispose();
             if (File.Exists(iir.FileName))
             {
                 File.Delete(iir.FileName);
             }
         }
     }
 }
        private IExtractResult CalcMix(string dblvFile, string ldfFile, double bandZoom, int bandNo, double resultZoom, int[] dblvAOI, float waterNir, float LandNir, double zoom)
        {
            Dictionary <string, FilePrdMap> filePrdMap = new Dictionary <string, FilePrdMap>();

            filePrdMap.Add("dblvFile", new FilePrdMap(dblvFile, 1, new VaildPra(float.MinValue, float.MaxValue), new int[] { 1 }));
            filePrdMap.Add("ldfFile", new FilePrdMap(ldfFile, bandZoom, new VaildPra(float.MinValue, float.MaxValue), new int[] { bandNo }));
            ITryCreateVirtualPrd       tryVPrd = new TryCreateVirtualPrdByMultiFile();
            IVirtualRasterDataProvider vrd = tryVPrd.CreateVirtualRasterPRD(ref filePrdMap);
            int minWnd = 3, maxWnd = 3;

            if (vrd == null)
            {
                if (filePrdMap != null && filePrdMap.Count > 0)
                {
                    foreach (FilePrdMap value in filePrdMap.Values)
                    {
                        if (value.Prd != null)
                        {
                            value.Prd.Dispose();
                        }
                    }
                }
                return(null);
            }
            try
            {
                ArgumentProvider            ap        = new ArgumentProvider(vrd, null);
                RasterPixelsVisitor <float> rpVisitor = new RasterPixelsVisitor <float>(ap);
                Size size = new Size(vrd.Width, vrd.Height);
                MemPixelFeatureMapper <Int16> result = new MemPixelFeatureMapper <Int16>("0MIX", 1000, size, vrd.CoordEnvelope, vrd.SpatialRef);
                int       dblvBand   = filePrdMap["dblvFile"].StartBand;
                int       ldfBand    = filePrdMap["ldfFile"].StartBand;
                int[]     wndBandNos = new int[] { dblvBand, ldfBand };
                Rectangle aoiRect    = AOIHelper.ComputeAOIRect(dblvAOI, size);
                bool      isEdge     = false;
                using (IRasterPixelsVisitor <float> visitor = new RasterPixelsVisitor <float>(ap))
                {
                    visitor.VisitPixelWnd(aoiRect, dblvAOI, wndBandNos, wndBandNos, minWnd, maxWnd,
                                          (pixelIdx, crtWndSize, bandValues, wndValues) =>
                    {
                        return(false);
                    },
                                          (pixelIdx, crtWndSize, bandValues, wndValues) =>
                    {
                        isEdge = IsEdgeMethod(bandValues, wndValues, 0);
                        if (isEdge)
                        {
                            result.Put(pixelIdx, GetResult(bandValues, wndValues, waterNir, LandNir, zoom));
                        }
                    });
                }
                return(result);
            }
            finally
            {
                if (vrd != null)
                {
                    vrd.Dispose();
                }
                if (filePrdMap != null && filePrdMap.Count > 0)
                {
                    foreach (FilePrdMap value in filePrdMap.Values)
                    {
                        if (value.Prd != null)
                        {
                            value.Prd.Dispose();
                        }
                    }
                }
            }
        }
        private void GetDBLVAOIIndex(string dblvFile, string cloudFile, List <int> dblvAOI)
        {
            Dictionary <string, FilePrdMap> filePrdMap = new Dictionary <string, FilePrdMap>();

            filePrdMap.Add("dblvFile", new FilePrdMap(dblvFile, 1, new VaildPra(float.MinValue, float.MaxValue), new int[] { 1 }));
            filePrdMap.Add("cloudFile", new FilePrdMap(cloudFile, 1, new VaildPra(float.MinValue, float.MaxValue), new int[] { 1 }));
            ITryCreateVirtualPrd       tryVPrd = new TryCreateVirtualPrdByMultiFile();
            IVirtualRasterDataProvider vrd = tryVPrd.CreateVirtualRasterPRD(ref filePrdMap);
            int minWnd = 3, maxWnd = 3;

            if (vrd == null)
            {
                if (filePrdMap != null && filePrdMap.Count > 0)
                {
                    foreach (FilePrdMap value in filePrdMap.Values)
                    {
                        if (value.Prd != null)
                        {
                            value.Prd.Dispose();
                        }
                    }
                }
                return;
            }
            try
            {
                List <int> temp = new List <int>();
                temp.AddRange(dblvAOI);
                dblvAOI.Clear();
                ArgumentProvider ap   = new ArgumentProvider(vrd, null);
                Size             size = new Size(vrd.Width, vrd.Height);
                int       dblvBand    = filePrdMap["dblvFile"].StartBand;
                int       cloudBand   = filePrdMap["cloudFile"].StartBand;
                int[]     tempAOI     = temp.ToArray();
                Rectangle aoiRect     = AOIHelper.ComputeAOIRect(tempAOI, size);
                int[]     wndBandNos  = new int[] { dblvBand, cloudBand };
                bool      isCloudEgde = false;
                using (IRasterPixelsVisitor <float> visitor = new RasterPixelsVisitor <float>(ap))
                {
                    visitor.VisitPixelWnd(aoiRect, tempAOI, wndBandNos, wndBandNos, minWnd, maxWnd,
                                          (pixelIdx, crtWndSize, bandValues, wndValues) =>
                    {
                        return(false);
                    },
                                          (pixelIdx, crtWndSize, bandValues, wndValues) =>
                    {
                        isCloudEgde = IsCloudEdgeMethod(bandValues, wndValues, 1);
                        if (isCloudEgde)
                        {
                            temp.Remove(pixelIdx);
                        }
                    });
                }
                dblvAOI.AddRange(temp);
                temp = null;
            }
            finally
            {
                if (vrd != null)
                {
                    vrd.Dispose();
                }
            }
        }
Exemple #10
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 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();
            }
        }