Пример #1
0
        public static bool SaveToFile(TVDIParaClass tvdiParas, string filename)
        {
            string path = Path.GetDirectoryName(filename);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
            try
            {
                _doc = new XmlDocument();
                CreateBootXML("TVDI");
                _bootNode = _doc.DocumentElement;
                CreateTVDIFile(tvdiParas);
                _doc.Save(filename);
                return(true);
            }
            finally
            {
                _doc      = null;
                _bootNode = null;
            }
        }
Пример #2
0
 private static void CreateTVDIFile(TVDIParaClass tvdiParas)
 {
     WriteNode(_bootNode, "Length", tvdiParas.Length.ToString());
     WriteNode(_bootNode, "Flimit", tvdiParas.FLimit.ToString());
     WriteNode(_bootNode, "HGYZ", tvdiParas.HGYZ.ToString());
     WriteNode(_bootNode, "LSTFreq", tvdiParas.LstFreq.ToString());
     WriteNode(_bootNode, "Zoom", tvdiParas.Zoom.ToString());
     WriteArgumentItem(_bootNode, "LST", tvdiParas.LstFile);
     WriteArgumentItem(_bootNode, "NDVI", tvdiParas.NdviFile);
 }
Пример #3
0
        private static DryWetEdgeArgs DryWetEdgesArgsCalc(TVDIUCArgs ucArgs, NdviList[] NDVIHistograms)
        {
            List <Samples> minData    = new List <Samples>();
            List <Samples> maxData    = new List <Samples>();
            TVDIParaClass  tvdiP      = ucArgs.TVDIParas;
            ArgumentItem   ndviArgs   = tvdiP.NdviFile;
            int            ndviCloudy = ndviArgs.Cloudy;
            ArgumentItem   lstArgs    = tvdiP.LstFile;

            try
            {
                int rangeSize = (int)Math.Ceiling((double)(ndviArgs.Max - ndviArgs.Min) / tvdiP.Length);//区间个数
                if (rangeSize == 0)
                {
                    return(null);
                }
                int   key    = 0;
                float minLst = 0;
                float maxLst = 0;
                for (int rangeIndex = 0; rangeIndex < rangeSize; rangeIndex++)//每个步长区间,0~step;step~step*rangeIndex;step
                {
                    key = (int)(ndviArgs.Min + tvdiP.Length * rangeIndex - (-1000));
                    if (key >= NDVIHistograms.Length || NDVIHistograms[key] == null)
                    {
                        continue;
                    }
                    if (NDVIHistograms[key].Ndvi == ndviCloudy || NDVIHistograms[key].Ndvi == 0)
                    {
                        continue;
                    }
                    if (!ValidValueHelper.IsVaild(key, ndviArgs))
                    {
                        continue;
                    }
                    if (NDVIHistograms[key].Lst == null || NDVIHistograms[key].Lst.Count == 0)
                    {
                        continue;
                    }
                    NDVIHistograms[key].Lst.Sort();
                    NdviLstPCStat(NDVIHistograms[key].Lst, out minLst, out maxLst, ucArgs.TVDIParas.LstFile, tvdiP.LstFreq);
                    if (minLst == 0 && maxLst == 0)
                    {
                        continue;
                    }
                    minData.Add(new Samples(NDVIHistograms[key].Ndvi, minLst));
                    maxData.Add(new Samples(NDVIHistograms[key].Ndvi, maxLst));
                }
                GC.Collect();
                return(NihePara(maxData, minData, tvdiP.FLimit, tvdiP.HGYZ));
            }
            finally
            {
            }
        }
Пример #4
0
 void UCTVDIPanel_Load(object sender, EventArgs e)
 {
     _cur = ReadExpCofficientFile.LoadTVDIParasFile(ArgsFileProvider.TVDIArgsFile);
     if (_cur == null)
     {
         _cur = new TVDIParaClass();
     }
     if (_handler != null)
     {
         _handler(GetArgumentValue());
     }
 }
Пример #5
0
        private static DryWetEdgeArgs DryWetEdgesArgsCalc(TVDIUCArgs ucArgs, Dictionary <float, List <float> > NDVIHistograms)
        {
            List <Samples> minData  = new List <Samples>();
            List <Samples> maxData  = new List <Samples>();
            TVDIParaClass  tvdiP    = ucArgs.TVDIParas;
            ArgumentItem   ndviArgs = tvdiP.NdviFile;
            ArgumentItem   lstArgs  = tvdiP.LstFile;

            try
            {
                int rangeSize = (int)Math.Ceiling((double)(ndviArgs.Max - ndviArgs.Min) / tvdiP.Length);//区间个数
                if (rangeSize == 0)
                {
                    return(null);
                }
                float key    = 0;
                float minLst = 0;
                float maxLst = 0;
                for (int rangeIndex = 0; rangeIndex < rangeSize; rangeIndex++) //每个步长区间,0~step;step~step*rangeIndex;step
                {
                    key = (float)(ndviArgs.Min + tvdiP.Length * rangeIndex);   // / ndviArgs.Zoom;

                    if (!NDVIHistograms.ContainsKey(key))
                    {
                        continue;
                    }
                    if (key == 0 || !ValidValueHelper.IsVaild(key, ndviArgs))
                    {
                        continue;
                    }
                    if (NDVIHistograms[key] == null || NDVIHistograms[key].Count == 0)
                    {
                        continue;
                    }
                    NDVIHistograms[key].Sort();
                    minLst = 0;
                    maxLst = 0;
                    NdviLstPCStat(NDVIHistograms[key], out minLst, out maxLst, ucArgs.TVDIParas.LstFile, tvdiP.LstFreq);
                    if (minLst == 0 && maxLst == 0)
                    {
                        continue;
                    }
                    minData.Add(new Samples(key * ndviArgs.Zoom, minLst * lstArgs.Zoom));
                    maxData.Add(new Samples(key * ndviArgs.Zoom, maxLst * lstArgs.Zoom));
                }
                GC.Collect();
                return(NihePara(maxData, minData, ndviArgs, tvdiP.LstFile, tvdiP.FLimit, tvdiP.HGYZ));
            }
            finally
            {
            }
        }
