public frmHistograms(ref TVDIUCArgs ucArgs, ref string error) { InitializeComponent(); _ucArgs = ucArgs; _error = error; Load += new EventHandler(frmHistograms_Load); }
private static bool CheckHistograms(TVDIUCArgs ucArgs, ref string error) { error = ""; if (string.IsNullOrEmpty(ucArgs.ECLstFile) || string.IsNullOrEmpty(ucArgs.NDVIFile) || ucArgs.TVDIParas == null || ucArgs.TVDIParas.LstFile == null || ucArgs.TVDIParas.NdviFile == null) { error = "直方图统计所需数据或参数设置不全."; return(false); } return(true); }
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 { } }
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 { } }
private TVDIUCArgs GetUCArgs() { if (_ucArgs == null) { _ucArgs = new TVDIUCArgs(); } _ucArgs.TVDIParas = _cur; _ucArgs.NDVIFile = _ndviFile; _ucArgs.LSTFile = _lstFile; _ucArgs.DEMFile = _demFile; _ucArgs.DryWetEdgesFitting = _dryWetEdgesArgs; return(_ucArgs); }
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(); } }
public static bool DoDryWetEdgeFitting(out DryWetEdgeArgs args, TVDIUCArgs ucArgs, ref string error) { args = null; if (!CheckHistograms(ucArgs, ref error)) { return(false); } Dictionary <float, List <float> > histograms = NDVIHistograms(ucArgs); args = DryWetEdgesArgsCalc(ucArgs, histograms); if (args == null) { error = "干湿边拟合失败,请调整NDVI值域范围后重试!"; return(false); } return(true); }
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(); } } }
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); } string lstFile = ucArgs.LSTFile; string demFile = ucArgs.DEMFile; float lstZoom = ucArgs.TVDIParas.LstFile.Zoom; int lstMin = ucArgs.TVDIParas.LstFile.Min; int lstMax = ucArgs.TVDIParas.LstFile.Max; int lstBand = ucArgs.TVDIParas.LstFile.Band; IRasterDataProvider lstPrd = null; IRasterDataProvider demPrd = null; try { List <RasterMaper> rms = new List <RasterMaper>(); lstPrd = RasterDataDriver.Open(lstFile) as IRasterDataProvider; if (lstPrd.BandCount < lstBand) { error = "选择的文件不正确,请重新选择。"; return(false); } RasterMaper lstRm = new RasterMaper(lstPrd, new int[] { lstBand }); rms.Add(lstRm); demPrd = RasterDataDriver.Open(demFile) as IRasterDataProvider; if (demPrd.BandCount < 1) { error = "选择的文件不正确,请重新选择。"; return(false); } RasterMaper demRm = new RasterMaper(demPrd, new int[] { 1 }); rms.Add(demRm); //输出文件准备(作为输入栅格并集处理) string outFileName = CreatOutFileName(lstFile, demFile); using (IRasterDataProvider outRaster = CreateOutRaster(outFileName, rms.ToArray())) { //栅格数据映射 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); rfr.RegisterCalcModel(new RasterCalcHandler <Int16, Int16>((rvInVistor, rvOutVistor, aoi) => { int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX; int value0 = 0; int value1 = 0; 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 (value1 == -9999) { rvOutVistor[0].RasterBandsData[0][index] = 9999;//海洋 continue; } if (value1 == -9000) { rvOutVistor[0].RasterBandsData[0][index] = 9000;//非中国区域陆地 continue; } if (value1 >= 6000) { rvOutVistor[0].RasterBandsData[0][index] = 0; //6000之内的LST数据 continue; } if (value0 == ucArgs.TVDIParas.LstFile.Cloudy) { rvOutVistor[0].RasterBandsData[0][index] = 9998; //云区 continue; } if (value0 == 12) { rvOutVistor[0].RasterBandsData[0][index] = 9997;//无数据区域 continue; } if (value0 == 0) { rvOutVistor[0].RasterBandsData[0][index] = 0; continue; } if (value1 == 0) { rvOutVistor[0].RasterBandsData[0][index] = 0; continue; } rvOutVistor[0].RasterBandsData[0][index] = (Int16)(((double)value0 / lstZoom - 273 + 0.006 * value1) * lstZoom); } })); //执行 rfr.Excute(); //FileExtractResult res = new FileExtractResult("0LEC", outFileName, true); //res.SetDispaly(false); } ucArgs.ECLstFile = outFileName; return(true); } finally { if (lstPrd != null) { lstPrd.Dispose(); } if (demPrd != null) { demPrd.Dispose(); } } }
private IExtractResult DemAlgorithm(Action <int, string> progressTracker) { TVDIUCArgs args = _argumentProvider.GetArg("ArgumentSetting") as TVDIUCArgs; if (args == null) { PrintInfo("请设置进行温度植被干旱指数计算的参数。"); return(null); } string ndviFile = args.NDVIFile; string lstFile = args.ECLstFile; DryWetEdgeArgs dryWetArg = args.DryWetEdgesFitting; if (string.IsNullOrEmpty(ndviFile) || string.IsNullOrEmpty(lstFile)) { PrintInfo("请选择进行温度植被干旱指数计算所需的文件。"); return(null); } if (dryWetArg == null) { PrintInfo("请先进行干湿边拟合,计算拟合参数。"); return(null); } double maxA = dryWetArg.MaxA, maxB = dryWetArg.MaxB, minA = dryWetArg.MinA, minB = dryWetArg.MinB; if (args.TVDIParas == null || args.TVDIParas.LstFile == null) { return(null); } int ndviBand = args.TVDIParas.NdviFile.Band; if (ndviBand == -1) { return(null); } int lstZoom = args.TVDIParas.Zoom; //args.TVDIParas.LstFile.Zoom; if (lstZoom == 0) { return(null); } int lstMin = args.TVDIParas.LstFile.Min; int lstMax = args.TVDIParas.LstFile.Max; int ndviCloudy = args.TVDIParas.NdviFile.Cloudy; //输入文件准备 List <RasterMaper> rms = new List <RasterMaper>(); IRasterDataProvider ndviPrd = null; IRasterDataProvider lstPrd = null; try { ndviPrd = GeoDataDriver.Open(ndviFile) as IRasterDataProvider; if (ndviPrd.BandCount < ndviBand) { PrintInfo("请选择正确的植被指数文件进行温度植被干旱指数计算。"); return(null); } RasterMaper ndviRm = new RasterMaper(ndviPrd, new int[] { ndviBand }); rms.Add(ndviRm); lstPrd = GeoDataDriver.Open(lstFile) as IRasterDataProvider; if (lstPrd.BandCount < 1) { PrintInfo("请选择正确的陆表高温文件进行温度植被干旱指数计算。"); return(null); } RasterMaper lstRm = new RasterMaper(lstPrd, new int[] { 1 }); rms.Add(lstRm); //输出文件准备 RasterIdentify ri = GetRasterIdentifyID(new string[] { ndviFile, lstFile }); string outFileName = ri.ToWksFullFileName(".dat"); //string outFileName = GetFileName(new string[] { ndviFile, lstFile }, _subProductDef.ProductDef.Identify, _identify, ".dat", null); using (IRasterDataProvider outRaster = CreateOutRaster(outFileName, rms.ToArray())) { //栅格数据映射 RasterMaper[] fileIns = rms.ToArray(); RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) }; RasterProcessModel <short, short> rfr = new RasterProcessModel <short, short>(progressTracker); rfr.SetRaster(fileIns, fileOuts); double tmin = 0d, tmax = 0d; short value0 = 0, value1 = 0; rfr.RegisterCalcModel(new RasterCalcHandler <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) { return; } for (int index = 0; index < dataLength; index++) { value0 = rvInVistor[0].RasterBandsData[0][index]; value1 = rvInVistor[1].RasterBandsData[0][index]; #region LST if (value1 == 9000) { rvOutVistor[0].RasterBandsData[0][index] = (Int16)(2 * lstZoom); //非中国区域陆地 continue; } if (value1 == 9999) { rvOutVistor[0].RasterBandsData[0][index] = (Int16)Math.Round((2.5 * lstZoom), 0); //海区 continue; } if (value1 == 9998) { rvOutVistor[0].RasterBandsData[0][index] = (Int16)Math.Round((2.55 * lstZoom), 0); //云区 continue; } if (value1 == 9997) { rvOutVistor[0].RasterBandsData[0][index] = (Int16)Math.Round((1.5 * lstZoom), 0); //无数据区域 continue; } if (value1 < lstMin || value1 > lstMax) { rvOutVistor[0].RasterBandsData[0][index] = (Int16)Math.Round((1.5 * lstZoom), 0); continue; } #endregion #region ndvi检查 if (value0 == ndviCloudy) //过滤无效值 { rvOutVistor[0].RasterBandsData[0][index] = (Int16)Math.Round((2.55 * lstZoom), 0); continue; } if (value0 == 0) { continue; } #endregion tmin = minA + minB * value0; tmax = maxA + maxB * value0; if (tmin == tmax) { rvOutVistor[0].RasterBandsData[0][index] = 0; } else { rvOutVistor[0].RasterBandsData[0][index] = (Int16)(((value1 - tmin) / (tmax - tmin)) * lstZoom); } } })); rfr.Excute(); FileExtractResult res = new FileExtractResult(_subProductDef.Identify, outFileName, true); res.SetDispaly(false); return(res); } } finally { if (ndviPrd != null) { ndviPrd.Dispose(); } if (lstPrd != null) { lstPrd.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(); } }