public static ICandidatePixelFilter CreateAbnormalHighTmpFile(IArgumentProvider argProvider, IContextMessage contextMessage) { float bandZoom = Obj2Float(argProvider.GetArg("MiddleInfrared_Zoom")); if (bandZoom < float.Epsilon) { PrintInfo(contextMessage, " 中红外波段数值缩放参数设置错误。"); return(null); } IBandNameRaster bandNameRaster = argProvider.DataProvider as IBandNameRaster; int midInfraredBandNo = TryGetBandNo(argProvider, bandNameRaster, "MiddleInfrared"); if (midInfraredBandNo < 1) { PrintInfo(contextMessage, " 无法正确获取中红外波段序号。"); return(null); } int farInfraredBandNo = TryGetBandNo(argProvider, bandNameRaster, "FarInfrared"); if (farInfraredBandNo < 1) { PrintInfo(contextMessage, " 无法正确获取远红外波段序号。"); return(null); } int maxWndSize = Obj2Int(argProvider.GetArg("HTWndMax")); if (maxWndSize < 7) { PrintInfo(contextMessage, " 未能获取正确的最大邻域窗口大小,设置为默认值7。"); maxWndSize = 7; } int minWndSize = 7; int midInfraredMax = Obj2Int(argProvider.GetArg("HTMiddleInfraredMax")); if (midInfraredMax == 0) { PrintInfo(contextMessage, " 中红外最大值参数设置错误。"); return(null); } int dlt_mid_far = Obj2Int(argProvider.GetArg("HTMiddleFarInfraredDiff")); if (dlt_mid_far == 0) { PrintInfo(contextMessage, " (中红外 - 远红外)差值阈值设置错误。"); return(null); } int mid_offset = Obj2Int(argProvider.GetArg("HTMiddleInfraredOffset")); if (mid_offset == 0) { PrintInfo(contextMessage, " 中红外偏移阈值设置错误。"); return(null); } int abnormalPixelCount = Obj2Int(argProvider.GetArg("HTAbnormalPixelCount")); if (abnormalPixelCount == 0) { PrintInfo(contextMessage, " 邻域内异常高温点数量阈值设置错误,设为默认值6。"); abnormalPixelCount = 6; } AbnormalHTmpPixelFilter filter = new AbnormalHTmpPixelFilter(minWndSize, maxWndSize, midInfraredBandNo, farInfraredBandNo, bandZoom, mid_offset, midInfraredMax, dlt_mid_far, abnormalPixelCount, argProvider); return(filter); }
public static BackTmpComputer CreateBackTmpComputer(IArgumentProvider argProvider, IBackTmpComputerHelper helper, IContextMessage contextMessage) { int minWndSize = Obj2Int(argProvider.GetArg("BackWndMin")); int maxWndSize = Obj2Int(argProvider.GetArg("BackWndMax")); int localBackTmpMax = Obj2Int(argProvider.GetArg("BackTmp_localBackTmpMax")); int localBackTmpMin = Obj2Int(argProvider.GetArg("BackTmp_localBackTmpMin")); int glaringVIRR = Obj2Int(argProvider.GetArg("BackTmp_GlaringVIRR")); int wildernessCorrect = Obj2Int(argProvider.GetArg("BackTmp_WildernessCorrect")); int maxHitedPixelCount = Obj2Int(argProvider.GetArg("BackTmp_SkyPixelCount")); IBandNameRaster bandNameRaster = argProvider.DataProvider as IBandNameRaster; int visBandNo = TryGetBandNo(argProvider, bandNameRaster, "Visible"); int nearIfrBandNo = TryGetBandNo(argProvider, bandNameRaster, "NearInfrared"); int midIfrBandNo = TryGetBandNo(argProvider, bandNameRaster, "MiddleInfrared"); int farIfrBandNo = TryGetBandNo(argProvider, bandNameRaster, "FarInfrared"); float fireGradeLevel1 = Obj2Float(argProvider.GetArg("Intensity_Grade1")); float fireGradeLevel2 = Obj2Float(argProvider.GetArg("Intensity_Grade2")); float fireGradeLevel3 = Obj2Float(argProvider.GetArg("Intensity_Grade3")); float fireGradeLevel4 = Obj2Float(argProvider.GetArg("Intensity_Grade4")); float fireGradeLevel5 = Obj2Float(argProvider.GetArg("Intensity_Grade5")); float vis_FirReliability = Obj2Float(argProvider.GetArg("Vis_FirReliability")); float midIfr_farInfr_FirReliability = Obj2Float(argProvider.GetArg("MidIfr_farInfr_FirReliability")); float midIfr_FirReliability = Obj2Float(argProvider.GetArg("MidIfr_FirReliability")); bool isNight = bool.Parse(argProvider.GetArg("IsNight").ToString()); if (!isNight && (visBandNo < 1 || midIfrBandNo < 1 || farIfrBandNo < 1 || nearIfrBandNo < 1)) { PrintInfo(contextMessage, " 获取波段序号(可见光、近红外、中红外、远红外)时发生错误。"); return(null); } else if (isNight && (farIfrBandNo < 1 || midIfrBandNo < 1)) { PrintInfo(contextMessage, " 获取波段序号(可见光、近红外、中红外、远红外)时发生错误。"); return(null); } float bandZoom = Obj2Float(argProvider.GetArg("MiddleInfrared_Zoom")); if (bandZoom < float.Epsilon) { PrintInfo(contextMessage, " 波段数值缩放参数设置错误,使用缺省值1。"); } ISolarZenithProvider solarZentihProvider = null; float minSolarZentih = Obj2Float(argProvider.GetArg("BackTmp_SolarAzimuthMin")); float maxSolarZentih = Obj2Float(argProvider.GetArg("BackTmp_SolarAzimuthMax")); //亚像元面积计算 float midIfrCenterWaveNum = Obj2Float(argProvider.GetArg("MiddleInfrared_CenterWaveNum")); float farIfrCenterWaveNum = Obj2Float(argProvider.GetArg("FarInfrared_CenterWaveNum")); TryCorrectCenterWaveNum(argProvider.DataProvider, midIfrBandNo, farIfrBandNo, ref midIfrCenterWaveNum, ref farIfrCenterWaveNum, contextMessage); if (midIfrCenterWaveNum < float.Epsilon || farIfrCenterWaveNum < float.Epsilon) { PrintInfo(contextMessage, " 获取中红外、远红外中心波数失败,忽略亚像元面积、火点强度计算。"); } int midIfrMaxMidIfrValue = Obj2Int(argProvider.GetArg("BackTmp_MaxMidIfrValue")); float firComputeFactor = Obj2Float(argProvider.GetArg("BackTmp_FirComputeFactor")); float firIntensityFactor = Obj2Float(argProvider.GetArg("BackTmp_FirIntensityFactor")); // return(new BackTmpComputer(minWndSize, maxWndSize, maxHitedPixelCount, solarZentihProvider, minSolarZentih, maxSolarZentih, farIfrBandNo, midIfrBandNo, visBandNo, nearIfrBandNo, bandZoom, midIfrCenterWaveNum, farIfrCenterWaveNum, midIfrMaxMidIfrValue, firComputeFactor, firIntensityFactor, localBackTmpMax, localBackTmpMin, glaringVIRR, wildernessCorrect, helper, fireGradeLevel1, fireGradeLevel2, fireGradeLevel3, fireGradeLevel4, fireGradeLevel5, vis_FirReliability, midIfr_farInfr_FirReliability, midIfr_FirReliability)); }
public IExtractResult DoCalLAIfromHDFPrj() { if (_progressTracker != null) { _progressTracker(1, "开始计算LAI..."); } Dictionary <string, string[]> arguments = _argumentProvider.GetArg("IOFilesArguments") as Dictionary <string, string[]>; if (arguments == null || !arguments.ContainsKey("INPUTFILES")) { return(null); } if (arguments["INPUTFILES"].Length != 7) { return(null); } foreach (string infile in arguments["INPUTFILES"]) { if (!File.Exists(infile)) { return(null); } } string L2LSRFile = arguments["INPUTFILES"][0];//LSR投影文件 string _szafile = arguments["INPUTFILES"][1]; string _saafile = arguments["INPUTFILES"][2]; string _vzafile = arguments["INPUTFILES"][3]; string _vaafile = arguments["INPUTFILES"][4]; string L2CLDMaskFile = arguments["INPUTFILES"][5]; //云检测文件 string landCoverFile = arguments["INPUTFILES"][6]; //土地覆盖类型文件 #region 获取波段信息 if (_argumentProvider.GetArg("Red") == null) { PrintInfo("参数\"Red\"为空。"); return(null); } int rno = (int)(_argumentProvider.GetArg("Red")); if (rno <= 0) { PrintInfo("参数\"Red\"波段号无效。"); return(null); } if (_argumentProvider.GetArg("NearInfrared") == null) { PrintInfo("参数\"NearInfrared\"为空。"); return(null); } int irno = (int)(_argumentProvider.GetArg("NearInfrared")); if (irno <= 0) { PrintInfo("参数\"NearInfrared\"波段号无效。"); return(null); } if (_argumentProvider.GetArg("SWInfrared") == null) { PrintInfo("参数\"SWInfrared\"为空。"); return(null); } int swirno = (int)(_argumentProvider.GetArg("SWInfrared")); if (swirno <= 0) { PrintInfo("参数\"SWInfrared\"波段号无效。"); return(null); } #endregion int rnoCH = -1, irnoCH = -1, swirnoCH = -1; IBandNameRaster bandNameRaster = null; bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster; using (IRasterDataProvider dr = GeoDataDriver.Open(L2LSRFile) as IRasterDataProvider) { if (dr != null) { bandNameRaster = dr as IBandNameRaster; } } if (bandNameRaster == null) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } int newbandNo = -1; if (bandNameRaster.TryGetBandNoFromBandName(rno, out newbandNo)) { rnoCH = newbandNo; } if (bandNameRaster.TryGetBandNoFromBandName(irno, out newbandNo)) { irnoCH = newbandNo; } if (bandNameRaster.TryGetBandNoFromBandName(swirno, out newbandNo)) { swirnoCH = newbandNo; } //double VisibleZoom = Obj2Double(_argumentProvider.GetArg("Visible_Zoom")); //double FarInfraredZoom = Obj2Double(_argumentProvider.GetArg("FarInfrared_Zoom")); //double NDSIVisibleZoom = Obj2Double(_argumentProvider.GetArg("NDSIVisible_Zoom")); if (rnoCH == -1 || irnoCH == -1 || swirnoCH == -1) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } output = new UInt16[1][]; #region 计算LAI if (_progressTracker != null) { _progressTracker(5, "开始读取数据文件..."); } IRasterDataProvider lsrRaster = null; IRasterDataProvider angleRaster = null; IRasterDataProvider L2CLDMaskRaster = null; IRasterDataProvider landcoverRaster = null; int outwidth, outheight; try { #region 波段数据读取 if (_progressTracker != null) { _progressTracker(7, "正在读取地表反射率数据文件..."); } lsrRaster = GeoDataDriver.Open(L2LSRFile) as IRasterDataProvider; if (lsrRaster == null || lsrRaster.BandCount < 3) { return(null); } float prjReslX = lsrRaster.ResolutionX; float prjReslY = lsrRaster.ResolutionY; double prjMinLon = lsrRaster.CoordEnvelope.MinX; double prjMaxLat = lsrRaster.CoordEnvelope.MaxY; outwidth = lsrRaster.Width; outheight = lsrRaster.Height; UInt16[] reddata = GetDataValue <UInt16>(lsrRaster.GetRasterBand(rnoCH), 0, 0, outwidth, outheight); UInt16[] IRdata = GetDataValue <UInt16>(lsrRaster.GetRasterBand(irnoCH), 0, 0, outwidth, outheight); UInt16[] swirdata = GetDataValue <UInt16>(lsrRaster.GetRasterBand(swirnoCH), 0, 0, outwidth, outheight); if (_progressTracker != null) { _progressTracker(9, "正在读取角度数据文件..."); } Int16[] sza, saa, vza, vaa; angleRaster = GeoDataDriver.Open(_szafile) as IRasterDataProvider; if (angleRaster == null || angleRaster.BandCount < 1) { return(null); } sza = GetDataValue <Int16>(angleRaster.GetRasterBand(1), 0, 0, outwidth, outheight); angleRaster = GeoDataDriver.Open(_saafile) as IRasterDataProvider; if (angleRaster == null || angleRaster.BandCount < 1) { return(null); } saa = GetDataValue <Int16>(angleRaster.GetRasterBand(1), 0, 0, outwidth, outheight); angleRaster = GeoDataDriver.Open(_vzafile) as IRasterDataProvider; if (angleRaster == null || angleRaster.BandCount < 1) { return(null); } vza = GetDataValue <Int16>(angleRaster.GetRasterBand(1), 0, 0, outwidth, outheight); angleRaster = GeoDataDriver.Open(_vaafile) as IRasterDataProvider; if (angleRaster == null || angleRaster.BandCount < 1) { return(null); } vaa = GetDataValue <Int16>(angleRaster.GetRasterBand(1), 0, 0, outwidth, outheight); L2CLDMaskRaster = GeoDataDriver.Open(L2CLDMaskFile) as IRasterDataProvider; if (L2CLDMaskRaster == null || L2CLDMaskRaster.BandCount < 1) { return(null); } #region 计算云检测文件的xy偏移量; double CLDMaskminx = L2CLDMaskRaster.CoordEnvelope.MinX, CLDMaskmaxy = L2CLDMaskRaster.CoordEnvelope.MaxY; _prjCLDMSKxOffset = (int)Math.Ceiling((prjMinLon - CLDMaskminx) / prjReslX); _prjCLDMSKyOffset = (int)Math.Ceiling((CLDMaskmaxy - prjMaxLat) / prjReslY); #endregion byte[] cldmask = GetDataValue <byte>(L2CLDMaskRaster.GetRasterBand(1), _prjCLDMSKxOffset, _prjCLDMSKyOffset, outwidth, outheight); if (_progressTracker != null) { _progressTracker(11, "正在读取LandCover数据文件..."); } landcoverRaster = GeoDataDriver.Open(landCoverFile) as IRasterDataProvider; if (landcoverRaster == null || landcoverRaster.BandCount < 1) { return(null); } #endregion output[0] = new ushort[reddata.Length]; #region 分块并行处理 int parts = 7; int step = reddata.Length / parts; int[] istart = new int[parts]; int[] iend = new int[parts]; istart[0] = 0; iend[0] = 0 + step; for (int p = 1; p < parts; p++) { istart[p] = istart[p - 1] + step; iend[p] = iend[p - 1] + step; } iend[parts - 1] = reddata.Length; var tasks = new Action[] { () => CalPrjLAIParts(istart[0], iend[0], outwidth, cldmask, reddata, IRdata, swirdata, landcoverRaster, sza, saa, vza, vza, prjReslX, prjMinLon, prjMaxLat), () => CalPrjLAIParts(istart[1], iend[1], outwidth, cldmask, reddata, IRdata, swirdata, landcoverRaster, sza, saa, vza, vza, prjReslX, prjMinLon, prjMaxLat), () => CalPrjLAIParts(istart[2], iend[2], outwidth, cldmask, reddata, IRdata, swirdata, landcoverRaster, sza, saa, vza, vza, prjReslX, prjMinLon, prjMaxLat), () => CalPrjLAIParts(istart[3], iend[3], outwidth, cldmask, reddata, IRdata, swirdata, landcoverRaster, sza, saa, vza, vza, prjReslX, prjMinLon, prjMaxLat), () => CalPrjLAIParts(istart[4], iend[4], outwidth, cldmask, reddata, IRdata, swirdata, landcoverRaster, sza, saa, vza, vza, prjReslX, prjMinLon, prjMaxLat), () => CalPrjLAIParts(istart[5], iend[5], outwidth, cldmask, reddata, IRdata, swirdata, landcoverRaster, sza, saa, vza, vza, prjReslX, prjMinLon, prjMaxLat), () => CalPrjLAIParts(istart[6], iend[6], outwidth, cldmask, reddata, IRdata, swirdata, landcoverRaster, sza, saa, vza, vza, prjReslX, prjMinLon, prjMaxLat), }; if (_progressTracker != null) { _progressTracker(13, "正在逐点计算LAI,请稍候..."); } System.Threading.Tasks.Parallel.Invoke(tasks); #endregion #region 建立输出文件 if (_progressTracker != null) { _progressTracker(75, "正在输出LAI数据,请稍候..."); } return(OutputLAI(angleRaster, L2LSRFile, false)); #endregion } catch (System.Exception ex) { //_progressTracker(0, ex.Message); PrintInfo(ex.Message); return(null); } finally { if (lsrRaster != null) { lsrRaster.Dispose(); } if (angleRaster != null) { angleRaster.Dispose(); } if (landcoverRaster != null) { landcoverRaster.Dispose(); } if (L2CLDMaskRaster != null) { L2CLDMaskRaster.Dispose(); } if (output != null) { output = null; } } #endregion }
public static DoubtFirPixelFilter CreateDoubtFilter(IArgumentProvider argProvider, IContextMessage contextMessage) { int minWndSize = Obj2Int(argProvider.GetArg("BackWndMin")); int maxWndSize = Obj2Int(argProvider.GetArg("BackWndMax")); IBandNameRaster bandNameRaster = argProvider.DataProvider as IBandNameRaster; int visBandNo = TryGetBandNo(argProvider, bandNameRaster, "Visible"); int nearIfrBandNo = TryGetBandNo(argProvider, bandNameRaster, "NearInfrared"); int midIfrBandNo = TryGetBandNo(argProvider, bandNameRaster, "MiddleInfrared"); int farIfrBandNo = TryGetBandNo(argProvider, bandNameRaster, "FarInfrared"); bool isNight = bool.Parse(argProvider.GetArg("IsNight").ToString()); if (!isNight && (visBandNo < 1 || midIfrBandNo < 1 || farIfrBandNo < 1 || nearIfrBandNo < 1)) { PrintInfo(contextMessage, " 获取波段序号(可见光、近红外、中红外、远红外)时发生错误。"); return(null); } else if (isNight && (farIfrBandNo < 1 || midIfrBandNo < 1)) { PrintInfo(contextMessage, " 获取波段序号(可见光、近红外、中红外、远红外)时发生错误。"); return(null); } float bandZoom = Obj2Float(argProvider.GetArg("MiddleInfrared_Zoom")); int hitedPixelCount = Obj2Int(argProvider.GetArg("HitedPixelCount")); ISolarZenithProvider solarZentihProvider = null; float minSolarZentih = Obj2Float(argProvider.GetArg("BackTSolarZenith")); if (bandZoom < float.Epsilon) { PrintInfo(contextMessage, " 波段数值缩放参数设置错误,使用缺省值1。"); } //water int minMidInfraredValue_water = Obj2Int(argProvider.GetArg("Water_MinMidIfr")); int minNearInfraredValue_water = Obj2Int(argProvider.GetArg("Water_MinNearIfr")); int nearInfrared_visibleValue_water = Obj2Int(argProvider.GetArg("Water_NearIfr_Vis")); //cloud int minVisibleValue_cloud = Obj2Int(argProvider.GetArg("Cloud_MinVis")); int farInfraredValue_cloud = Obj2Int(argProvider.GetArg("Cloud_FarIfr")); //doubt int midInfraredValue_DoubtFir = Obj2Int(argProvider.GetArg("Doubt_MidIfr")); int dltMidInfraredValue_DoubtFir = Obj2Int(argProvider.GetArg("Doubt_MidIfr_Diff")); int midInfrared_farInfrared_DoubtFir = Obj2Int(argProvider.GetArg("Doubt_MidIfr_FarIfr")); int minMidInfraredValue_DoubtFir = Obj2Int(argProvider.GetArg("Doubt_MinMidIfr")); int maxHTmpPixelCount_DoubtFir = Obj2Int(argProvider.GetArg("Doubt_MaxHTmpPixelCount")); int midInfraredAvg_DoubtFir = Obj2Int(argProvider.GetArg("Doubt_MidIfrAvg")); // DoubtFirPixelFilter filter = new DoubtFirPixelFilter ( //wnd size minWndSize, maxWndSize, //bandNo farIfrBandNo, midIfrBandNo, nearIfrBandNo, visBandNo, //zoom bandZoom, solarZentihProvider, // hitedPixelCount, minSolarZentih, //water minMidInfraredValue_water, minNearInfraredValue_water, nearInfrared_visibleValue_water, //cloud minVisibleValue_cloud, farInfraredValue_cloud, //doubt fir midInfraredValue_DoubtFir, dltMidInfraredValue_DoubtFir, midInfrared_farInfrared_DoubtFir, minMidInfraredValue_DoubtFir, maxHTmpPixelCount_DoubtFir, midInfraredAvg_DoubtFir ); return(filter); }
public override IExtractResult Make(Action <int, string> progressTracker, IContextMessage contextMessage) { _contextMessage = contextMessage; string express = ""; List <int> bandNos = new List <int>(); if (_argumentProvider == null || _argumentProvider.DataProvider == null) { return(null); } IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster; object obj = _argumentProvider.GetArg("AlgorithmName"); string argName = obj == null ? null : obj.ToString(); if (string.IsNullOrEmpty(argName)) { PrintInfo("参数\"AlgorithmName\"为空。"); return(null); } switch (argName) { case "SunDay1": { int bandNo = TryGetBandNo(bandNameRaster, "NearInfrared"); double nearInfraredZoom = (double)_argumentProvider.GetArg("NearInfrared_Zoom"); //配置文件中设置为float类型,但有时为float类型,有时为double型 //double shortInfraredMin = (double)_argumentProvider.GetArg("ShortInfraredMin"); //double shortInfraredMax = (double)_argumentProvider.GetArg("ShortInfraredMax"); if (bandNo <= 0 || nearInfraredZoom == 0) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } bandNos.Add(bandNo); express = "(band" + bandNo + "/" + nearInfraredZoom + ">" + _argumentProvider.GetArg("ShortInfraredMin") + ")&&(band" + bandNo + "/" + nearInfraredZoom + "<" + _argumentProvider.GetArg("ShortInfraredMax") + ")"; break; } case "SunDay2": { int visibleNo = TryGetBandNo(bandNameRaster, "Visible"); int nearInfraredNo = TryGetBandNo(bandNameRaster, "NearInfrared"); double visibleZoom = (double)_argumentProvider.GetArg("Visible_Zoom"); double nearInfraredZoom = (double)_argumentProvider.GetArg("NearInfrared_Zoom"); if (visibleNo <= 0 || nearInfraredNo <= 0 || visibleZoom == 0 || nearInfraredZoom == 0) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } bandNos.Add(visibleNo); bandNos.Add(nearInfraredNo); express = "((band" + nearInfraredNo + "/" + nearInfraredZoom + "-band" + visibleNo + "/" + visibleZoom + ")<" + _argumentProvider.GetArg("NearInfraredVisibleMax") + " && (band" + nearInfraredNo + "/" + nearInfraredZoom + ")<" + _argumentProvider.GetArg("NearInfraredMax") + " && (band" + visibleNo + "/" + visibleZoom + ")<" + _argumentProvider.GetArg("VisibleMax") + ")"; break; } case "Night": { int nightFarInfraredNo = TryGetBandNo(bandNameRaster, "FarInfrared"); double nightFarInfraredZoom = (double)_argumentProvider.GetArg("FarInfrared_Zoom"); if (nightFarInfraredNo <= 0) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } bandNos.Add(nightFarInfraredNo); express = "((band" + nightFarInfraredNo + "/" + nightFarInfraredZoom + ")>" + _argumentProvider.GetArg("FarInfraredMin") + @" && (band" + nightFarInfraredNo + "/" + nightFarInfraredZoom + ")<" + _argumentProvider.GetArg("FarInfraredMax") + ")"; break; } case "ThinCloud": { int visibleNo = TryGetBandNo(bandNameRaster, "Visible"); int nearInfraredNo = TryGetBandNo(bandNameRaster, "NearInfrared"); double visibleZoom = (double)_argumentProvider.GetArg("Visible_Zoom"); double nearInfraredZoom = (double)_argumentProvider.GetArg("NearInfrared_Zoom"); if (visibleNo <= 0 || nearInfraredNo <= 0 || visibleZoom == 0 || nearInfraredZoom == 0) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } bandNos.Add(visibleNo); bandNos.Add(nearInfraredNo); express = "(band" + visibleNo + "==0)?false:((((float)band" + nearInfraredNo + "/" + nearInfraredZoom + ")/(band" + visibleNo + "/" + visibleZoom + ")>" + _argumentProvider.GetArg("NearInfraredVisibleMin") + ")&&(((float)band" + nearInfraredNo + "/" + nearInfraredZoom + ")/(band" + visibleNo + "/" + visibleZoom + ")<" + _argumentProvider.GetArg("NearInfraredVisibleMax") + "))"; break; } case "Fog": { int middleInfraredNo = TryGetBandNo(bandNameRaster, "MiddleInfrared"); int farInfraredNo = TryGetBandNo(bandNameRaster, "FarInfrared"); double fogMiddleInfraredZoom = (double)_argumentProvider.GetArg("MiddleInfrared_Zoom"); double fogFarInfraredZoom = (double)_argumentProvider.GetArg("FarInfrared_Zoom"); if (middleInfraredNo <= 0 || farInfraredNo <= 0 || fogFarInfraredZoom == 0 || fogMiddleInfraredZoom == 0) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } object midFar = _argumentProvider.GetArg("MiddleInfraredFarInfrared"); float value = float.MinValue; if (!float.TryParse(midFar.ToString(), out value)) { PrintInfo("亮温差不在合法范围内,请重新获取。"); return(null); } bandNos.Add(middleInfraredNo); bandNos.Add(farInfraredNo); express = "(band" + middleInfraredNo + "/" + fogMiddleInfraredZoom + "-band" + farInfraredNo + "/" + fogFarInfraredZoom + ")>" + value; break; } case "NDVI": { int visibleNo = TryGetBandNo(bandNameRaster, "Visible"); int nearInfraredNo = TryGetBandNo(bandNameRaster, "NearInfrared"); double ndviVisibleZoom = (double)_argumentProvider.GetArg("Visible_Zoom"); double ndvitcNearInfraredZoom = (double)_argumentProvider.GetArg("NearInfrared_Zoom"); if (visibleNo <= 0 || nearInfraredNo <= 0 || ndvitcNearInfraredZoom == 0 || ndvitcNearInfraredZoom == 0) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } bandNos.Add(visibleNo); bandNos.Add(nearInfraredNo); express = "(band" + nearInfraredNo + "/" + ndvitcNearInfraredZoom + "+band" + visibleNo + "/" + ndviVisibleZoom + ")==0?false:((band" + nearInfraredNo + "/" + ndvitcNearInfraredZoom + "-band" + visibleNo + "/" + ndviVisibleZoom + ")" + " /(float)(band" + nearInfraredNo + "/" + ndvitcNearInfraredZoom + "+band" + visibleNo + "/" + ndviVisibleZoom + ")>" + _argumentProvider.GetArg("VisibleNearInfraredMin") + ")&&((band" + nearInfraredNo + "/" + ndvitcNearInfraredZoom + "-band" + visibleNo + "/" + ndviVisibleZoom + ")" + "/(float)(band" + nearInfraredNo + "/" + ndvitcNearInfraredZoom + "+band" + visibleNo + "/" + ndviVisibleZoom + ")<" + _argumentProvider.GetArg("VisibleNearInfraredMax") + ")"; break; } case "GFProcess": { int bandNo = TryGetBandNo(bandNameRaster, "band"); double bandZoom = (double)_argumentProvider.GetArg("band_Zoom"); if (bandNo <= 0 || bandZoom <= 0) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } bandNos.Add(bandNo); express = "((band" + bandNo + "/" + bandZoom + ")>=" + _argumentProvider.GetArg("band1Min") + ")&&((band" + bandNo + "/" + bandZoom + ")<" + _argumentProvider.GetArg("band1Max") + ")"; break; } default: { PrintInfo("指定的算法\"" + argName + "\"没有实现。"); return(null); } } IThresholdExtracter <UInt16> extracter = new SimpleThresholdExtracter <UInt16>(); extracter.Reset(_argumentProvider, bandNos.ToArray(), express); IRasterDataProvider prd = _argumentProvider.DataProvider; IPixelIndexMapper resultFLD = PixelIndexMapperFactory.CreatePixelIndexMapper("FLD", prd.Width, prd.Height, prd.CoordEnvelope, prd.SpatialRef); extracter.Extract(resultFLD); CreateStageAreaInfo(); return(resultFLD); }
private IExtractResult ComputeVisibility() { if (_argumentProvider.DataProvider == null) { PrintInfo("请提供沙尘影像数据!"); return(null); } IRasterDataProvider prd = _argumentProvider.DataProvider; int[] aois = GetAOIByBinaryFile(); if (aois != null && aois.Length != 0) { _argumentProvider.AOI = aois; } int visiNo = -1, nearNo = -1, shortNo = -1, farNo = -1; IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster; // visiNo = TryGetBandNo(bandNameRaster, "Visible"); //(int)_argumentProvider.GetArg("Visible"); nearNo = TryGetBandNo(bandNameRaster, "NearInfrared"); //(int)_argumentProvider.GetArg("NearInfrared"); shortNo = TryGetBandNo(bandNameRaster, "ShortInfrared"); //(int)_argumentProvider.GetArg("ShortInfrared"); farNo = TryGetBandNo(bandNameRaster, "FarInfrared"); //(int)_argumentProvider.GetArg("FarInfrared"); double visiZoom = (double)_argumentProvider.GetArg("Visible_Zoom"); double nearZoom = (double)_argumentProvider.GetArg("NearInfrared_Zoom"); double shortZoom = (double)_argumentProvider.GetArg("ShortInfrared_Zoom"); double farZoom = (double)_argumentProvider.GetArg("FarInfrared_Zoom"); if (visiNo == -1 || nearNo == -1 || shortNo == -1 || farNo == -1 || visiZoom == -1 || farZoom == -1 || shortZoom == -1) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } int bandCount = prd.BandCount; if (visiNo > bandCount) { PrintInfo("可见光波段序号超过数据的波段范围,可能是影像数据选择不正确。"); return(null); } if (nearNo > bandCount) { PrintInfo("近红外波段序号超过数据的波段范围,可能是影像数据选择不正确。"); return(null); } if (shortNo > bandCount) { PrintInfo("短波红外波段序号超过数据的波段范围,可能是影像数据选择不正确。"); return(null); } if (farNo > bandCount) { PrintInfo("远红外波段序号超过数据的波段范围,可能是影像数据选择不正确。"); return(null); } int[] bandNos = new int[] { visiNo, nearNo, shortNo, farNo }; string express = "(UInt16)Math.Round(1000 * Math.Pow(Math.E,(var_VisibilityA + var_VisibilityB * band" + visiNo + " / " + visiZoom + "f + var_VisibilityC * band" + nearNo + "/" + nearZoom + "f + var_VisibilityD * band" + shortNo + "/" + shortZoom + "f + var_VisibilityE * band" + farNo + "/" + farZoom + "f + var_VisibilityF *(band" + shortNo + "/" + shortZoom + "f - band" + farNo + "/" + farZoom + "f + var_ShortFarVar))),0)"; IRasterExtracter <UInt16, UInt16> extracter = new SimpleRasterExtracter <UInt16, UInt16>(); extracter.Reset(_argumentProvider, bandNos, express); IPixelFeatureMapper <UInt16> result = new MemPixelFeatureMapper <UInt16>("Visibility", 1000, new Size(prd.Width, prd.Height), prd.CoordEnvelope, prd.SpatialRef); extracter.Extract(result); return(result); }
private IExtractResult EVIAlgorithm1(Action <int, string> progressTracker) { int bands = _argumentProvider.DataProvider.BandCount; if (bands == 0 || bands == 1) { PrintInfo("请选择正确的局地文件进行计算。"); return(null); } if (_argumentProvider.GetArg("Visible") == null) { PrintInfo("参数\"Visible\"为空。"); return(null); } IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster; int bandV = TryGetBandNo(bandNameRaster, "Visible"); if (_argumentProvider.GetArg("NearInfrared") == null) { PrintInfo("参数\"NearInfrared\"为空。"); return(null); } int bandN = TryGetBandNo(bandNameRaster, "NearInfrared"); if (_argumentProvider.GetArg("Blue") == null) { PrintInfo("参数\"Blue\"为空。"); return(null); } int bandB = TryGetBandNo(bandNameRaster, "Blue"); if (bandV < 1 || bandB < 1 || bandN < 1 || bandV > bands || bandB > bands || bandN > bands) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } int bandMid = TryGetBandNo(bandNameRaster, "MiddInfrared"); //中红外 int bandFar = TryGetBandNo(bandNameRaster, "FarInfrared11"); //远红外 if (_argumentProvider.GetArg("Visible_Zoom") == null) { PrintInfo("参数\"Visible_Zoom\"为空。"); return(null); } double visibleZoom = (double)_argumentProvider.GetArg("Visible_Zoom"); if (_argumentProvider.GetArg("NearInfrared_Zoom") == null) { PrintInfo("参数\"NearInfrared_Zoom\"为空。"); return(null); } double nearInfrared = (double)_argumentProvider.GetArg("NearInfrared_Zoom"); if (_argumentProvider.GetArg("Blue_Zoom") == null) { PrintInfo("参数\"Blue_Zoom\"为空。"); return(null); } double blueZoom = (double)_argumentProvider.GetArg("Blue_Zoom"); double middZoom = (double)_argumentProvider.GetArg("MiddInfrared_Zoom"); double farZoom = (double)_argumentProvider.GetArg("FarInfrared11_Zoom"); int[] bandNos = new int[] { bandV, bandN, bandB, bandMid, bandFar }; double[] bandZoom = new double[] { visibleZoom, nearInfrared, blueZoom, middZoom, farZoom }; float NearInfraredCLMMin = float.Parse(_argumentProvider.GetArg("NearInfraredCLMMin").ToString()); float FarInfrared11CLMMax = float.Parse(_argumentProvider.GetArg("FarInfrared11CLMMax").ToString()); float FarInfrared1112CLMMin = float.Parse(_argumentProvider.GetArg("FarInfrared1112CLMMin").ToString()); float[] cloudyArgs = new float[] { NearInfraredCLMMin, FarInfrared11CLMMax, FarInfrared1112CLMMin }; Int16 defCloudy = (Int16)_argumentProvider.GetArg("defCloudy"); float zoom = (ushort)_argumentProvider.GetArg("resultZoom"); zoom = zoom == 0f ? 1000 : zoom; string[] aois = _argumentProvider.GetArg("AOITemplate") as string[]; string aoiTemplate = (aois == null || aois.Length == 0) ? null : aois[0]; string[] inputFiles = GetStringArray("RasterFile"); if (inputFiles == null || inputFiles.Length == 0) { PrintInfo("没有设置输入数据"); return(null); } bool isFitterCloud; if (!bool.TryParse(_argumentProvider.GetArg("isFilterCloudy").ToString(), out isFitterCloud)) { PrintInfo("是否过滤云参数设置不正确!"); return(null); } IExtractResultArray results = new ExtractResultArray("EVI"); foreach (string inputFile in inputFiles) { //计算RVI IExtractResult ret = CalcEVIAlgorithm1(inputFile, bandNos, zoom, bandZoom, cloudyArgs, defCloudy, isFitterCloud, aoiTemplate, progressTracker); if (ret != null) { results.Add(ret as IExtractResultBase); } } return(results); }
public IExtractResult GetBAG() { double visiBandRoom = (double)_argumentProvider.GetArg("Visible_Zoom"); double niBandRoom = (double)_argumentProvider.GetArg("NearInfrared_Zoom"); bool needcloud = (bool)_argumentProvider.GetArg("isAppCloud"); UCSetNearTool uccontrl = _argumentProvider.GetArg("UCSetNearTool") as UCSetNearTool; if (uccontrl.ckbone.Checked) { uccontrl.btnGetAOIIndex(null, null); } MinNear = double.Parse(uccontrl.txtnearmin.Text) * 100;//放大调节 跟界面参数设置有关 IRasterDataProvider prd = _argumentProvider.DataProvider; if (prd == null) { PrintInfo("未能获取当前影像数据。"); return(null); } IBandNameRaster bandNameRaster = prd as IBandNameRaster; int visiBandNo = TryGetBandNo(bandNameRaster, "Visible"); int niBandNo = TryGetBandNo(bandNameRaster, "NearInfrared"); int shortBandNo = TryGetBandNo(bandNameRaster, "ShortInfrared"); if (visiBandNo == -1 || niBandNo == -1 || visiBandRoom == -1 || niBandRoom == -1) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } string express = string.Format("band{0}/{1}f" + " >= " + MinNear, niBandNo, niBandRoom); string cloudexpress = GetCloudExpress(); if (needcloud) { express = string.Format("{0} && ({1})", express, cloudexpress); } int[] bandNos = new int[] { visiBandNo, niBandNo, shortBandNo }; IThresholdExtracter <UInt16> extracter = new SimpleThresholdExtracter <UInt16>(); extracter.Reset(_argumentProvider, bandNos, express); int width = prd.Width; int height = prd.Height; IPixelIndexMapper memResult = PixelIndexMapperFactory.CreatePixelIndexMapper("BAG", width, height, prd.CoordEnvelope, prd.SpatialRef); extracter.Extract(memResult); memResult.Tag = new BagFeatureCollection("蓝藻辅助信息", GetDisplayInfo(memResult, visiBandNo, niBandNo)); //计算NDVI文件 IPixelFeatureMapper <float> ndvi = null; try { ndvi = ComputeNDVIResult(_argumentProvider.DataProvider, memResult, visiBandNo, niBandNo); IExtractResultBase bPCDResult = CreatPixelCoverRate(ndvi); ExtractResultArray results = new ExtractResultArray("BAG_BINS"); results.Add(memResult); //results.Add(ndvi); results.Add(bPCDResult); return(results); } finally { if (ndvi != null) { ndvi.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 != "FLMX") { 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); } } IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster; int bandNo = TryGetBandNo(bandNameRaster, "FIFLBandNo"); if (bandNo == -1) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } //输入文件准备 List <RasterMaper> rms = new List <RasterMaper>(); try { for (int i = 0; i < fileNames.Length; i++) { IRasterDataProvider inRaster = RasterDataDriver.Open(fileNames[i]) as IRasterDataProvider; if (inRaster.BandCount < bandNo) { PrintInfo("请选择正确的数据进行最大值合成,请检查文件[" + fileNames[i] + "]."); return(null); } RasterMaper rm = new RasterMaper(inRaster, new int[] { bandNo }); rms.Add(rm); } //输出文件准备(作为输入栅格并集处理) RasterIdentify ri = GetRasterIdentifyID(fileNames); string outFileName = ri.ToWksFullFileName(".dat"); 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 = null; rfr = new RasterProcessModel <Int16, Int16>(progressTracker); rfr.SetRaster(fileIns, fileOuts); Int16[] nanValues = GetNanValues("CloudyValue"); Int16[] waterValues = GetNanValues("WaterValue"); Int16[] invailValues = GetNanValues("InvailValue"); rfr.RegisterCalcModel(new RasterCalcHandler <Int16, Int16>((rvInVistor, rvOutVistor, aoi) => { int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX; Int16[] maxData = new Int16[dataLength]; for (int i = 0; i < dataLength; i++) { maxData[i] = Int16.MinValue; } for (int index = 0; index < dataLength; index++) { foreach (RasterVirtualVistor <Int16> rvs in rvInVistor) { Int16[] dt = rvs.RasterBandsData[0]; if (dt == null) { continue; } if (invailValues.Contains(dt[index])) { continue; } if (IsMaxValue(dt[index], nanValues, waterValues, maxData[index])) { maxData[index] = dt[index]; } } } for (int index = 0; index < dataLength; index++) { rvOutVistor[0].RasterBandsData[0][index] = maxData[index]; } })); //执行 rfr.Excute(Int16.MinValue); FileExtractResult res = new FileExtractResult(_subProductDef.Identify, outFileName, true); res.SetDispaly(false); return(res); } } finally { foreach (RasterMaper rm in rms) { rm.Raster.Dispose(); } } }
private IExtractResult ComputeByCurrentRaster(IRasterDataProvider currPrd, Action <int, string> progressTracker) { currPrd = currPrd != null ? currPrd : _argumentProvider.DataProvider; if (currPrd == null) { return(null); } IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster;// int VisibleCH = TryGetBandNo(bandNameRaster, "RedBand"); int NearInfraredCH = TryGetBandNo(bandNameRaster, "NirBand"); int FarInfrared11CH = TryGetBandNo(bandNameRaster, "FarBand"); double VisibleZoom = (double)_argumentProvider.GetArg("RedBand_Zoom"); double NearInfraredZoom = (double)_argumentProvider.GetArg("NirBand_Zoom"); double FarInfrared11Zoom = (double)_argumentProvider.GetArg("FarBand_Zoom"); bool isAutoCloud = (bool)_argumentProvider.GetArg("isAutoCloud"); bool isAppCloud = (bool)_argumentProvider.GetArg("isAppCloud"); if (VisibleCH == -1 || NearInfraredCH == -1 || (isAutoCloud && FarInfrared11CH == -1)) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } float pdiZoom = (float)_argumentProvider.GetArg("PDIZoom"); Int16 defCloudy = (Int16)_argumentProvider.GetArg("defCloudy"); Int16 defWater = (Int16)_argumentProvider.GetArg("defWater"); Int16 InvaildValue = (Int16)_argumentProvider.GetArg("InvaildValue"); float NearInfraredCLMMin = float.Parse(_argumentProvider.GetArg("NearInfraredCLMMin").ToString()); float FarInfrared11CLMMax = float.Parse(_argumentProvider.GetArg("FarInfrared11CLMMax").ToString()); float FarInfrared11WaterMin = float.Parse(_argumentProvider.GetArg("FarInfrared11WaterMin").ToString()); float NDVIWaterMax = float.Parse(_argumentProvider.GetArg("NDVIWaterMax").ToString()); int cloudCH = (int)_argumentProvider.GetArg("CLMBand"); string clmFile = GetClmFile(currPrd); float RegionExp1 = (float)_argumentProvider.GetArg("RegionExp1"); float RegionExp2 = (float)_argumentProvider.GetArg("RegionExp2"); DRTExpCoefficientCollection ExpCoefficient = _argumentProvider.GetArg("ExpCoefficient") as DRTExpCoefficientCollection; string EdgesFile = ExpCoefficient.EgdesFilename; int bandNo = TryGetBandNo(bandNameRaster, "DemBand"); string[] aois = _argumentProvider.GetArg("AOITemplate") as string[]; string aoiTemplate = (aois == null || aois.Length == 0) ? null : aois[0]; //输入文件准备 List <RasterMaper> rms = new List <RasterMaper>(); IRasterDataProvider currRaster = null; IRasterDataProvider edgeRaster = null; IRasterDataProvider clmPrd = null; try { currRaster = currPrd; if (currRaster.BandCount < VisibleCH || currRaster.BandCount < NearInfraredCH || (isAutoCloud && currRaster.BandCount < FarInfrared11CH)) { PrintInfo("请选择正确的数据进行垂直干旱指数计算。"); return(null); } RasterMaper rmCurr = new RasterMaper(currRaster, new int[] { VisibleCH, NearInfraredCH, FarInfrared11CH }); rms.Add(rmCurr); bool isContainEdgesFile = false; if (!string.IsNullOrEmpty(EdgesFile) && File.Exists(EdgesFile)) { edgeRaster = RasterDataDriver.Open(EdgesFile) as IRasterDataProvider; if (edgeRaster.BandCount < bandNo) { PrintInfo("请正确选择经验系数中的边界文件,波段数不足!"); return(null); } RasterMaper rmEdge = new RasterMaper(edgeRaster, new int[] { bandNo }); rms.Add(rmEdge); isContainEdgesFile = true; } bool isContainClm = false; if (isAppCloud && !string.IsNullOrEmpty(clmFile) && File.Exists(clmFile)) { clmPrd = GeoDataDriver.Open(clmFile) as IRasterDataProvider; if (clmPrd.BandCount < cloudCH) { PrintInfo("请选择正确的云数据进行计算,波段数不足!"); return(null); } RasterMaper clmRm = new RasterMaper(clmPrd, new int[] { cloudCH }); rms.Add(clmRm); isContainClm = true; } float curNDVI = 0f; //输出文件准备(作为输入栅格并集处理) string outFileName = GetFileName(new string[] { currRaster.fileName }, _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 <Int16, Int16> rfr = null; rfr = new RasterProcessModel <Int16, Int16>(progressTracker); rfr.SetRaster(fileIns, fileOuts); rfr.SetTemplateAOI(aoiTemplate); DRTExpCoefficientItem item = null; int demCode = -1; rfr.RegisterCalcModel(new RasterCalcHandler <Int16, Int16>((rvInVistor, rvOutVistor, aoi) => { if (rvInVistor[0] == null || rvInVistor[0].RasterBandsData[0] == null || (isContainEdgesFile && (rvInVistor[1] == null || rvInVistor[1].RasterBandsData[0] == null)) || (isContainClm && (rvInVistor[2 - (isContainEdgesFile ? 0 : 1)] == null || rvInVistor[2 - (isContainEdgesFile ? 0 : 1)].RasterBandsData[0] == null))) { return; } int dataLength = aoi == null || aoi.Length == 0 ? rvOutVistor[0].SizeY * rvOutVistor[0].SizeX : aoi.Length; for (int i = 0; i < dataLength; i++) { int index = aoi == null || aoi.Length == 0 ? i : aoi[i]; Int16 visiableValue = rvInVistor[0].RasterBandsData[0][index]; Int16 nearInfraredValue = rvInVistor[0].RasterBandsData[1][index]; Int16 farInfraredVale = rvInVistor[0].RasterBandsData[2][index]; if (isContainEdgesFile && rvInVistor[1].RasterBandsData[0] != null) { demCode = (int)rvInVistor[1].RasterBandsData[0][index]; } else { demCode = -1; } curNDVI = GetNDVI(nearInfraredValue, visiableValue); if (visiableValue == 0 && nearInfraredValue == 0) { rvOutVistor[0].RasterBandsData[0][index] = InvaildValue; } else if (isContainClm && rvInVistor[2 - (isContainEdgesFile ? 0 : 1)].RasterBandsData[0][index] != 0) { rvOutVistor[0].RasterBandsData[0][index] = defCloudy; } else if (isAutoCloud && (nearInfraredValue / NearInfraredZoom > NearInfraredCLMMin && farInfraredVale / FarInfrared11Zoom < FarInfrared11CLMMax)) { rvOutVistor[0].RasterBandsData[0][index] = defCloudy; } else { if (farInfraredVale / FarInfrared11Zoom > FarInfrared11WaterMin && curNDVI < NDVIWaterMax) { rvOutVistor[0].RasterBandsData[0][index] = defWater; } else { item = ExpCoefficient.GetExpItemByNum(demCode); if (item == null) { rvOutVistor[0].RasterBandsData[0][index] = (Int16)((visiableValue / VisibleZoom + RegionExp1 * nearInfraredValue / NearInfraredZoom) / Math.Sqrt(RegionExp2 * RegionExp2 + 1) * pdiZoom); } else { rvOutVistor[0].RasterBandsData[0][index] = (Int16)((visiableValue / VisibleZoom + item.APara * nearInfraredValue / NearInfraredZoom) / Math.Sqrt(item.BPara * item.BPara + 1) * pdiZoom); } } } } })); //执行 rfr.Excute(); IFileExtractResult pdiFile = new FileExtractResult(_subProductDef.Identify, outFileName, true); pdiFile.SetDispaly(false); return(pdiFile); } } finally { if (clmPrd != null) { clmPrd.Dispose(); } if (edgeRaster != null) { edgeRaster.Dispose(); } } }
private IExtractResult CYCAAlgorithm(Action <int, string> progressTracker) { 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); } RegionArg args = _argumentProvider.GetArg("RegionArgs") as RegionArg; if (args == null) { PrintInfo("请点击\"确定\"按钮,以确定周期参数设置完毕!"); return(null); } if (progressTracker != null) { progressTracker.Invoke(10, "正在整理文件列表,请稍后..."); } CYCAFileListInfo cycaFileInfo = GeneralCYCAFileList.GeneralFileList(files, args, _subProductDef, "DBLV"); if (cycaFileInfo == null || cycaFileInfo.OutFilename.Count == 0) { return(null); } UInt16[] cloudValues = GetNanValues("CloudyValue"); UInt16[] waterValues = GetNanValues("WaterValue"); IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster;// int bandNo = TryGetBandNo(bandNameRaster, "LstBand"); IExtractResultArray array = new ExtractResultArray("LST"); if (cycaFileInfo.Days001Files != null && cycaFileInfo.Days001Files.Count != 0) { if (progressTracker != null) { progressTracker.Invoke(25, "正在处理日数据,请稍后..."); } foreach (string key in cycaFileInfo.Days001Files.Keys) { array.Add(LSTDataProcessor.DataProcessor(progressTracker, _contextMessage, args.CK001Days, cycaFileInfo.Days001Files[key].ToArray(), bandNo, _subProductDef.Identify, cloudValues, waterValues, cycaFileInfo.OutFilename[key], args.CycType) as FileExtractResult); } } if (cycaFileInfo.Days007Files != null && cycaFileInfo.Days007Files.Count != 0) { if (progressTracker != null) { progressTracker.Invoke(40, "正在处理周数据,请稍后..."); } foreach (string key in cycaFileInfo.Days007Files.Keys) { array.Add(LSTDataProcessor.DataProcessor(progressTracker, _contextMessage, args.CK007Days, cycaFileInfo.Days007Files[key].ToArray(), bandNo, _subProductDef.Identify, cloudValues, waterValues, cycaFileInfo.OutFilename[key], args.CycType) as FileExtractResult); } } if (cycaFileInfo.Days010Files != null && cycaFileInfo.Days010Files.Count != 0) { if (progressTracker != null) { progressTracker.Invoke(55, "正在处理旬数据,请稍后..."); } foreach (string key in cycaFileInfo.Days010Files.Keys) { array.Add(LSTDataProcessor.DataProcessor(progressTracker, _contextMessage, args.CK010Days, cycaFileInfo.Days010Files[key].ToArray(), bandNo, _subProductDef.Identify, cloudValues, waterValues, cycaFileInfo.OutFilename[key], args.CycType) as FileExtractResult); } } if (cycaFileInfo.Days030Files != null && cycaFileInfo.Days030Files.Count != 0) { if (progressTracker != null) { progressTracker.Invoke(70, "正在处理月数据,请稍后..."); } foreach (string key in cycaFileInfo.Days030Files.Keys) { array.Add(LSTDataProcessor.DataProcessor(progressTracker, _contextMessage, args.CK030Days, cycaFileInfo.Days030Files[key].ToArray(), bandNo, _subProductDef.Identify, cloudValues, waterValues, cycaFileInfo.OutFilename[key], args.CycType) as FileExtractResult); } } if (cycaFileInfo.Days090Files != null && cycaFileInfo.Days090Files.Count != 0) { if (progressTracker != null) { progressTracker.Invoke(80, "正在处理季数据,请稍后..."); } foreach (string key in cycaFileInfo.Days090Files.Keys) { array.Add(LSTDataProcessor.DataProcessor(progressTracker, _contextMessage, args.CK090Days, cycaFileInfo.Days090Files[key].ToArray(), bandNo, _subProductDef.Identify, cloudValues, waterValues, cycaFileInfo.OutFilename[key], args.CycType) as FileExtractResult); } } if (cycaFileInfo.Days365Files != null && cycaFileInfo.Days365Files.Count != 0) { if (progressTracker != null) { progressTracker.Invoke(90, "正在处理年数据,请稍后..."); } foreach (string key in cycaFileInfo.Days365Files.Keys) { array.Add(LSTDataProcessor.DataProcessor(progressTracker, _contextMessage, args.CK365Days, cycaFileInfo.Days365Files[key].ToArray(), bandNo, _subProductDef.Identify, cloudValues, waterValues, cycaFileInfo.OutFilename[key], args.CycType) as FileExtractResult); } } return(array); }
public override IExtractResult Make(Action <int, string> progressTracker, IContextMessage contextMessage) { _contextMessage = contextMessage; if (_argumentProvider == null || _argumentProvider.DataProvider == null) { return(null); } string algname = _argumentProvider.GetArg("AlgorithmName").ToString(); if (algname == "BAGExtract_New") { //return GetBAG(); return(GetCloudBAG()); } if (!string.IsNullOrEmpty(algname)) { double visiBandRoom = (double)_argumentProvider.GetArg("Visible_Zoom"); double niBandRoom = (double)_argumentProvider.GetArg("NearInfrared_Zoom"); if (algname == "BAGExtract") { MinNDVI = (double)_argumentProvider.GetArg("NDVIMin"); MaxNDVI = (double)_argumentProvider.GetArg("NDVIMax"); } else if (algname == "BAGExtract_Test") { UCSetNDVITool uccontrl = _argumentProvider.GetArg("ucSetNDVITool") as UCSetNDVITool; if (uccontrl.ckbaoi.Checked) { uccontrl.btnGetAOIIndex(null, null); } else { MinNDVI = uccontrl.txtndvimin.Value; MaxNDVI = uccontrl.txtndvimax.Value; } } IRasterDataProvider prd = _argumentProvider.DataProvider; if (prd == null) { PrintInfo("未能获取当前影像数据。"); return(null); } IBandNameRaster bandNameRaster = prd as IBandNameRaster; int visiBandNo = TryGetBandNo(bandNameRaster, "Visible"); int niBandNo = TryGetBandNo(bandNameRaster, "NearInfrared"); if (visiBandNo == -1 || niBandNo == -1 || visiBandRoom == -1 || niBandRoom == -1) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } string express = string.Format(@"({0}==0||{1}==0 )? false :((float)(band{3}/{1}f - band{2}/{0}f) / (band{2}/{0}f+ band{3}/{1}f) < {5}) && ((float)(band{3} /{1}f- band{2}/{0}f) / (band{3}/{1}f + band{2}/{0}f) > {4})", visiBandRoom, niBandRoom, visiBandNo, niBandNo, MinNDVI, MaxNDVI); int[] bandNos = new int[] { visiBandNo, niBandNo }; IThresholdExtracter <UInt16> extracter = new SimpleThresholdExtracter <UInt16>(); extracter.Reset(_argumentProvider, bandNos, express); int width = prd.Width; int height = prd.Height; IPixelIndexMapper memResult = PixelIndexMapperFactory.CreatePixelIndexMapper("BAG", width, height, prd.CoordEnvelope, prd.SpatialRef); extracter.Extract(memResult); memResult.Tag = new BagFeatureCollection("蓝藻辅助信息", GetDisplayInfo(memResult, visiBandNo, niBandNo)); //计算NDVI文件 IPixelFeatureMapper <float> ndvi = null; try { ndvi = ComputeNDVIResult(_argumentProvider.DataProvider, memResult, visiBandNo, niBandNo); IExtractResultBase bPCDResult = CreatPixelCoverRate(ndvi); ExtractResultArray results = new ExtractResultArray("BAG_BINS"); results.Add(memResult); //results.Add(ndvi); results.Add(bPCDResult); return(results); } finally { if (ndvi != null) { ndvi.Dispose(); } } } else { PrintInfo("指定的算法\"" + algname + "\"没有实现。"); return(null); } }
public IExtractResult GetCloudBAG() { double niBandRoom = (double)_argumentProvider.GetArg("NearInfrared_Zoom"); bool needcloud = (bool)_argumentProvider.GetArg("isAppCloud"); UCSetNearTool uccontrl = _argumentProvider.GetArg("UCSetNearTool") as UCSetNearTool; if (uccontrl.ckbone.Checked) { uccontrl.btnGetAOIIndex(null, null); } string cloudfile = GetClmFile(_argumentProvider.DataProvider); bool isexistcloud = File.Exists(cloudfile); MinNear = double.Parse(uccontrl.txtnearmin.Text) * 100;//放大调节 跟界面参数设置有关 IRasterDataProvider prd = _argumentProvider.DataProvider; if (prd == null) { PrintInfo("未能获取当前影像数据。"); return(null); } IBandNameRaster bandNameRaster = prd as IBandNameRaster; int niBandNo = TryGetBandNo(bandNameRaster, "NearInfrared"); if (niBandNo == -1 || niBandRoom == -1) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } List <RasterMaper> rms = new List <RasterMaper>(); rms.Add(new RasterMaper(_argumentProvider.DataProvider, new int[] { niBandNo })); if (isexistcloud) { rms.Add(new RasterMaper(GeoDataDriver.Open(cloudfile) as IRasterDataProvider, new int[] { 1 })); } RasterIdentify rid = new RasterIdentify(_argumentProvider.DataProvider); rid.ProductIdentify = "BAG"; rid.SubProductIdentify = "DBLV"; string outfile = rid.ToPrjWksFullFileName(".dat"); IRasterDataProvider outRaster = null; outRaster = CreateOutRaster(outfile, rms.ToArray(), enumDataType.Int16); IPixelIndexMapper result = PixelIndexMapperFactory.CreatePixelIndexMapper("BAG", _argumentProvider.DataProvider.Width, _argumentProvider.DataProvider.Height, _argumentProvider.DataProvider.CoordEnvelope, _argumentProvider.DataProvider.SpatialRef); try { RasterProcessModel <Int16, Int16> rfr = null; RasterMaper[] fileIns = rms.ToArray(); RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) }; rfr = new RasterProcessModel <Int16, Int16>(); int totalindex = 0; rfr.SetRaster(fileIns, fileOuts); rfr.SetArgumentProviderAOI(_argumentProvider.AOI); rfr.RegisterCalcModel(new RasterCalcHandlerFun <Int16, Int16>((rvInVistor, rvOutVistor, aoi) => { if (rvInVistor[0].RasterBandsData[0] != null && rvInVistor[1].RasterBandsData[0] != null) { int dataLength = rvInVistor[0].SizeY * rvInVistor[0].SizeX; for (int i = 0; i < aoi.Length; i++) { int index = aoi[i]; if (rvInVistor[0].RasterBandsData[0][index] / niBandRoom > MinNear) { if (needcloud) { if (!isexistcloud) { result.Put(totalindex + index); continue; } else if (rvInVistor[1].RasterBandsData[0][index] == 0)//非云 { result.Put(totalindex + index); } else { //rvOutVistor[0].RasterBandsData[0][aoi[i]] = -9999;// 云 这里是否需要配置一下? } } else { result.Put(totalindex + index); //rvOutVistor[0].RasterBandsData[0][aoi[i]] = 1; } } else { } } totalindex = totalindex += dataLength; } return(false); })); rfr.Excute(); return(result); } catch (Exception ex) { return(null); } finally { outRaster.Dispose(); } }
private FileExtractResult CalcMPDI(string pviFile, float ndviCalcMin, float ndviCalcMax, IRasterDataProvider currPrd, bool normalizationSuccess, Action <int, string> progressTracker) { IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster;// int VisibleCH = TryGetBandNo(bandNameRaster, "RedBand"); int NearInfraredCH = TryGetBandNo(bandNameRaster, "NirBand"); double VisibleZoom = (double)_argumentProvider.GetArg("RedBand_Zoom"); double NearInfraredZoom = (double)_argumentProvider.GetArg("NirBand_Zoom"); if (VisibleCH == -1 || NearInfraredCH == -1) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } float mpdiZoom = (float)_argumentProvider.GetArg("MPDIZoom"); Int16 defCloudy = (Int16)_argumentProvider.GetArg("defCloudy"); Int16 defWater = (Int16)_argumentProvider.GetArg("defWater"); Int16 InvaildValue = (Int16)_argumentProvider.GetArg("InvaildValue"); DRTExpCoefficientCollection ExpCoefficient = _argumentProvider.GetArg("ExpCoefficient") as DRTExpCoefficientCollection; string EdgesFile = ExpCoefficient.EgdesFilename; DRTExpCoefficientCollection LandExpCoefficient = _argumentProvider.GetArg("LandExpCoefficient") as DRTExpCoefficientCollection; string LandFile = LandExpCoefficient.EgdesFilename; int bandNo = TryGetBandNo(bandNameRaster, "DemBand"); int LandbandNo = TryGetBandNo(bandNameRaster, "LandBand"); float ndviExp = (float)_argumentProvider.GetArg("NDVIExp"); bool isSetMinMax = (bool)_argumentProvider.GetArg("isSetMinMax"); float ndviMax = (float)_argumentProvider.GetArg("NDVIMax"); float ndviMin = (float)_argumentProvider.GetArg("NDVIMin"); float RegionExp1 = (float)_argumentProvider.GetArg("RegionExp1"); float RegionExp2 = (float)_argumentProvider.GetArg("RegionExp2"); float LandExp1 = (float)_argumentProvider.GetArg("LandExp1"); float LandExp2 = (float)_argumentProvider.GetArg("LandExp2"); string[] aois = _argumentProvider.GetArg("AOITemplate") as string[]; string aoiTemplate = (aois == null || aois.Length == 0) ? null : aois[0]; if (isSetMinMax) { ndviCalcMin = ndviMin; ndviCalcMax = ndviMax; } //输入文件准备 List <RasterMaper> rms = new List <RasterMaper>(); IRasterDataProvider currRaster = null; IRasterDataProvider pviPrd = null; IRasterDataProvider edgeRaster = null; IRasterDataProvider edgeLand = null; FileExtractResult mpdiRes = null; float PNVIZoom = (float)_argumentProvider.GetArg("PNVIZoom"); try { currRaster = currPrd; if (!normalizationSuccess && (currRaster.BandCount < VisibleCH || currRaster.BandCount < NearInfraredCH)) { PrintInfo("请选择正确的数据进行垂直干旱指数计算。"); return(null); } RasterMaper rmCurr = normalizationSuccess ? new RasterMaper(currRaster, new int[] { 1, 2 }) : new RasterMaper(currRaster, new int[] { VisibleCH, NearInfraredCH }); rms.Add(rmCurr); pviPrd = GeoDataDriver.Open(pviFile) as IRasterDataProvider; RasterMaper clmRm = new RasterMaper(pviPrd, new int[] { 1 }); rms.Add(clmRm); bool isContainEdges = false; if (!string.IsNullOrEmpty(EdgesFile) && File.Exists(EdgesFile)) { edgeRaster = RasterDataDriver.Open(EdgesFile) as IRasterDataProvider; if (edgeRaster.BandCount < bandNo) { PrintInfo("请正确选择经验系数中的边界文件,波段数不足!"); return(null); } RasterMaper rmEdge = new RasterMaper(edgeRaster, new int[] { bandNo }); rms.Add(rmEdge); isContainEdges = true; } bool isContainEdgesLand = false; if (!string.IsNullOrEmpty(LandFile) && File.Exists(LandFile)) { edgeLand = RasterDataDriver.Open(LandFile) as IRasterDataProvider; if (edgeLand.BandCount < LandbandNo) { PrintInfo("请正确选择土地参数中的边界文件,波段数不足!"); return(null); } RasterMaper rmLand = new RasterMaper(edgeLand, new int[] { LandbandNo }); rms.Add(rmLand); isContainEdgesLand = true; } //输出文件准备(作为输入栅格并集处理) string outFileName = GetFileName(new string[] { currRaster.fileName }, _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 <Int16, Int16> rfr = null; rfr = new RasterProcessModel <Int16, Int16>(progressTracker); rfr.SetRaster(fileIns, fileOuts); rfr.SetTemplateAOI(aoiTemplate); DRTExpCoefficientItem item = null; DRTExpCoefficientItem landitem = null; int demCode = -1; int landCode = -1; Int16 curNDVI = 0; float tempNDVIExp = 0f; float argsM = 0f; float argsM2 = 0f; float argsLand = 0f; float argsLand2 = 0f; rfr.RegisterCalcModel(new RasterCalcHandler <Int16, Int16>((rvInVistor, rvOutVistor, aoi) => { if (rvInVistor[0] == null || rvInVistor[0].RasterBandsData[0] == null || rvInVistor[1] == null || rvInVistor[1].RasterBandsData[0] == null || (isContainEdges && (rvInVistor[2] == null || rvInVistor[2].RasterBandsData[0] == null)) || (isContainEdgesLand && (rvInVistor[3 - (isContainEdges ? 0 : 1)] == null || rvInVistor[3 - (isContainEdges ? 0 : 1)].RasterBandsData[0] == null))) { return; } int dataLength = aoi == null || aoi.Length == 0 ? rvOutVistor[0].SizeY * rvOutVistor[0].SizeX : aoi.Length; for (int i = 0; i < dataLength; i++) { int index = aoi == null || aoi.Length == 0 ? i : aoi[i]; Int16 visiableValue = rvInVistor[0].RasterBandsData[0][index]; Int16 nearInfraredValue = rvInVistor[0].RasterBandsData[1][index]; if (isContainEdges && rvInVistor[2].RasterBandsData[0] != null) { demCode = (int)rvInVistor[2].RasterBandsData[0][index]; } else { demCode = -1; } if (isContainEdgesLand && rvInVistor[3 - (isContainEdges ? 0 : 1)].RasterBandsData[0] != null) { landCode = (int)rvInVistor[3 - (isContainEdges ? 0 : 1)].RasterBandsData[0][index]; } else { landCode = -1; } curNDVI = rvInVistor[1].RasterBandsData[0][index]; if (visiableValue == 0 && nearInfraredValue == 0) { rvOutVistor[0].RasterBandsData[0][index] = InvaildValue; } else if (curNDVI == defCloudy) { rvOutVistor[0].RasterBandsData[0][index] = defCloudy; } else if (curNDVI == defWater) { rvOutVistor[0].RasterBandsData[0][index] = defWater; } else { if (ndviCalcMax - ndviCalcMin == 0) { rvOutVistor[0].RasterBandsData[0][index] = 0; } tempNDVIExp = (float)(1 - Math.Pow(((ndviCalcMax - curNDVI / PNVIZoom) / (ndviCalcMax - ndviCalcMin)), ndviExp)); if (1 - tempNDVIExp == 0) { rvOutVistor[0].RasterBandsData[0][index] = 0; } item = ExpCoefficient.GetExpItemByNum(demCode); landitem = LandExpCoefficient.GetExpItemByNum(landCode); argsM = item == null ? RegionExp1 : (float)item.APara; argsM2 = item == null ? RegionExp2 : (float)item.BPara; argsLand = landitem == null ? LandExp1 : (float)landitem.APara; argsLand2 = landitem == null ? LandExp2 : (float)landitem.BPara; rvOutVistor[0].RasterBandsData[0][index] = (Int16)((visiableValue / VisibleZoom + (argsM * nearInfraredValue / NearInfraredZoom) - tempNDVIExp * (argsLand + argsM * argsLand2)) / ((1 - tempNDVIExp) * (Math.Sqrt(argsM2 * argsM2 + 1))) * mpdiZoom); } } })); //执行 rfr.Excute(InvaildValue); mpdiRes = new FileExtractResult(_subProductDef.Identify, outFileName, true); mpdiRes.SetDispaly(false); _argumentProvider.SetArg("CursorInfo:MPDI-NDVIMax", ndviCalcMax); _argumentProvider.SetArg("CursorInfo:MPDI-NDVIMin", ndviCalcMin); return(mpdiRes); } } finally { if (edgeLand != null) { edgeLand.Dispose(); } if (pviPrd != null) { pviPrd.Dispose(); } if (normalizationSuccess && currPrd != null) { currPrd.Dispose(); } if (edgeRaster != null) { edgeRaster.Dispose(); } } }
private IExtractResult EVIAlgorithm2(Action <int, string> progressTracker) { int bands = _argumentProvider.DataProvider.BandCount; if (bands == 0 || bands == 1) { PrintInfo("请选择正确的局地文件进行计算。"); return(null); } if (_argumentProvider.GetArg("Visible") == null) { PrintInfo("参数\"Visible\"为空。"); return(null); } IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster; int bandV = TryGetBandNo(bandNameRaster, "Visible"); if (_argumentProvider.GetArg("NearInfrared") == null) { PrintInfo("参数\"NearInfrared\"为空。"); return(null); } int bandN = TryGetBandNo(bandNameRaster, "NearInfrared"); if (_argumentProvider.GetArg("Blue") == null) { PrintInfo("参数\"Blue\"为空。"); return(null); } int bandB = TryGetBandNo(bandNameRaster, "Blue"); if (bandV < 1 || bandB < 1 || bandN < 1 || bandV > bands || bandB > bands || bandN > bands) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } if (_argumentProvider.GetArg("Visible_Zoom") == null) { PrintInfo("参数\"Visible_Zoom\"为空。"); return(null); } double visibleZoom = (double)_argumentProvider.GetArg("Visible_Zoom"); if (_argumentProvider.GetArg("NearInfrared_Zoom") == null) { PrintInfo("参数\"NearInfrared_Zoom\"为空。"); return(null); } double nearInfrared = (double)_argumentProvider.GetArg("NearInfrared_Zoom"); if (_argumentProvider.GetArg("Blue_Zoom") == null) { PrintInfo("参数\"Blue_Zoom\"为空。"); return(null); } double blueZoom = (double)_argumentProvider.GetArg("Blue_Zoom"); int[] bandNos = new int[] { bandV, bandN, bandB, }; double[] bandZoom = new double[] { visibleZoom, nearInfrared, blueZoom }; Dictionary <string, string> dic = Obj2Dic(_argumentProvider.GetArg("ArgumentSetting")); string nearVisiableMinStr = dic.ContainsKey("NearVisableMin") ? dic["NearVisableMin"] : string.Empty; string nearVisiableMaxStr = dic.ContainsKey("NearVisableMax") ? dic["NearVisableMax"] : string.Empty; string visibleMinStr = dic.ContainsKey("VisibleMin") ? dic["VisibleMin"] : string.Empty; float nearVisiableMin = float.Parse(nearVisiableMinStr); float nearVisiableMax = float.Parse(nearVisiableMaxStr); float visibleMin = float.Parse(visibleMinStr); float[] cloudyArgs = new float[] { visibleMin, nearVisiableMax, nearVisiableMin }; Int16 defCloudy = (Int16)_argumentProvider.GetArg("defCloudy"); float zoom = (ushort)_argumentProvider.GetArg("resultZoom"); zoom = zoom == 0f ? 1000 : zoom; string[] aois = _argumentProvider.GetArg("AOITemplate") as string[]; string aoiTemplate = (aois == null || aois.Length == 0) ? null : aois[0]; string[] inputFiles = GetStringArray("RasterFile"); if (inputFiles == null || inputFiles.Length == 0) { PrintInfo("没有设置输入数据"); return(null); } bool isFitterCloud; if (!bool.TryParse(_argumentProvider.GetArg("isFilterCloudy").ToString(), out isFitterCloud)) { PrintInfo("是否过滤云参数设置不正确!"); return(null); } IExtractResultArray results = new ExtractResultArray("EVI"); foreach (string inputFile in inputFiles) { //计算RVI IExtractResult ret = CalcEVIAlgorithm2(inputFile, bandNos, zoom, bandZoom, cloudyArgs, defCloudy, isFitterCloud, aoiTemplate, progressTracker); if (ret != null) { results.Add(ret as IExtractResultBase); } } return(results); }
private string NormalizationProcess(IRasterDataProvider currPrd, Action <int, string> progressTracker) { IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster;// int VisibleCH = TryGetBandNo(bandNameRaster, "RedBand"); int NearInfraredCH = TryGetBandNo(bandNameRaster, "NirBand"); int FarInfrared11CH = TryGetBandNo(bandNameRaster, "FarBand"); double VisibleZoom = (double)_argumentProvider.GetArg("RedBand_Zoom"); double NearInfraredZoom = (double)_argumentProvider.GetArg("NirBand_Zoom"); double FarInfrared11Zoom = (double)_argumentProvider.GetArg("FarBand_Zoom"); int SunZCH = TryGetBandNo(bandNameRaster, "SunZBand"); int SatZCH = TryGetBandNo(bandNameRaster, "SatZBand"); int SunACH = TryGetBandNo(bandNameRaster, "SunABand"); int SatACH = TryGetBandNo(bandNameRaster, "SatABand"); int LandConveryCH = TryGetBandNo(bandNameRaster, "LandCoveryBand"); double SunZZoom = (double)_argumentProvider.GetArg("SunZBand_Zoom"); double SatZZoom = (double)_argumentProvider.GetArg("SatZBand_Zoom"); double SunAZoom = (double)_argumentProvider.GetArg("SunABand_Zoom"); double SatAZoom = (double)_argumentProvider.GetArg("SatABand_Zoom"); double LandCoveryZoom = (double)_argumentProvider.GetArg("LandCoveryBand_Zoom"); AngleParModel angleArg = _argumentProvider.GetArg("Angle") as AngleParModel; _zooms = new float[] { (float)VisibleZoom, (float)NearInfraredZoom, (float)FarInfrared11Zoom, (float)SunZZoom, (float)SunAZoom, (float)SatZZoom, (float)SatAZoom, (float)LandCoveryZoom }; if (_progressTracker != null) { _progressTracker(5, "开始读取数据文件..."); } IRasterDataProvider angleRaster = null; IRasterDataProvider landcoverRaster = null; int outwidth, outheight; try { #region 波段数据读取 if (_progressTracker != null) { _progressTracker(7, "正在读取当前影像文件..."); } float prjReslX = currPrd.ResolutionX; float prjReslY = currPrd.ResolutionY; double prjMinLon = currPrd.CoordEnvelope.MinX; double prjMaxLat = currPrd.CoordEnvelope.MaxY; outwidth = currPrd.Width; outheight = currPrd.Height; UInt16[] reddata = GetDataValue <UInt16>(currPrd.GetRasterBand(VisibleCH), 0, 0, outwidth, outheight); UInt16[] IRdata = GetDataValue <UInt16>(currPrd.GetRasterBand(NearInfraredCH), 0, 0, outwidth, outheight); UInt16[] Firdata = GetDataValue <UInt16>(currPrd.GetRasterBand(FarInfrared11CH), 0, 0, outwidth, outheight); if (_progressTracker != null) { _progressTracker(9, "正在读取角度数据文件..."); } Int16[] sza, saa, vza, vaa; angleRaster = GeoDataDriver.Open(angleArg.FileAsunZ) as IRasterDataProvider; if (angleRaster == null || angleRaster.BandCount < 1) { return(null); } sza = GetDataValue <Int16>(angleRaster.GetRasterBand(1), 0, 0, outwidth, outheight); angleRaster = GeoDataDriver.Open(angleArg.FileAsunA) as IRasterDataProvider; if (angleRaster == null || angleRaster.BandCount < 1) { return(null); } saa = GetDataValue <Int16>(angleRaster.GetRasterBand(1), 0, 0, outwidth, outheight); angleRaster = GeoDataDriver.Open(angleArg.FileAsatZ) as IRasterDataProvider; if (angleRaster == null || angleRaster.BandCount < 1) { return(null); } vza = GetDataValue <Int16>(angleRaster.GetRasterBand(1), 0, 0, outwidth, outheight); angleRaster = GeoDataDriver.Open(angleArg.FileAsatA) as IRasterDataProvider; if (angleRaster == null || angleRaster.BandCount < 1) { return(null); } vaa = GetDataValue <Int16>(angleRaster.GetRasterBand(1), 0, 0, outwidth, outheight); if (_progressTracker != null) { _progressTracker(11, "正在读取LandCover数据文件..."); } landcoverRaster = GeoDataDriver.Open(angleArg.FileLandConvery) as IRasterDataProvider; if (landcoverRaster == null || landcoverRaster.BandCount < 1) { return(null); } #endregion output = new ushort[3][]; output[0] = new ushort[reddata.Length]; output[1] = new ushort[reddata.Length]; output[2] = new ushort[reddata.Length]; #region 分块并行处理 int parts = 7; int step = reddata.Length / parts; int[] istart = new int[parts]; int[] iend = new int[parts]; istart[0] = 0; iend[0] = 0 + step; for (int p = 1; p < parts; p++) { istart[p] = istart[p - 1] + step; iend[p] = iend[p - 1] + step; } iend[parts - 1] = reddata.Length; var tasks = new Action[] { () => CalNormalizationParts(istart[0], iend[0], outwidth, reddata, IRdata, Firdata, landcoverRaster, sza, saa, vza, vza, prjReslX, prjMinLon, prjMaxLat), () => CalNormalizationParts(istart[1], iend[1], outwidth, reddata, IRdata, Firdata, landcoverRaster, sza, saa, vza, vza, prjReslX, prjMinLon, prjMaxLat), () => CalNormalizationParts(istart[2], iend[2], outwidth, reddata, IRdata, Firdata, landcoverRaster, sza, saa, vza, vza, prjReslX, prjMinLon, prjMaxLat), () => CalNormalizationParts(istart[3], iend[3], outwidth, reddata, IRdata, Firdata, landcoverRaster, sza, saa, vza, vza, prjReslX, prjMinLon, prjMaxLat), () => CalNormalizationParts(istart[4], iend[4], outwidth, reddata, IRdata, Firdata, landcoverRaster, sza, saa, vza, vza, prjReslX, prjMinLon, prjMaxLat), () => CalNormalizationParts(istart[5], iend[5], outwidth, reddata, IRdata, Firdata, landcoverRaster, sza, saa, vza, vza, prjReslX, prjMinLon, prjMaxLat), () => CalNormalizationParts(istart[6], iend[6], outwidth, reddata, IRdata, Firdata, landcoverRaster, sza, saa, vza, vza, prjReslX, prjMinLon, prjMaxLat), }; if (_progressTracker != null) { _progressTracker(13, "正在逐点归一化反射率,请稍候..."); } System.Threading.Tasks.Parallel.Invoke(tasks); #endregion #region 建立输出文件 if (_progressTracker != null) { _progressTracker(75, "正在输出归一化反射率结果,请稍候..."); } return(OutputNormalization(currPrd)); #endregion } finally { } }
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(); } } }