Пример #6
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();
            }
        }
Пример #7
0
        public static TVDIParaClass LoadTVDIParasFile(string filename)
        {
            if (string.IsNullOrEmpty(filename) || !File.Exists(filename))
            {
                return(null);
            }
            TVDIParaClass paras = new TVDIParaClass();
            XElement      root  = XElement.Load(filename);

            if (root == null)
            {
                return(null);
            }
            XElement zoomRoot = ReadXElement(root, "Zoom");

            if (zoomRoot != null)
            {
                paras.Zoom = int.Parse(zoomRoot.Value);
            }
            XElement lengthRoot = ReadXElement(root, "Length");

            if (lengthRoot != null)
            {
                paras.Length = int.Parse(lengthRoot.Value);
            }
            XElement flimitRoot = ReadXElement(root, "Flimit");

            if (flimitRoot != null)
            {
                paras.FLimit = float.Parse(flimitRoot.Value);
            }
            XElement LstPcRoot = ReadXElement(root, "LSTFreq");

            if (LstPcRoot != null)
            {
                paras.LstFreq = int.Parse(LstPcRoot.Value);
            }
            XElement hgYZRoot = ReadXElement(root, "HGYZ");

            if (hgYZRoot != null)
            {
                paras.HGYZ = float.Parse(hgYZRoot.Value);
            }
            paras.NdviFile = ReadFileParaParas(root, "NDVI");
            paras.LstFile  = ReadFileParaParas(root, "LST");
            return(paras);
        }
Пример #8
0
        public static NdviList[] NDVIHistograms(TVDIUCArgs ucArgs)
        {
            string error = string.Empty;

            if (!CheckHistograms(ucArgs, ref error))
            {
                return(null);
            }
            string ndviFile = ucArgs.NDVIFile;
            int    ndviZoom = ucArgs.TVDIParas.NdviFile.Zoom;
            int    ndviMin  = ucArgs.TVDIParas.NdviFile.Min;
            int    ndviMax  = ucArgs.TVDIParas.NdviFile.Max;
            int    ndviBand = ucArgs.TVDIParas.NdviFile.Band;

            string lstFile = ucArgs.ECLstFile;
            int    lstZoom = ucArgs.TVDIParas.LstFile.Zoom;
            int    lstMin  = ucArgs.TVDIParas.LstFile.Min;
            int    lstMax  = ucArgs.TVDIParas.LstFile.Max;
            IRasterDataProvider ndviPrd = null;
            IRasterDataProvider lstPrd  = null;

            try
            {
                List <RasterMaper> rms = new List <RasterMaper>();
                ndviPrd = RasterDataDriver.Open(ndviFile) as IRasterDataProvider;
                if (ndviPrd.BandCount < ndviBand)
                {
                    return(null);
                }
                RasterMaper ndviRm = new RasterMaper(ndviPrd, new int[] { ndviBand });
                rms.Add(ndviRm);

                lstPrd = RasterDataDriver.Open(lstFile) as IRasterDataProvider;
                if (lstPrd.BandCount < 1)
                {
                    return(null);
                }
                RasterMaper lstRm = new RasterMaper(lstPrd, new int[] { 1 });
                rms.Add(lstRm);

                string outFileName = CreatOutFile();
                Int16  value0      = 0;
                Int16  value1      = 0;
                using (IRasterDataProvider outRaster = CreateOutRaster(outFileName, rms.ToArray()))
                {
                    int           start = -1000, end = 1000;
                    int           statLength = end - start + 1;
                    NdviList[]    results    = new NdviList[statLength];
                    RasterMaper[] fileIns    = rms.ToArray();
                    RasterMaper[] fileOuts   = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                    RasterProcessModel <Int16, Int16> rfr = new RasterProcessModel <Int16, Int16>();
                    rfr.SetRaster(fileIns, fileOuts);
                    TVDIParaClass tvdiP = ucArgs.TVDIParas;
                    rfr.RegisterCalcModel(new RasterCalcHandler <Int16, Int16>((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];
                            if (value0 < -1000 || value0 > 1000)
                            {
                                continue;
                            }
                            if (results[value0 - (-1000)] == null)
                            {
                                results[value0 - (-1000)] = new NdviList(value0);
                            }
                            results[value0 - (-1000)].Lst.Add(value1);
                        }
                    }));
                    rfr.Excute();
                    return(results);
                }
            }
            finally
            {
                if (ndviPrd != null)
                {
                    ndviPrd.Dispose();
                }
                if (lstPrd != null)
                {
                    lstPrd.Dispose();
                }
            }
        }
Пример #9
0
 public void BtnEdit_Click(object curArg)
 {
     _cur = curArg as TVDIParaClass;
 }