private IExtractResult ComputeByFiles(string[] files) { IExtractResultArray result = new ExtractResultArray("DRT"); IRasterDataProvider currPrd = null; for (int i = 0; i < files.Length; i++) { currPrd = GeoDataDriver.Open(files[i], null) as IRasterDataProvider; if (currPrd != null) { try { IExtractResult temp = ComputeByCurrentRaster(currPrd, _progressTracker); if (temp == null || (temp as FileExtractResult) == null) { continue; } result.Add(temp as FileExtractResult); } finally { currPrd.Dispose(); } } } return(result); }
private IExtractResult StatProcentRaster <T>(string fname, string statVector, Dictionary <string, Func <short, bool> > filters, Action <int, string> progressTracker, bool weight, float weightZoom) { string title; string[] colDescs; IStatResult[] results = StatProcentRasterToStatResult(fname, statVector, filters, progressTracker, out title, out colDescs, false, weight, weightZoom); string outFileIdentify = GetStringArgument("OutFileIdentify"); string[] outFileIdentifys = new string[] { outFileIdentify, outFileIdentify.Substring(1) + "P" }; string productIdentify = _subProductDef.ProductDef.Identify; IExtractResultArray array = new ExtractResultArray("FIR"); string filename = null; for (int i = 0; i < results.Length; i++) { if (i >= outFileIdentifys.Length) { break; } filename = StatResultToFile(new string[] { fname }, results[i], productIdentify, outFileIdentifys[i], title + colDescs[i] + "统计", null, 1, false, 1); array.Add(new FileExtractResult(outFileIdentify, filename)); } return(array); }
public override IExtractResult Make(Action <int, string> progressTracker, IContextMessage contextMessage) { if (_argumentProvider.GetArg("SelectedPrimaryFiles") == null) { return(null); } string[] binWater = _argumentProvider.GetArg("SelectedPrimaryFiles") as string[]; for (int i = 0; i < binWater.Length; i++) { if (!File.Exists(binWater[i])) { return(null); } } _contextMessage = contextMessage; if (_argumentProvider == null) { return(null); } if (_argumentProvider.GetArg("AlgorithmName") == null) { return(null); } IFileExtractResult[] flodFiles = null; IExtractResult fldsFile = null; if (_argumentProvider.GetArg("AlgorithmName").ToString() == "DayFLDSAlgorithm") { flodFiles = GreateFLODFile(binWater, progressTracker); if (flodFiles == null || flodFiles.Length == 0 || string.IsNullOrEmpty(flodFiles[0].FileName)) { return(null); } List <string> toFLDSFiles = new List <string>(); foreach (IFileExtractResult item in flodFiles) { toFLDSFiles.Add(item.FileName); } fldsFile = FLODLastFiles(toFLDSFiles.ToArray(), progressTracker); } else if (_argumentProvider.GetArg("AlgorithmName").ToString() == "FloodFLDSAlgorithm") { fldsFile = FLODLastFiles(binWater, progressTracker); } if (fldsFile != null) { IExtractResultArray array = new ExtractResultArray("洪涝持续天数"); if (flodFiles != null && flodFiles.Length != 0) { foreach (IFileExtractResult item in flodFiles) { (item as IFileExtractResult).SetDispaly(false); array.Add(item as IExtractResultBase); } } array.Add(fldsFile as IExtractResultBase); return(array); } return(null); }
private IExtractResultArray CalcGFRF(string[] files) { string datFname = GetDatFilename(files); string GFInfoList = GenGFILfname(files); using (StreamWriter sw = new StreamWriter(GFInfoList, false, Encoding.Default)) { sw.WriteLine("NO.\t" + "Latitude\t" + "Longitude\t" + "Size/ha\t" + "Temperature/K\t" + "Fire_Intensity\t" + "Reliability"); } int[,] fireCountArray = InitValueArray(); int[] firPositionArray = null; for (int i = 0; i < files.Length; i++) { firPositionArray = ProcessVectorToArray(files[i], GFInfoList); int col, row; foreach (int cr in firPositionArray) { row = cr / _datwidth; col = (cr % _datwidth); fireCountArray[row, col] += 1; } } _firePointsCount = 0; ProcessArrayToRaster(datFname, fireCountArray); _argumentProvider.SetArg("SelectedPrimaryFiles", datFname); IFileExtractResult GFRF = GFRFAlgorithm() as IFileExtractResult; IExtractResultArray array = new ExtractResultArray("全球火点累计"); IFileExtractResult GFIL = new FileExtractResult("GFIL", GFInfoList, true); GFIL.SetDispaly(false); array.Add(GFRF); array.Add(GFIL); return(array); }
public override IExtractResult Make(Action <int, string> progressTracker) { if (_argumentProvider == null) { return(null); } List <string> covertDegreeRegions = _argumentProvider.GetArg("CovertDegreeRegion") as List <string>; if (_argumentProvider.GetArg("AlgorithmName") == null || covertDegreeRegions == null || covertDegreeRegions.Count == 0) { return(null); } if (_argumentProvider.GetArg("AlgorithmName").ToString() == "BCDF") { int count = covertDegreeRegions.Count; ExtractResultArray results = new ExtractResultArray("BAG_BCDF"); for (int i = 0; i < count; i++) { float[] minmax = BAGStatisticHelper.GetCovertDegreeValue(covertDegreeRegions[i]); FileExtractResult result = FREQAlgorithm(minmax[0], minmax[1]) as FileExtractResult; results.Add(result); } return(results); } return(null); }
private IExtractResult DVIAlgorithm2(Action <int, string> progressTracker) { IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster; int bandV = TryGetBandNo(bandNameRaster, "Visible"); //可见光 int bandNear = TryGetBandNo(bandNameRaster, "NearInfrared"); //近红外 if (bandV == -1 || bandNear == -1) { PrintInfo("通道序号设置不正确"); return(null); } int[] bandNos = new int[] { bandV, bandNear }; double visibleZoom = (double)_argumentProvider.GetArg("Visible_Zoom"); double nearInfrared = (double)_argumentProvider.GetArg("NearInfrared_Zoom"); double[] bandzoom = new double[] { visibleZoom, nearInfrared }; 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("NDVI"); foreach (string inputFile in inputFiles) { //计算NDVI IExtractResult ret = CalcDVIAlgorithm2(inputFile, bandNos, zoom, bandzoom, cloudyArgs, defCloudy, isFitterCloud, aoiTemplate, progressTracker); if (ret != null) { results.Add(ret as IExtractResultBase); } } return(results); }
private IExtractResult DVIAlgorithm1(Action <int, string> progressTracker) { IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster; int bandV = TryGetBandNo(bandNameRaster, "Visible"); //可见光 int bandNear = TryGetBandNo(bandNameRaster, "NearInfrared"); //近红外 int bandMid = TryGetBandNo(bandNameRaster, "MiddInfrared"); //中红外 int bandFar = TryGetBandNo(bandNameRaster, "FarInfrared11"); //远红外 if (bandV == -1 || bandNear == -1 || bandMid < 1 || bandFar < 1) { PrintInfo("通道序号设置不正确"); return(null); } int[] bandNos = new int[] { bandV, bandNear, bandMid, bandFar }; double visibleZoom = (double)_argumentProvider.GetArg("Visible_Zoom"); double nearInfrared = (double)_argumentProvider.GetArg("NearInfrared_Zoom"); double middZoom = (double)_argumentProvider.GetArg("MiddInfrared_Zoom"); double farZoom = (double)_argumentProvider.GetArg("FarInfrared11_Zoom"); double[] bandzoom = new double[] { visibleZoom, nearInfrared, 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("NDVI"); foreach (string inputFile in inputFiles) { //计算NDVI IExtractResult ret = CalcDVIAlgorithm1(inputFile, bandNos, zoom, bandzoom, cloudyArgs, defCloudy, isFitterCloud, aoiTemplate, progressTracker); if (ret != null) { results.Add(ret as IExtractResultBase); } } return(results); }
private IExtractResult EDGEAlgorithm() { int band = (int)_argumentProvider.GetArg("band"); int smaping = (int)_argumentProvider.GetArg("Smaping"); float dataValue = (float)_argumentProvider.GetArg("dataValue"); bool isOutputUncompleted = (bool)_argumentProvider.GetArg("IsOutputUncompleted"); string[] files = GetStringArray("SelectedPrimaryFiles"); string extInfos = GetStringArgument("extinfo"); if (files == null || files.Length == 0) { return(null); } try { ExtractResultArray array = new ExtractResultArray("FLD"); IRasterDataProvider rdp = null; string shpFile = null; GenerateContourLines gcl = null; FileExtractResult res = null; RasterIdentify rid; foreach (string file in files) { try { //生成等值线shp文件 shpFile = GenEDGEFiename(file); gcl = new GenerateContourLines(_progressTracker, _contextMessage); rdp = GeoDataDriver.Open(file, null) as IRasterDataProvider; rid = new RasterIdentify(rdp); if (rid.SubProductIdentify == "DBLV" && dataValue == 1) { dataValue = 0; } gcl.DoGenerateContourLines(rdp, band, _argumentProvider.AOI, new double[] { dataValue }, smaping, shpFile, isOutputUncompleted); if (!File.Exists(shpFile)) { PrintInfo(Path.GetFileName(file) + ":生成等值线数据失败。"); continue; } res = new FileExtractResult(_subProductDef.Identify, shpFile, true); res.SetDispaly(false); array.Add(res); } finally { rdp.Dispose(); } } return(array.PixelMappers == null || array.PixelMappers.Length == 0 ? null : array); } finally { } }
private IExtractResult CalcNDVI(Action <int, string> progressTracker) { //参数准备 int bandV = (int)_argumentProvider.GetArg("Visible"); //可见光 int bandNear = (int)_argumentProvider.GetArg("NearInfrared"); //近红外 if (bandV == -1 || bandNear == -1) { PrintInfo("通道序号设置不正确"); return(null); } int[] bandNos = new int[] { bandV, bandNear }; double visibleZoom = (double)_argumentProvider.GetArg("Visible_Zoom"); double nearInfrared = (double)_argumentProvider.GetArg("NearInfrared_Zoom"); float zoom = (ushort)_argumentProvider.GetArg("resultZoom"); zoom = zoom == 0f ? 1000 : zoom; string[] aois = _argumentProvider.GetArg("AOITemplate") as string[]; string aoiTemplate = aois == null ? null : aois[0]; string[] inputFiles = _argumentProvider.GetArg("RasterFile") as string[]; if (inputFiles == null || inputFiles.Length == 0) { PrintInfo("没有设置输入数据"); return(null); } IExtractResultArray results = new ExtractResultArray("NDVI"); foreach (string inputFile in inputFiles) { //计算NDVI IExtractResult ret = CalcNDVI(inputFile, bandNos, zoom, aoiTemplate, progressTracker); if (ret != null) { results.Add(ret as IExtractResultBase); } } return(results); }
public IExtractResult ComputeByFiles(string[] fnames) { if (_arg == null) { return(null); } IExtractResultArray resultAry = new ExtractResultArray(_identify); IRasterExtracter <UInt16, Int16> extracter = new SimpleRasterExtracter <UInt16, Int16>(); foreach (string fname in fnames) { if (!IsSameTypeFile(fname)) { continue; } IExtractResultBase result = ComputeSingleFile(fname, extracter, _arg.BandNos, _arg.Express); if (result != null) { resultAry.Add(result); } } return(resultAry); }
private IExtractResult TauL55Algorithm() { IFileExtractResult U5TTResult = null; string instanceIdentify = _argumentProvider.GetArg("OutFileIdentify") as string; if (string.IsNullOrWhiteSpace(instanceIdentify)) { return(null); } SubProductInstanceDef instance = FindSubProductInstanceDefs(instanceIdentify); if (instance != null) { U5TTResult = ThemeGraphyResult(null) as IFileExtractResult; IExtractResultArray array = new ExtractResultArray("气溶胶产品"); IFileExtractResult U5TIResult = new FileExtractResult("U5TI", _055TauFname, true); U5TIResult.SetDispaly(false); array.Add(U5TTResult); array.Add(U5TIResult); return(array); } return(null); }
/// <summary> /// 融合微波雪深文件 和 可见光雪云辨识文件更新雪深 /// </summary> /// <param name="sdfilname"></param> /// <param name="visfilename"></param> /// <returns></returns> private IFileExtractResult ComputeSD(string sdfilename, string visfilename) { List <RasterMaper> rms = null; IRasterDataProvider outRaster = null; IRasterDataProvider outClassRaster = null;//融合分类 rms = new List <RasterMaper>(); IRasterDataProvider inRaster1 = GeoDataDriver.Open(sdfilename) as IRasterDataProvider; //微波雪深数据 RasterMaper fileIn1 = new RasterMaper(inRaster1, new int[] { 1 }); rms.Add(fileIn1); IRasterDataProvider inRaster2 = GeoDataDriver.Open(visfilename) as IRasterDataProvider;//可见云和雪判识结果 RasterMaper fileIn2 = new RasterMaper(inRaster2, new int[] { 1 }); rms.Add(fileIn2); //林地覆盖率 string forestFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemData\\ProductArgs\\MWS\\SnowArgFile\\china_forest._frac.dat"); IRasterDataProvider inRaster3 = GeoDataDriver.Open(forestFile) as IRasterDataProvider; RasterMaper fileIn3 = new RasterMaper(inRaster3, new int[] { 1 }); rms.Add(fileIn3); if (inRaster1.ResolutionX != inRaster3.ResolutionX) { PrintInfo("雪深数据分辨率与辅助数据分辨率0.1度不同!"); return(null); } string visFileName = GetFileName(new string[] { sdfilename }, _subProductDef.ProductDef.Identify, "MWVI", ".dat", null); outRaster = CreateOutRaster(visFileName, enumDataType.Float, rms.ToArray(), inRaster2.ResolutionX); //融合分类数据 string classFileName = GetFileName(new string[] { sdfilename }, _subProductDef.ProductDef.Identify, "MCVI", ".dat", null); outClassRaster = CreateOutRaster(classFileName, enumDataType.Float, rms.ToArray(), inRaster2.ResolutionX); double minX = outRaster.CoordEnvelope.MinX; double minY = outRaster.CoordEnvelope.MinY; double maxX = outRaster.CoordEnvelope.MaxX; double maxY = outRaster.CoordEnvelope.MaxY; int xLeft = (int)((minX - inRaster1.CoordEnvelope.MinX) / inRaster1.ResolutionX); int yUp = (int)((inRaster1.CoordEnvelope.MaxY - maxY) / inRaster1.ResolutionY); int xRight = (int)((maxX - inRaster1.CoordEnvelope.MinX) / inRaster1.ResolutionX); int yDown = (int)((inRaster1.CoordEnvelope.MaxY - minY) / inRaster1.ResolutionX); int xSize = xRight - xLeft; int ySize = yDown - yUp; float[] buffer = new float[xSize * ySize]; IRasterBand bandinRaster1 = inRaster1.GetRasterBand(1); float[] sd = new float[xSize * ySize]; //float[] snowClass = new float[xSize * ySize]; unsafe { fixed(float *pointer = buffer) { IntPtr ptr = new IntPtr(pointer); bandinRaster1.Read(xLeft, yUp, xSize, ySize, ptr, inRaster1.DataType, xSize, ySize); for (int j = 0; j < xSize * ySize; j++) { sd[j] = buffer[j]; } } } int visLeftX = (int)((minX - inRaster2.CoordEnvelope.MinX) / inRaster2.ResolutionX); int visLeftY = (int)((inRaster2.CoordEnvelope.MaxY - maxY) / inRaster2.ResolutionY); int visRightX = (int)((maxX - inRaster2.CoordEnvelope.MinX) / inRaster2.ResolutionX); int visRightY = (int)((inRaster2.CoordEnvelope.MaxY - minY) / inRaster2.ResolutionX); int visxSize = visRightX - visLeftX; int visySize = visRightY - visLeftY; Int16[] visbuffer = new Int16[visxSize * visySize]; IRasterBand bandinRaster2 = inRaster2.GetRasterBand(1); Int16[] visSNW = new Int16[visxSize * visySize]; // float[] sdSnow = new float[outRaster.Width * outRaster.Height]; float[ ,] sdSnow = new float[2, outRaster.Width *outRaster.Height];//一维放融合雪深,二维放融合分类 unsafe { fixed(Int16 *pointer = visbuffer) { IntPtr ptr = new IntPtr(pointer); bandinRaster2.Read(visLeftX, visLeftY, visxSize, visySize, ptr, inRaster2.DataType, visxSize, visySize); for (int j = 0; j < visxSize * visySize; j++) { visSNW[j] = visbuffer[j]; } } } //读取森林覆盖率; int xforestLeft = (int)((minX - inRaster3.CoordEnvelope.MinX) / inRaster3.ResolutionX); int yforestUp = (int)((inRaster3.CoordEnvelope.MaxY - maxY) / inRaster3.ResolutionY); int xforestRight = (int)((maxX - inRaster3.CoordEnvelope.MinX) / inRaster3.ResolutionX); int yforestDown = (int)((inRaster3.CoordEnvelope.MaxY - minY) / inRaster3.ResolutionX); int xforestSize = xforestRight - xforestLeft; int yforestSize = yforestDown - yforestUp; Int16[] forestbuffer = new Int16[xforestSize * yforestSize]; IRasterBand bandinRaster3 = inRaster3.GetRasterBand(1); Int16[] forestFrac = new Int16[xforestSize * yforestSize]; unsafe { fixed(Int16 *pointer = forestbuffer) { IntPtr ptr = new IntPtr(pointer); bandinRaster3.Read(xforestLeft, yforestUp, xforestSize, yforestSize, ptr, inRaster3.DataType, xforestSize, yforestSize); for (int j = 0; j < xforestSize * yforestSize; j++) { forestFrac[j] = forestbuffer[j]; } } } int zoom = (int)(inRaster1.ResolutionX / inRaster2.ResolutionX); try { for (int j = 0; j < xSize * ySize; j++) //低分的格子 { if (((j + 1) % xSize == 0) && (j != xSize * ySize - 1)) //最后一列并且不是低分最后一个格子 { int zoomcha = xSize * zoom - visxSize; Int32[] index = new Int32[zoom * (zoom - zoomcha)]; for (int row = 0; row < zoom; row++) //行还是原来的zoom行 { for (int col = 0; col < zoom - zoomcha; col++) //列比原来少 zoomcha 列 { index[col + row * (zoom - zoomcha)] = (j / xSize * zoom * visxSize + j % xSize * zoom) + (row * visxSize) + col; } } sdSnow = SDsnow(zoom - zoomcha, zoom, index, visSNW, sd[j], sdSnow, forestFrac[j]); } else { if ((j >= xSize * ySize - xSize) && (j != xSize * ySize - 1)) //最后一行并且不是低分最后一个格子 { int zoomcha = ySize * zoom - visySize; Int32[] index = new Int32[(zoom - zoomcha) * zoom]; for (int row = 0; row < zoom - zoomcha; row++) //行比原来少 zoomcha行 { for (int col = 0; col < zoom; col++) //列还是原来列 { index[col + row * zoom] = (j / xSize * zoom * visxSize + j % xSize * zoom) + (row * visxSize) + col; } } sdSnow = SDsnow(zoom, zoom - zoomcha, index, visSNW, sd[j], sdSnow, forestFrac[j]); } else { if (j == xSize * ySize - 1) //低分的最后一个格子 { int zoomcha = ySize * zoom - visySize; Int32[] index = new Int32[(zoom - zoomcha) * (zoom - zoomcha)]; for (int row = 0; row < zoom - zoomcha; row++) //行比原来少 zoomcha行 { for (int col = 0; col < zoom - zoomcha; col++) //列列比原来少 zoomcha 列 { index[col + row * (zoom - zoomcha)] = (j / xSize * zoom * visxSize + j % xSize * zoom) + (row * visxSize) + col; } } sdSnow = SDsnow(zoom - zoomcha, zoom - zoomcha, index, visSNW, sd[j], sdSnow, forestFrac[j]); } else { Int32[] index = new Int32[zoom * zoom]; for (int row = 0; row < zoom; row++) { for (int col = 0; col < zoom; col++) { index[col + row * zoom] = (j / xSize * zoom * visxSize + j % xSize * zoom) + (row * visxSize) + col; } } sdSnow = SDsnow(zoom, zoom, index, visSNW, sd[j], sdSnow, forestFrac[j]); } } } } } catch (Exception ex) { PrintInfo(ex.Message); } float[] sdSnow1 = new float[outRaster.Width * outRaster.Height]; float[] sdclass = new float[outRaster.Width * outRaster.Height]; IExtractResultArray array = new ExtractResultArray("融合雪深分类"); for (int index = 0; index < outRaster.Width * outRaster.Height; index++) { sdSnow1[index] = sdSnow[0, index]; sdclass[index] = sdSnow[1, index]; } try { unsafe { fixed(float *ptr = sdSnow1) { IntPtr sdSnowPtr = new IntPtr(ptr); IRasterBand bandoutRaster = outRaster.GetRasterBand(1); bandoutRaster.Write(0, 0, outRaster.Width, outRaster.Height, sdSnowPtr, outRaster.DataType, outRaster.Width, outRaster.Height); } fixed(float *ptr = sdclass) { IntPtr sdclassPtr = new IntPtr(ptr); IRasterBand bandoutRaster = outClassRaster.GetRasterBand(1); bandoutRaster.Write(0, 0, outClassRaster.Width, outClassRaster.Height, sdclassPtr, outClassRaster.DataType, outClassRaster.Width, outClassRaster.Height); } } IFileExtractResult res = new FileExtractResult(_subProductDef.Identify, visFileName, true); array.Add(res); IFileExtractResult res2 = new FileExtractResult(_subProductDef.Identify, classFileName, true); array.Add(res2); return(res); } finally { if (outRaster != null) { outRaster.Dispose(); } if (outClassRaster != null) { outClassRaster.Dispose(); } if (rms != null && rms.Count > 0) { foreach (RasterMaper rm in rms) { if (rm.Raster != null) { rm.Raster.Dispose(); } } } } }
private IExtractResult FRDSAlgorithm(Action <int, string> progressTracker) { 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); } } int bandNo = 1; ExtractResultArray array = new ExtractResultArray("SNW"); //输出文件准备(作为输入栅格并集处理) RasterIdentify ri = GetRasterIdentifyID(ref fileNames); string outFileName = ri.ToWksFullFileName(".dat"); //输入文件准备 List <RasterMaper> rms = new List <RasterMaper>(); string tempFilename; try { for (int i = 0; i < fileNames.Length; i++) { tempFilename = ProcessCloud(fileNames[i], bandNo); IRasterDataProvider inRaster = RasterDataDriver.Open(tempFilename) as IRasterDataProvider; if (inRaster.BandCount < bandNo) { PrintInfo("请选择正确的数据进行积雪天数统计。"); return(null); } RasterMaper rm = new RasterMaper(inRaster, new int[] { tempFilename == fileNames[i] ? bandNo : 1 }); rms.Add(rm); } 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"); Int16 currTimeValue = 0; rfr.RegisterCalcModel(new RasterCalcHandler <Int16, Int16>((rvInVistor, rvOutVistor, aoi) => { int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX; Int16[] timeValue = new Int16[dataLength]; List <Int16> tempValue = new List <Int16>(); for (int i = 0; i < dataLength; i++) { timeValue[i] = 0; } for (int index = 0; index < dataLength; index++) { foreach (RasterVirtualVistor <Int16> rvs in rvInVistor) { Int16[] dt = rvs.RasterBandsData[0]; if (dt == null) { continue; } tempValue.Add(dt[index]); } if (tempValue.Count == 0) { continue; } if (TimeValue(tempValue.ToArray(), nanValues, invailValues, waterValues, out currTimeValue)) { timeValue[index] = currTimeValue; } tempValue.Clear(); } for (int index = 0; index < dataLength; index++) { rvOutVistor[0].RasterBandsData[0][index] = timeValue[index]; } })); //执行 rfr.Excute(0); FileExtractResult res = new FileExtractResult(_subProductDef.Identify, outFileName, true); array.Add(res); res.SetDispaly(false); } } finally { foreach (RasterMaper rm in rms) { rm.Raster.Dispose(); } } _argumentProvider.SetArg("SelectedPrimaryFiles", new string[] { outFileName }); string instanceIdentify = _argumentProvider.GetArg("OutFileIdentify") as string; if (string.IsNullOrWhiteSpace(instanceIdentify)) { return(array); } SubProductInstanceDef instance = FindSubProductInstanceDefs(instanceIdentify); IExtractResult ress = ThemeGraphyByInstance(instance); if (ress != null) { array.Add(ress as IFileExtractResult); } return(array); }
private IExtractResult SateValAlgorithm(Action <int, string> progressTracker) { ValArguments args = _argumentProvider.GetArg("SateArgs") as ValArguments; if (args == null) { return(null); } string toValFile = args.FileNamesToVal[0]; string forValFile = args.FileNamesForVal[0]; string invalid = args.Invalid; //先判断时间是否一样 string toValDate = "0000"; string forValDate = "0000"; try { foreach (Regex dt in DataReg) { Match m1 = dt.Match(Path.GetFileName(toValFile)); Match m2 = dt.Match(Path.GetFileName(forValFile)); if (m1.Success) { toValDate = m1.Value; } if (m2.Success) { forValDate = m2.Value; } } if (toValDate == "0000" || forValDate == "0000") { MessageBox.Show("数据文件时间为空,默认两文件时间相符"); } else { int year = Convert.ToInt32(toValDate.Substring(0, 4)); int month = Convert.ToInt32(toValDate.Substring(4, 2)); int day = Convert.ToInt32(toValDate.Substring(6, 2)); DateTime datetime = new DateTime(year, month, day); string days = Convert.ToString(datetime.DayOfYear); if (days != forValDate.Substring(1)) { MessageBox.Show("提示:对比数据时间不同"); } } } catch (Exception ex) { MessageBox.Show("异常信息:" + ex.Message); } //再看两个数据范围是否相同 IRasterDataProvider forValRaster = GeoDataDriver.Open(forValFile) as IRasterDataProvider; IRasterDataProvider toValRaster = GeoDataDriver.Open(toValFile) as IRasterDataProvider; if (forValRaster.CoordEnvelope.MaxX != toValRaster.CoordEnvelope.MaxX || forValRaster.CoordEnvelope.MinX != toValRaster.CoordEnvelope.MinX || forValRaster.CoordEnvelope.MaxY != toValRaster.CoordEnvelope.MaxY || forValRaster.CoordEnvelope.MinY != toValRaster.CoordEnvelope.MinY || toValRaster.Height != forValRaster.Height || toValRaster.Width != toValRaster.Width) { MessageBox.Show("两个数据空间范围不一致"); //这里也可修改为读取两数据的交差范围,做直方图 return(null); } #region//读取数据 Int16[] toValbuffer = new Int16[toValRaster.Height * toValRaster.Width]; Int16[] forValbuffer = new Int16[toValRaster.Height * toValRaster.Width]; Int16[] toVal = new Int16[toValRaster.Height * toValRaster.Width]; Int16[] forVal = new Int16[toValRaster.Height * toValRaster.Width]; IRasterBand toValBand = toValRaster.GetRasterBand(1); IRasterBand forValBand = forValRaster.GetRasterBand(1); unsafe { fixed(Int16 *pointer = toValbuffer) { IntPtr ptr = new IntPtr(pointer); toValBand.Read(0, 0, toValRaster.Width, toValRaster.Height, ptr, toValRaster.DataType, toValRaster.Width, toValRaster.Height); for (int i = 0; i < toValRaster.Height * toValRaster.Width; i++) { toVal[i] = toValbuffer[i]; } } fixed(Int16 *pointer = forValbuffer) { IntPtr ptr = new IntPtr(pointer); forValBand.Read(0, 0, forValRaster.Width, forValRaster.Height, ptr, forValRaster.DataType, forValRaster.Width, forValRaster.Height); for (int i = 0; i < forValRaster.Height * forValRaster.Width; i++) { forVal[i] = forValbuffer[i]; } } } #endregion IExtractResultArray array = new ExtractResultArray("统计表格"); if (args.CreatHistogram) { List <string[]> listRowHist = new List <string[]>(); string histfilename = ""; IStatResult fresult = null; int maxcol = 10; if (!String.IsNullOrEmpty(args.MaxColumns)) { maxcol = Convert.ToInt32(args.MaxColumns); } IStaticComputer <Int16> computer = new StaticComputerInt16(); listRowHist = computer.ComputeDeviation(toVal, forVal, GetInvalidArray(args.Invalid), GetInvalidArray(args.ForInvalid), maxcol); string sentitle = "统计日期:" + DateTime.Now.ToShortDateString(); string[] columns = new string[] { "偏差值", "累加值" }; fresult = new StatResult(sentitle, columns, listRowHist.ToArray()); string title = "陆表温度产品偏差直方图"; histfilename = StatResultToFile(new string[] { toValFile }, fresult, "VAL", "HIST", title, null, 1, true, 1); IFileExtractResult res = new FileExtractResult("HIST", histfilename); array.Add(res); } if (args.CreatRMSE) { IStaticComputer <Int16> computer = new StaticComputerInt16(); double rmse = computer.ComputeRMSE(toVal, forVal, GetInvalidArray(args.Invalid), GetInvalidArray(args.ForInvalid)); MessageBox.Show("数据均方根误差是:" + Convert.ToString(rmse)); } #region 用这种方式出栅格数据的散点图 //if (args.CreatScatter) //{ // List<string[]> listRow = new List<string[]>(); //散点图 // for (int i = 0; i < toValRaster.Height * toValRaster.Width; i++) // { // //剔除无效值 // if (!String.IsNullOrEmpty(args.invalid)) // { // if (args.invalid.Contains(Convert.ToString(toVal[i])) || args.invalid.Contains(Convert.ToString(forVal[i]))) // { // } // else // { // string[] row = new string[] { Convert.ToString(toVal[i]), Convert.ToString(forVal[i]) }; // listRow.Add(row); // } // } // else // { // string[] row = new string[] { Convert.ToString(toVal[i]), Convert.ToString(forVal[i]) }; // listRow.Add(row); // } // } // string[][] rows = listRow.ToArray(); // IStatResult result = new StatResult("统计时间:", new string[] { "待验证云参数", "MOD06云产品" }, rows); // string title = "陆表温度数据与MODIS LST对比"; // string filename = ""; // try // { // using (StatResultToChartInExcelFile excelControl = new StatResultToChartInExcelFile()) // { // excelControl.Init(masExcelDrawStatType.xlXYScatter); // excelControl.Add("数据对比", result, true, 0, false, result.Columns[0], result.Columns[1 // ]); // filename = StatResultToFile(new string[] { toValFile }, result, "VAL", "SCAT", title, null, 1, true, 1); // if (!filename.ToUpper().EndsWith(".XLSX")) // filename += ".XLSX"; // excelControl.SaveFile(filename); // IFileExtractResult res = new FileExtractResult("SCAT", filename); // array.Add(res); // } // } // catch (Exception ex) // { // } //} #endregion return(array); }
private IExtractResult CompareAlgorithm() { string[] files = GetStringArray("SelectedPrimaryFiles"); string file = _argumentProvider.GetArg("SelectedPrimaryFiles").ToString(); if (files == null && string.IsNullOrEmpty(file)) { return(null); } if (files != null && files.Length < 2) { return(null); } if (files == null && !string.IsNullOrEmpty(file)) { string[] fnames = file.Split('*'); if (fnames != null && fnames.Length > 1) { foreach (string item in fnames) { if (!File.Exists(item)) { return(null); } } files = fnames; } else { return(null); } } //文件列表排序 string[] dstFiles = SortFileName(files); string outFileIdentify = GetStringArgument("OutFileIdentify"); string productIdentify = _subProductDef.ProductDef.Identify; ExtractResultArray results = new ExtractResultArray(productIdentify + _identify); List <IPixelFeatureMapper <Int16> > rasterList = new List <IPixelFeatureMapper <short> >(); List <RasterIdentify> rstIdentifys = new List <RasterIdentify>(); for (int i = 0; i < dstFiles.Length - 1; i++) { IPixelFeatureMapper <Int16> rasterResult = MakeCompareRaster <float, Int16>(productIdentify, dstFiles[i], dstFiles[i + 1], (fstFileValue, sedFileValue) => { if (fstFileValue == 1f && sedFileValue == 1f) { return(1); } else if (fstFileValue == 0f && sedFileValue == 1f) { return(4); } else if (fstFileValue == 1f && sedFileValue == 0f) { return(5); } else { return(0); } }, true); if (rasterResult == null) { continue; } rasterList.Add(rasterResult); rstIdentifys.Add(new RasterIdentify(new string[] { dstFiles[i], dstFiles[i + 1] })); } if (rasterList.Count == 0) { return(null); } else { for (int i = 0; i < rasterList.Count; i++) { RasterIdentify rid = GetRasterIdentifyID(rstIdentifys[i]); IInterestedRaster <Int16> iir = new InterestedRaster <Int16>(rid, rasterList[i].Size, rasterList[i].CoordEnvelope, null); iir.Put(rasterList[i]); iir.Dispose(); FileExtractResult res = new FileExtractResult(outFileIdentify, iir.FileName); res.SetDispaly(false); results.Add(res); } } return(results); }
private IExtractResult VirrAlgorithm() { int farInfraredNo1, farInfraredNo2; IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster; farInfraredNo1 = TryGetBandNo(bandNameRaster, "FarInfrared1"); farInfraredNo2 = TryGetBandNo(bandNameRaster, "FarInfrared2"); if (farInfraredNo1 == -1 || farInfraredNo2 == -1) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } int[] bandNos = new int[] { farInfraredNo1, farInfraredNo2 }; if (_argumentProvider.GetArg("BinaryFile") == null) { PrintInfo("获取判识结果文件失败。"); return(null); } string dblvFile = _argumentProvider.GetArg("BinaryFile").ToString(); if (string.IsNullOrEmpty(dblvFile) || !File.Exists(dblvFile)) { PrintInfo("获取判识结果文件失败。"); return(null); } string angleFile = _argumentProvider.GetArg("AngleFile").ToString(); if (string.IsNullOrEmpty(angleFile) || !File.Exists(angleFile)) { PrintInfo("获取太阳天顶角文件失败。"); return(null); } //参数检查与获取 string landTypeFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemData\\ProductArgs\\DST\\GlobleLandCover.dat"); if (!File.Exists(landTypeFile)) { PrintInfo("土地类型文件不存在!"); return(null); } string tempFile = _argumentProvider.GetArg("TemperatureFile").ToString(); if (string.IsNullOrEmpty(tempFile) || !File.Exists(tempFile)) { PrintInfo("获取温度场文件失败。"); return(null); } string pressureFile = _argumentProvider.GetArg("PressureFile").ToString(); if (string.IsNullOrEmpty(pressureFile) || !File.Exists(pressureFile)) { PrintInfo("获取气压场文件失败。"); return(null); } //进行光学厚度与沙尘粒子有效半径计算需要文件:1、原始影像数据;2、查算表数据;3、太阳高度角数据 List <RasterMaper> inputRms = new List <RasterMaper>(); List <RasterMaper> outputRms = new List <RasterMaper>(); try { //当前影像(待判识文件) RasterMaper rm = new RasterMaper(_argumentProvider.DataProvider, bandNos); inputRms.Add(rm); //判识结果文件 IRasterDataProvider dblvPrd = GeoDataDriver.Open(dblvFile) as IRasterDataProvider; RasterMaper dblvRm = new RasterMaper(dblvPrd, new int[] { 1 }); inputRms.Add(dblvRm); //太阳天顶角文件 IRasterDataProvider angleDataPrd = GeoDataDriver.Open(angleFile) as IRasterDataProvider; RasterMaper anglerm = new RasterMaper(angleDataPrd, new int[] { 1 }); inputRms.Add(anglerm); //土地类型文件 IRasterDataProvider landTypeDataPrd = GeoDataDriver.Open(landTypeFile) as IRasterDataProvider; RasterMaper landTypeRm = new RasterMaper(landTypeDataPrd, new int[] { 1 }); inputRms.Add(landTypeRm); //温度场文件 IRasterDataProvider tempDataPrd = GeoDataDriver.Open(landTypeFile) as IRasterDataProvider; RasterMaper tempRm = new RasterMaper(tempDataPrd, new int[] { 1 }); inputRms.Add(tempRm); //气压场文件 IRasterDataProvider pressureDataPrd = GeoDataDriver.Open(pressureFile) as IRasterDataProvider; RasterMaper pressureRm = new RasterMaper(tempDataPrd, new int[] { 1 }); inputRms.Add(pressureRm); RasterIdentify ri = new RasterIdentify(_argumentProvider.DataProvider.fileName); ri.ProductIdentify = "DST"; ri.IsOutput2WorkspaceDir = true; IRasterDataProvider htRaster = CreateOutRaster(ri, dblvPrd, "0DHT"); RasterMaper htRm = new RasterMaper(htRaster, new int[] { 1 }); outputRms.Add(htRm); IRasterDataProvider optRaster = CreateOutRaster(ri, dblvPrd, "0OPT"); RasterMaper optRm = new RasterMaper(optRaster, new int[] { 1 }); outputRms.Add(optRm); //栅格数据映射 RasterMaper[] fileIns = inputRms.ToArray(); RasterMaper[] fileOuts = outputRms.ToArray(); //创建处理模型 RasterProcessModel <short, float> rfr = new RasterProcessModel <short, float>(); rfr.SetRaster(fileIns, fileOuts); #region rfr.RegisterCalcModel(new RasterCalcHandler <short, float>((rvInVistor, rvOutVistor, aoi) => { int landType; float t1 = 0, t2 = 0; if (rvInVistor[0].RasterBandsData[0] != null) { int length = rvInVistor[0].RasterBandsData[0].Length; for (int i = 0; i < length; i++) { if (rvInVistor[1].RasterBandsData[0][i] == 1) { if (rvInVistor[4].RasterBandsData[0][i] > 263) { t1 = rvInVistor[4].RasterBandsData[0][i] - 3; t2 = rvInVistor[4].RasterBandsData[0][i] + 3; } if (rvInVistor[4].RasterBandsData[0][i] < rvInVistor[0].RasterBandsData[0][i]) { t1 = rvInVistor[0].RasterBandsData[0][i]; t2 = rvInVistor[0].RasterBandsData[0][i] + 5; } //for(int m=0;m<) landType = rvInVistor[3].RasterBandsData[0][i]; //water if (landType == 0 || landType >= 17) { } //desert else if (landType == 16) { } else { } } } } })); #endregion rfr.Excute(); FileExtractResult htResult = new FileExtractResult("0DHT", htRaster.fileName, true); htResult.SetDispaly(false); FileExtractResult optResult = new FileExtractResult("0OPT", optRaster.fileName, true); optResult.SetDispaly(false); ExtractResultArray resultArray = new ExtractResultArray(_subProductDef.Identify); resultArray.Add(htResult); resultArray.Add(optResult); return(resultArray); } finally { for (int i = 1; i < inputRms.Count; i++) { if (inputRms[i].Raster != null) { inputRms[i].Raster.Dispose(); } } foreach (RasterMaper rm in outputRms) { if (rm.Raster != null) { rm.Raster.Dispose(); } } } }
private IExtractResult ModisAlgorithm() { int middleInfraredNo, farInfrared1No, farInfrared2No; IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster; middleInfraredNo = TryGetBandNo(bandNameRaster, "MiddleInfrared"); farInfrared1No = TryGetBandNo(bandNameRaster, "FarInfrared1"); farInfrared2No = TryGetBandNo(bandNameRaster, "FarInfrared2"); if (middleInfraredNo == -1 || farInfrared1No == -1 || farInfrared2No == -1) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } int[] bandNos = new int[] { middleInfraredNo, farInfrared1No, farInfrared2No }; if (_argumentProvider.GetArg("BinaryFile") == null) { PrintInfo("获取判识结果文件失败。"); return(null); } string dblvFile = _argumentProvider.GetArg("BinaryFile").ToString(); if (string.IsNullOrEmpty(dblvFile) || !File.Exists(dblvFile)) { PrintInfo("获取判识结果文件失败。"); return(null); } float mbtd = (float)_argumentProvider.GetArg("mbtd"); float mbt = (float)_argumentProvider.GetArg("mbt"); int ntype = Int32.Parse(_argumentProvider.GetArg("ntype").ToString()); //获取查找表参数 LookupTableArgument argument = new LookupTableArgument(); //进行光学厚度与沙尘粒子有效半径计算需要文件:1、原始影像数据;2、查算表数据 List <RasterMaper> inputRms = new List <RasterMaper>(); List <RasterMaper> outputRms = new List <RasterMaper>(); try { //当前影像(待判识文件) RasterMaper rm = new RasterMaper(_argumentProvider.DataProvider, bandNos); inputRms.Add(rm); IRasterDataProvider dblvPrd = GeoDataDriver.Open(dblvFile) as IRasterDataProvider; RasterMaper dblvRm = new RasterMaper(dblvPrd, new int[] { 1 }); inputRms.Add(dblvRm); RasterIdentify ri = new RasterIdentify(_argumentProvider.DataProvider.fileName); ri.ProductIdentify = "DST"; ri.IsOutput2WorkspaceDir = true; IRasterDataProvider reRaster = CreateOutRaster(ri, dblvPrd, "0DRE"); RasterMaper reRm = new RasterMaper(reRaster, new int[] { 1 }); outputRms.Add(reRm); IRasterDataProvider optRaster = CreateOutRaster(ri, dblvPrd, "0OPT"); RasterMaper optRm = new RasterMaper(optRaster, new int[] { 1 }); outputRms.Add(optRm); IRasterDataProvider denRaster = CreateOutRaster(ri, dblvPrd, "DDEN"); RasterMaper denRm = new RasterMaper(denRaster, new int[] { 1 }); outputRms.Add(denRm); //栅格数据映射 RasterMaper[] fileIns = inputRms.ToArray(); RasterMaper[] fileOuts = outputRms.ToArray(); //创建处理模型 RasterProcessModel <short, float> rfr = new RasterProcessModel <short, float>(); rfr.SetRaster(fileIns, fileOuts); #region rfr.RegisterCalcModel(new RasterCalcHandler <short, float>((rvInVistor, rvOutVistor, aoi) => { int nindex; double ocdiff = 0, mindiff = 0, den = 0, gcon; float den0, rpsize = 0, rpsize0, rpmin = 0.01f, rpmax = 100; double sgma = 2.0, sgdust = 2.5e-12; double dr = (Math.Log10(rpmax) - Math.Log10(rpmin)) / 100; if (rvInVistor[0].RasterBandsData[0] != null) { int length = rvInVistor[0].RasterBandsData[0].Length; for (int i = 0; i < length; i++) { if (rvInVistor[1].RasterBandsData[0][i] == 1) { float bt31 = rvInVistor[0].RasterBandsData[1][i] / 10f; float btd3132 = (rvInVistor[0].RasterBandsData[1][i] - rvInVistor[0].RasterBandsData[2][i]) / 10f; float btd2931 = (rvInVistor[0].RasterBandsData[0][i] - rvInVistor[0].RasterBandsData[1][i]) / 10f; for (int m = 0; m < 50; m++) { for (int n = 0; n < 29; n++) { ocdiff = Math.Pow(btd3132 - argument.Cbtd3132[m, n], 2) + Math.Pow((btd2931 - argument.Cbtd2931[m, n]), 2) * mbtd + Math.Pow((bt31 - argument.Cbt31[m, n]), 2) * mbt; if (ocdiff < mindiff || (m == 0 && n == 0)) { mindiff = ocdiff; rvOutVistor[0].RasterBandsData[0][i] = argument.Dref[n]; rvOutVistor[1].RasterBandsData[0][i] = argument.Dopt[m]; } } } //计算rvOutVistor[2].RasterBandsData[0][i]载沙量 if (rvOutVistor[0].RasterBandsData[0][i] <= 1) { nindex = (int)(rvOutVistor[0].RasterBandsData[0][i] * 10); } else { nindex = (int)(rvOutVistor[0].RasterBandsData[0][i]) + 9; } den0 = rvOutVistor[1].RasterBandsData[0][i] / argument.Ext55[nindex - 1]; double ravg = Calravg(rvOutVistor[1].RasterBandsData[0][i], sgma); double tcv = 0; rpsize = rpmin; for (int j = 0; j < 100; j++) { //源代码中未定义type为1,2所需变量初始值 den = DType(ntype, rpsize, 0, 0, 0, 0, 0, 0, 0, den0, ravg, sgma); rpsize0 = rpsize; rpsize = (float)Math.Pow(10, (Math.Log10(rpsize) + dr)); gcon = 4f / 3 * Math.PI * Math.Pow(rpsize0, 3) * den * (rpsize - rpsize0); tcv += gcon; } float value = (float)((tcv * sgdust * 1.0e+9 * 10)); rvOutVistor[2].RasterBandsData[0][i] = value > 50f ? 50f : value; } } } })); #endregion rfr.Excute(); FileExtractResult reResult = new FileExtractResult("0DRE", reRaster.fileName, true); reResult.SetDispaly(false); FileExtractResult optResult = new FileExtractResult("0OPT", optRaster.fileName, true); optResult.SetDispaly(false); FileExtractResult denResult = new FileExtractResult("DDEN", denRaster.fileName, true); ExtractResultArray resultArray = new ExtractResultArray(_subProductDef.Identify); resultArray.Add(reResult); resultArray.Add(optResult); //生成载沙量 resultArray.Add(denResult); return(resultArray); } finally { for (int i = 1; i < inputRms.Count; i++) { if (inputRms[i].Raster != null) { inputRms[i].Raster.Dispose(); } } foreach (RasterMaper rm in outputRms) { if (rm.Raster != null) { rm.Raster.Dispose(); } } } }
private IExtractResult MicroVisSNWSDAlgorithm(Action <int, string> progressTracker) { string inputSDFileName = _argumentProvider.GetArg("RasterSDFile").ToString(); if (string.IsNullOrEmpty(inputSDFileName) || !File.Exists(inputSDFileName)) { PrintInfo("缺少微波雪深文件"); return(null); } string inputCLDSNWFileName = ""; string inputVISNWFileName = ""; string identify = ""; string[] snowfname = GetStringArray("RasterVISNWFiles"); if (progressTracker != null) { progressTracker(1, "开始计算"); } if (snowfname == null || snowfname.Length <= 0) { PrintInfo("请选可见光雪判识文件!"); return(null); } if (snowfname.Length == 1) { inputVISNWFileName = snowfname[0]; } else { identify = "SNDB"; IFileExtractResult vissnowFilename = ComposeVISSNW(snowfname, identify); inputVISNWFileName = vissnowFilename.FileName; } progressTracker(20, "计算完成20%"); string[] cloudfname = GetStringArray("RasterCLDSNWFiles"); if (cloudfname == null || cloudfname.Length <= 0) { PrintInfo("请选可见光云判识文件!"); return(null); } if (cloudfname.Length == 1) { inputCLDSNWFileName = cloudfname[0]; } else { identify = "0CLM"; IFileExtractResult viscldFilename = ComposeVISSNW(cloudfname, identify); inputCLDSNWFileName = viscldFilename.FileName; } progressTracker(50, "计算完成50%"); if (string.IsNullOrEmpty(inputVISNWFileName) || !File.Exists(inputVISNWFileName) || string.IsNullOrEmpty(inputCLDSNWFileName) || !File.Exists(inputCLDSNWFileName)) { PrintInfo("缺少可见光雪或者云判识文件"); return(null); } else { IExtractResultArray array = new ExtractResultArray("融合雪深"); IFileExtractResult visFilename = ComputeVIS(inputVISNWFileName, inputCLDSNWFileName); array.Add(visFilename); progressTracker(70, "计算完成70%"); string visSNWfilename = visFilename.FileName; IFileExtractResult microvisfilename = ComputeSD(inputSDFileName, visSNWfilename); array.Add(microvisfilename); //中值滤波 Int16 smoothwindow = 5; string microvisName = microvisfilename.FileName; IFileExtractResult midSDFilterResult = ComputerMid(microvisName, smoothwindow);//滤波 array.Add(midSDFilterResult); progressTracker(100, "计算完成"); return(array); } }
private IExtractResult JuPingAnalysisAlgorithm(Action <int, string> progressTracker) { string[] inputCurrentFiles = null; //= ExportManager.GetInstance().List.ToArray();//GetStringArray("RasterCurrentFile"); 由查询那里获得 string[] inputHistoryFiles = null; List <string> list1 = ExportManager.GetInstance().List; //得到的是从数据库里查询出来的周期数据 StatisticResultManager manager = StatisticResultManager.GetInstance(); List <StatisticResult> list = manager.List; List <string> list2 = manager.GetFilePathFromList(); //得到的是基于数据查询的数据又做的统计数据 regionNames = _argumentProvider.GetArg("regionNames") as string; //处理后的数据,用它来出专题图 List <string> afterProcessfiles = new List <string>(); #region 获得目标区域 aoiContainer = new GeoDo.RSS.Core.VectorDrawing.AOIContainerLayer(); string fieldName; string shapeFilename; int fieldIndex = -1; List <string> fieldValues = new List <string>(); string regionsname = ""; using (frmStatSubRegionTemplates frm = new frmStatSubRegionTemplates()) { frm.listView1.MultiSelect = true; if (frm.ShowDialog() == DialogResult.OK) { Feature[] fets = frm.GetSelectedFeatures(); fets = frm.GetStatFeatures(out fieldName, out shapeFilename, out fieldIndex); if (fets == null) { aoiContainer = null; regionsname = "全国"; } else { string chinafieldValue = fets[0].GetFieldValue(fieldIndex); if (chinafieldValue == "中国") { aoiContainer = null; regionsname = "全国"; } else { foreach (Feature fet in fets) { fieldValues.Add(fet.GetFieldValue(fieldIndex)); //获得选择区域名称 aoiContainer.AddAOI(fet); } foreach (string region in fieldValues) { regionsname += region; } if (regionsname.Contains("西藏") && regionsname.Contains("青海")) { regionsname = "青藏地区"; } if (!string.IsNullOrEmpty(regionNames)) { regionsname = regionNames.Trim(); } } } } else { return(null); } } #endregion Regex DataReg = new Regex(@"(?<year>\d{4})", RegexOptions.Compiled); //处理后的数据存储路径 string savePath = _argumentProvider.GetArg("HistoryDataSave") as string; string jpsavepath = savePath + "\\" + "距平分析"; if (!System.IO.Directory.Exists(jpsavepath))//如果不存在这个路径 { System.IO.Directory.CreateDirectory(jpsavepath); } //参数设置 List <string> paraset = _argumentProvider.GetArg("paraSet") as List <string>; string[] paras = paraset.ToArray(); List <string> jpfiles = new List <string>();//存放相减的距平分析文件 string date = ""; string jupingfile = ""; IExtractResultArray array = new ExtractResultArray("距平分析"); string Nostr = ""; //排除非选择的轨道数据 if (paras[0] == "Ascend") { Nostr = "_D_"; } if (paras[0] == "Descend") { Nostr = "_A_"; } if (paras[1] == "winter") // inputCurrentFiles = manager.GetFilePathFromList() 冬季的数所是统计出来的。 { // inputHistoryFiles 需要再重新计算一次 *** 这是多对一计算距平 //比如说要算2000-2013年冬季的距平,需要先分别算出每年冬季的值,用这些值算总的均值。再分别用每年冬季减去总冬季值。 List <string> files = new List <string>(); foreach (string file in list2) { if (!Path.GetFileName(file).Contains(Nostr)) { files.Add(file); } } inputCurrentFiles = files.ToArray(); string outHistoryFile = jpsavepath + "\\" + Path.GetFileNameWithoutExtension(inputCurrentFiles[0]).Substring(0, 14) + "_" + paras[2] + ".dat"; SNWParaStat snwStat = new SNWParaStat(); snwStat.SNWParaAvgStat(inputCurrentFiles, 0.1f, outHistoryFile); List <string> temphistory = new List <string>(); temphistory.Add(outHistoryFile); inputHistoryFiles = temphistory.ToArray(); if (inputCurrentFiles == null || inputCurrentFiles.Length < 0 || inputHistoryFiles == null || inputHistoryFiles.Length < 0) { PrintInfo("缺少分析文件"); return(null); } foreach (string inputCurrentFile in inputCurrentFiles) { Regex DataReg2 = new Regex(@"(?<year>\d{4})_(?<month>\d{2})_(?<year>\d{4})_(?<month>\d{1})", RegexOptions.Compiled); Match m = DataReg2.Match(inputCurrentFile); //提取每年冬季的时间 string year = ""; if (m.Success) { year = m.Value; } jupingfile = JuPinComputer(inputCurrentFile, inputHistoryFiles[0], jpsavepath); string hdrfile = Path.GetDirectoryName(jupingfile) + "\\" + Path.GetFileNameWithoutExtension(jupingfile) + ".hdr"; FileInfo fi = new FileInfo(jupingfile); string newjpfile = Path.Combine(jpsavepath, Path.GetFileNameWithoutExtension(jupingfile) + "_" + year.Substring(0, 4) + ".dat"); string newhdrfile = Path.Combine(jpsavepath, Path.GetFileNameWithoutExtension(jupingfile) + "_" + year.Substring(0, 4) + ".hdr"); fi.MoveTo(newjpfile); FileInfo fihdr = new FileInfo(hdrfile); fihdr.MoveTo(newhdrfile); jpfiles.Add(newjpfile); } } else { //例 2013年11月上旬-2013年11月下旬分别与1987-2013年11月上中下旬 同期比较 一对一计算距平 inputCurrentFiles = list1.ToArray(); inputHistoryFiles = list2.ToArray(); if (inputCurrentFiles == null || inputCurrentFiles.Length < 0 || inputHistoryFiles == null || inputHistoryFiles.Length < 0) { PrintInfo("缺少分析文件"); return(null); } if ((inputCurrentFiles.Length) * 2 != inputHistoryFiles.Length) { MessageBox.Show("当年数据与同期数据不对应"); return(null); } foreach (string inputCurrentFile in inputCurrentFiles) { //先假设选择的是旬数据 MWS_MWSD_China_Xun_0SD_A_2011_1_avg.dat // 则同期旬数据 MWS_MWSD_China_Xun_0SD_A_1989_2011_1_avg.dat string cfile = Path.GetFileNameWithoutExtension(inputCurrentFile); Match m = DataReg.Match(cfile); if (m.Success) { date = m.Value; //根据年4个数字来拆分字符串 } string bhalf = cfile.Substring(0, cfile.IndexOf(date)); string ahalf = cfile.Substring(cfile.IndexOf(date) + 4, cfile.Length - 4 - cfile.IndexOf(date)); foreach (string inputHistoryFile in inputHistoryFiles) { string aa = Path.GetFileNameWithoutExtension(inputHistoryFile); if (aa.Contains(bhalf) && aa.Contains(ahalf) && aa.Contains(date) && !aa.Contains(Nostr)) { jupingfile = JuPinComputer(inputCurrentFile, inputHistoryFile, jpsavepath); jpfiles.Add(jupingfile); break; } } } } #region 距平的文件在jpfiles 中,下面是裁切和平滑处理 MulRegionsClip muticlip = new MulRegionsClip(); //裁切 MWSSmoothHelp smooth = new MWSSmoothHelp(); //平滑 //创建专题图路径 gxdsave = jpsavepath + "\\" + regionsname + "\\" + "专题图"; if (!System.IO.Directory.Exists(gxdsave))//如果不存在这个路径 { System.IO.Directory.CreateDirectory(gxdsave); } //创建平滑路径 string smoothsave = jpsavepath + "\\" + regionsname + "\\" + "平滑"; if (!System.IO.Directory.Exists(smoothsave)) { System.IO.Directory.CreateDirectory(smoothsave); } //创建平滑\\中值 string filtersave = smoothsave + "\\" + "中值"; if (!System.IO.Directory.Exists(filtersave)) { System.IO.Directory.CreateDirectory(filtersave); } if (aoiContainer == null) { //只做中值处理 foreach (string infile in jpfiles) { // 先判断这个文件是否存在,存在了就不做 string filterfile = filtersave + "\\" + Path.GetFileName(infile); if (!File.Exists(filterfile)) { filterfile = smooth.ComputerMid(infile, 5, filtersave); } afterProcessfiles.Add(filterfile); toBarfiles.Add(infile); } } else { // 裁切 // 中值 // 插值 string clipsave = jpsavepath + "\\" + regionsname + "\\" + "裁切"; if (!System.IO.Directory.Exists(clipsave))//如果不存在这个路径 { System.IO.Directory.CreateDirectory(clipsave); } string bilisave = smoothsave + "\\" + "插值"; if (!System.IO.Directory.Exists(bilisave)) { System.IO.Directory.CreateDirectory(bilisave); } foreach (string infile in jpfiles) { string newclipfile = clipsave + "\\" + Path.GetFileName(infile).Replace("China", regionsname); if (!File.Exists(newclipfile)) { string clipfile = muticlip.MutiRegionsClip(infile, aoiContainer, clipsave); string hdrfile = Path.GetDirectoryName(clipfile) + "\\" + Path.GetFileNameWithoutExtension(clipfile) + ".hdr"; //重命名 string newhdrfile = Path.Combine(Path.GetDirectoryName(clipfile), Path.GetFileNameWithoutExtension(infile).Replace("China", regionsname) + ".hdr"); FileInfo fi = new FileInfo(clipfile); fi.MoveTo(newclipfile); FileInfo fihdr = new FileInfo(hdrfile); fihdr.MoveTo(newhdrfile); } toBarfiles.Add(newclipfile); //加上裁切后的文件 //中值、插值 string filterfile = smooth.ComputerMid(newclipfile, 5, filtersave); string bilifile = smooth.Bilinear(filterfile, 10, bilisave); afterProcessfiles.Add(bilifile); } } #endregion //出专题图 #region IExtractResultArray results = new ExtractResultArray(""); foreach (string arguments in afterProcessfiles.ToArray()) { string product = ""; if (arguments.Contains("MWSD")) { product = "雪深"; _argumentProvider.SetArg("OutFileIdentify", "JPDI"); } if (arguments.Contains("MSWE")) { product = "雪水当量"; _argumentProvider.SetArg("OutFileIdentify", "JPEI"); } //解析文件名确定专题图名称 string filename = Path.GetFileNameWithoutExtension(arguments); if (paras[1] == "usual") { Regex DataReg1 = new Regex(@"(?<year>\d{4})_(?<year>\d{4})", RegexOptions.Compiled); Match m = DataReg1.Match(filename); string year = ""; if (m.Success) { year = m.Value; } //提取年至avg之间的字符 string filetime = filename.Substring(filename.IndexOf(year), filename.Length - 3 - filename.IndexOf(year)); string[] mxchars = filetime.Split(new char[] { '_' }); string mx = "";//月+旬 if (filename.Contains("Xun")) { if (mxchars[3] == "1") { mx = mxchars[2] + "月" + "上旬"; } if (mxchars[3] == "2") { mx = mxchars[2] + "月" + "中旬"; } if (mxchars[3] == "3") { mx = mxchars[2] + "月" + "下旬"; } } if (filename.Contains("Month")) { mx = mxchars[2] + "月"; } imgname = year.Substring(5, 4) + "年" + mx + regionsname + product + "距平分布图(" + paras[2] + "年)"; } if (paras[1] == "winter") { imgname = Path.GetFileNameWithoutExtension(arguments).Substring(Path.GetFileNameWithoutExtension(arguments).Length - 4, 4) + "年" + "冬季" + regionsname + product + "距平分布图(" + paras[2] + "年)"; } _argumentProvider.SetArg("SelectedPrimaryFiles", arguments); _argumentProvider.SetArg("fileOpenArgs", arguments); FileExtractResult result = ThemeGraphyResult(null) as FileExtractResult; //增加矢量 string autopath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"SystemData\ProductArgs\MWS\shppath.txt"); string shpFile = ""; if (File.Exists(autopath)) { FileStream fauto = new FileStream(autopath, FileMode.Open, FileAccess.Read); StreamReader rauto = new StreamReader(fauto, Encoding.GetEncoding("gb2312")); shpFile = rauto.ReadLine(); rauto.Close(); fauto.Close(); } else { shpFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"数据引用\基础矢量\行政区划\线\中国边界_线.shp"); } CreateMcd(shpFile); _shpFile = shpFile; _gxdFile = (result as FileExtractResult).FileName; AddShpToGxd(); string newresultfile = Path.Combine(gxdsave, Path.GetFileNameWithoutExtension(arguments) + ".gxd"); FileInfo fi = new FileInfo(result.FileName); if (!File.Exists(newresultfile)) { fi.MoveTo(newresultfile); } else { FileInfo fi1 = new FileInfo(newresultfile); fi1.Delete(); } IFileExtractResult res = new FileExtractResult(_subProductDef.Identify, newresultfile, false); results.Add(res); } #endregion return(results); }
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); }
private IExtractResult DataVal(ValArguments args) { //分波长,每个波长多时次进行验证(前提各时次地理位置相同) //2,3,4 IVectorFeatureDataReader reader = AeronetDataReaderFactory.GetVectorFeatureDataReader(args.FileNamesToVal[0], new object[] { "LEV20" }); Dictionary <string, List <AslDataSet> >[] fieldValue = new Dictionary <string, List <AslDataSet> >[] { new Dictionary <string, List <AslDataSet> > { }, new Dictionary <string, List <AslDataSet> > { }, new Dictionary <string, List <AslDataSet> > { } }; ///分别为470,550,650波长,每个字典分别为站点名为关键字,值为观测站点值的时间序列 foreach (string item in args.FileNamesForVal) { RasterIdentify rid = new RasterIdentify(item); using (IRasterDataProvider dataPrd2Val = GeoDataDriver.Open(item) as IRasterDataProvider) { //470 for (int bandNo = 2; bandNo < 5; bandNo++) { string description = dataPrd2Val.GetRasterBand(bandNo).Description; string key = Regex.Match(description, pattern).ToString(); int bandLength = Int32.Parse(key); int fieldIndex = 0; //求验证数据中的Field for (int i = 5; i < 20; i++) { if (bandLength >= GetBandLength(reader.Fields[i]) && bandLength < GetBandLength(reader.Fields[i - 1])) { fieldIndex = i; break; } } //验证数据中在范围内时间内的Feature string timeString = rid.OrbitDateTime.ToString("dd:MM:yyyy"); string t3 = rid.OrbitDateTime.ToString("yyyy/MM/dd"); Feature[] feature4Vals = GetValFeature(reader.Features, dataPrd2Val.CoordEnvelope, timeString); foreach (Feature fet in feature4Vals) { //已存在该站点 string location = fet.FieldValues[0]; double value4Val = StringToDouble(fet.FieldValues, fieldIndex); if (value4Val == -9999) { continue; } double value2Val = ReadDataValueInRaster(dataPrd2Val, fet.Geometry.Envelope.MinX, fet.Geometry.Envelope.MinY, bandNo); if (value2Val < 0)//去除无效值 { continue; } if (fieldValue[bandNo - 2].ContainsKey(location)) { fieldValue[bandNo - 2][location].Add(new AslDataSet(t3, new double[] { value2Val, value4Val })); } else { fieldValue[bandNo - 2].Add(location, new List <AslDataSet> { new AslDataSet(t3, new double[] { value2Val, value4Val }) }); } } } } } IExtractResultArray array = new ExtractResultArray("统计表格"); //生成结果 if (args.CreatScatter) { for (int i = 0; i < fieldValue.Length; i++) { foreach (string key in fieldValue[i].Keys) { List <string[]> rowList = new List <string[]>(); foreach (AslDataSet set in fieldValue[i][key]) { rowList.Add(new string[] { set.DateString, set.SiteValue[0].ToString(), set.SiteValue[1].ToString() }); } string[][] rows = rowList.ToArray(); IStatResult result = new StatResult("站点名称:" + key + "波长:" + GetBandLength(i), new string[] { "时间", "待验证ASL", "Aeronet LST" }, rows); string title = "气溶胶产品数据对比"; string filename = GetOutputFileName(args.FileNamesForVal, "SCAT", key, GetBandLength(i)); try { using (StatResultToChartInExcelFile excelControl = new StatResultToChartInExcelFile()) { excelControl.Init(masExcelDrawStatType.xlXYScatter); excelControl.Add(title, result, true, 1, false, result.Columns[1], result.Columns[2]); if (!filename.ToUpper().EndsWith(".XLSX")) { filename += ".XLSX"; } excelControl.SaveFile(filename); IFileExtractResult res = new FileExtractResult("SCAT", filename); array.Add(res); } } catch (Exception ex) { } } } } if (args.CreatTimeSeq) { for (int i = 0; i < fieldValue.Length; i++) { foreach (string key in fieldValue[i].Keys) { List <string[]> rowList = new List <string[]>(); foreach (AslDataSet set in fieldValue[i][key]) { rowList.Add(new string[] { set.DateString, set.SiteValue[0].ToString(), set.SiteValue[1].ToString() }); } string[][] rows = rowList.ToArray(); IStatResult result = new StatResult("站点名称:" + key + "波长:" + GetBandLength(i), new string[] { "时间", "待验证ASL", "Aeronet LST" }, rows); string title = "气溶胶产品数据对比"; string filename = GetOutputFileName(args.FileNamesForVal, "SEQD", key, GetBandLength(i)); try { using (StatResultToChartInExcelFile excelControl = new StatResultToChartInExcelFile()) { excelControl.Init(masExcelDrawStatType.xlLineMarkers); excelControl.Add(title, result, true, 0, true, result.Columns[0], "ASL"); if (!filename.ToUpper().EndsWith(".XLSX")) { filename += ".XLSX"; } excelControl.SaveFile(filename); IFileExtractResult res = new FileExtractResult("SEQD", filename); array.Add(res); } } catch (Exception ex) { } } } } return(array); }
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 IExtractResult SnowPrdAlgorithm() { string inputFileName = _argumentProvider.DataProvider.fileName; if (string.IsNullOrEmpty(inputFileName) || !File.Exists(inputFileName)) { return(null); } int[] bandNos = CheckBandNos(); if (bandNos == null || bandNos.Length < 10) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } double[] sdParas = GetSDPara(); if (sdParas == null) { PrintInfo("雪深计算参数为空。"); return(null); } //查找参数数据 string argFileDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemData\\ProductArgs\\SNW\\SnowArgFile"); string fileNameBare = Path.Combine(argFileDir, "china_bares.dat"); string filenameGrass = Path.Combine(argFileDir, "china_grass.dat"); string filenameForest = Path.Combine(argFileDir, "china_forest.dat"); string filenameFarmhand = Path.Combine(argFileDir, "china_farmhand.dat"); string filenameDensity = Path.Combine(argFileDir, "china_snow_density.dat"); if (!File.Exists(filenameDensity)) { return(null); } //1、查找是否存在各土地类型百分比文件(4个),不存在则生成 string bareFracFile = Path.ChangeExtension(fileNameBare, "_frac.dat"); string grassFracFile = Path.ChangeExtension(filenameGrass, "_frac.dat"); string forestFracFile = Path.ChangeExtension(filenameForest, "_frac.dat"); string farmhandFracFile = Path.ChangeExtension(filenameFarmhand, "_frac.dat"); string[] argFiles = new string[] { bareFracFile, grassFracFile, forestFracFile, farmhandFracFile }; foreach (string file in argFiles) { string sumFile = null; if (!File.Exists(file)) { //计算 //1)生成SummaryFile(不存在) sumFile = GetArgSummaryFile(fileNameBare, filenameGrass, filenameForest, filenameFarmhand); //2)计算某个百分比文件 ComputeFracFile(sumFile, file); } } //2、计算雪深、雪水当量 //雪深 IExtractResultArray array = new ExtractResultArray("雪深当量"); IFileExtractResult depthResult = ComputeSnowDepth(inputFileName, bandNos, argFiles, sdParas); //雪水当量 if (!File.Exists(filenameDensity)) { return(null); } string depthFileName = (depthResult as FileExtractResult).FileName; if (!File.Exists(depthFileName)) { return(null); } IFileExtractResult sweResult = ComputeSnowSWE(filenameDensity, depthFileName); array.Add(depthResult); array.Add(sweResult); return(array); }
private IExtractResult StatProcentRaster <T>(string fname, Dictionary <string, Func <short, bool> > filters, Action <int, string> progressTracker) { string statString = AreaStatProvider.GetAreaStatItemFileName("行政区划"); SortedDictionary <string, double[][]> srcResult = RasterStatFactory.StatPercent <short>(fname, statString, filters, progressTracker); //删除为空的AOI区域以及计算百分比 SortedDictionary <string, double[][]> statResult = new SortedDictionary <string, double[][]>(); //区间个数 int regionCount = filters.Keys.Count; foreach (string key in srcResult.Keys) { if (srcResult[key] == null) { continue; } else { int zeroCount = 0; double[][] value = new double[regionCount][]; for (int i = 0; i < regionCount; i++) { value[i] = new double[] { srcResult[key][i][0], srcResult[key][i][0] / srcResult[key][i][1] * 100 }; if (value[i][0] == 0) { zeroCount++; } } //如果全为0,也不添加 if (zeroCount < regionCount) { statResult.Add(key, value); } } } if (statResult.Count == 0) { return(null); } string productName = _subProductDef.ProductDef.Name; string title = productName + "行政区划"; string subTitle = GetSubTitle(fname); string[] colDescs = new string[] { "面积", "百分比" }; IStatResult[] results = DicToStatResult(statResult, filters.Keys.ToArray(), subTitle, colDescs); if (results == null) { return(null); } string outFileIdentify = GetStringArgument("OutFileIdentify"); string[] outFileIdentifys = new string[] { outFileIdentify, outFileIdentify.Substring(1) + "P" }; string productIdentify = _subProductDef.ProductDef.Identify; IExtractResultArray array = new ExtractResultArray("LST"); string filename = null; for (int i = 0; i < results.Length; i++) { if (i >= outFileIdentifys.Length) { break; } filename = StatResultToFile(new string[] { fname }, results[i], productIdentify, outFileIdentifys[i], title + colDescs[i] + "统计", null, 1, false, 1); array.Add(new FileExtractResult(outFileIdentify, filename)); } return(array); }
public override IExtractResult Make(Action <int, string> progressTracker) { if (!CheckArguments()) { return(null); } Dictionary <DateTime, List <string> > orderedFiles = GroupByOrbitDate(); if (orderedFiles.Count == 0) { return(null); } object obj = _argumentProvider.GetArg("ThemeGraphyGenerator"); if (obj == null) { return(null); } IThemeGraphGenerator tgg = obj as IThemeGraphGenerator; List <string> rdpList = new List <string>();//按照日期生成的多个日最大合成数据 //每天生成一个最大日合成图 foreach (DateTime time in orderedFiles.Keys) { RasterMoasicProcesser processer = new RasterMoasicProcesser(); List <IRasterDataProvider> srcdata = new List <IRasterDataProvider>(); try { foreach (string item in orderedFiles[time]) { IRasterDataProvider rdp = GeoDataDriver.Open(item) as IRasterDataProvider; if (rdp != null) { srcdata.Add(rdp); } } string fileName = null; IFileNameGenerator generator = GetFileNameGenerator(); if (generator == null) { fileName = string.Empty; } else { fileName = generator.NewFileName(CreatRasterIndetifyId(orderedFiles[time].ToArray(), "SNW", "MAXI", GetDataIdentify(), ".LDF", null)); } using (IRasterDataProvider dstPrd = processer.Moasic <Int16>(srcdata.ToArray(), "LDF", fileName, false, null, "MAX", null, (srcValue, dstValue) => { return(srcValue > dstValue ? srcValue : dstValue); })) { if (dstPrd != null) { rdpList.Add(dstPrd.fileName); } } } finally { foreach (IRasterDataProvider rdp in srcdata) { rdp.Dispose(); } srcdata.Clear(); } } string templatName = GetStringArgument("ThemeGraphTemplateName"); string colorTabelName = GetColorTableName("colortablename"); IExtractResultArray resultArray = new ExtractResultArray("MAXI"); foreach (string file in rdpList) { tgg.Generate(file, templatName, null, null, "MAXI", colorTabelName); string resultFilename = tgg.Save(); if (string.IsNullOrEmpty(resultFilename)) { continue; } resultArray.Add(new FileExtractResult("MAXI", resultFilename)); } if (resultArray != null) { return(resultArray); } return(null); }
public override IExtractResult MakeExtProduct(IPixelIndexMapper piexd, Action <int, string> progressTracker) { object obj = _argumentProvider.GetArg("ucAnlysisTool"); UCAnlysisTool ucAnlysisTool = null; if (obj != null) { ucAnlysisTool = obj as UCAnlysisTool; } else { return(null); } IRasterDataProvider sourceraster = _argumentProvider.DataProvider as IRasterDataProvider; RasterIdentify rid = new RasterIdentify(_argumentProvider.DataProvider.fileName); rid.ProductIdentify = _subProductDef.ProductDef.Identify; rid.SubProductIdentify = _subProductDef.Identify; string tempFile = rid.ToWksFullFileName(".dat"); string outFileName = Path.Combine(Path.GetDirectoryName(tempFile), Path.GetFileNameWithoutExtension(tempFile) + GetExtInfo(ucAnlysisTool.cmbType.Text) + ".ldf"); IExtractResultArray array = new ExtractResultArray("BAG"); bool onlyTxt = bool.Parse(_argumentProvider.GetArg("OnlyTxt").ToString()); if (!onlyTxt) { int totalLength = 0; //原始影像raster List <RasterMaper> listRaster = new List <RasterMaper>(); RasterMaper rmsoure = new RasterMaper(sourceraster, GetBandArray(sourceraster.BandCount)); int totalbandcount = sourceraster.BandCount; listRaster.Add(rmsoure); try { using (IRasterDataProvider outRaster = CreateOutM_BandRaster(outFileName, listRaster.ToArray(), totalbandcount)) { //波段总数 RasterMaper[] fileIns = listRaster.ToArray(); RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, GetBandArray(totalbandcount)) }; //创建处理模型 RasterProcessModel <UInt16, UInt16> rfr = null; rfr = new RasterProcessModel <UInt16, UInt16>(progressTracker); rfr.SetRaster(fileIns, fileOuts); rfr.SetFeatureAOI(_argumentProvider.AOIs); rfr.RegisterCalcModel(new RasterCalcHandler <UInt16, UInt16>((rvInVistor, rvOutVistor, aoi) => { int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX; if (rvInVistor[0].RasterBandsData == null || rvInVistor[0].RasterBandsData[0] == null) { totalLength += dataLength; return; } for (int index = 0; index < dataLength; index++) { if (_argumentProvider.AOI.Contains(totalLength + index)) { for (int i = 0; i < totalbandcount; i++) { rvOutVistor[0].RasterBandsData[i][index] = rvInVistor[0].RasterBandsData[i][index]; } } } totalLength += dataLength; } )); //执行 rfr.Excute(0); } string dstfilename = outFileName.Replace(".ldf", ".dat"); if (File.Exists(dstfilename)) { File.Delete(dstfilename); } File.Move(outFileName, dstfilename); FileExtractResult res = new FileExtractResult("BAG", dstfilename, true); res.SetDispaly(false); array.Add(res); } finally { } } if (!string.IsNullOrEmpty(ucAnlysisTool.txtInfos.Text)) { string txtFile = outFileName.Replace(".ldf", ".txt"); File.WriteAllLines(txtFile, ucAnlysisTool.WriteText, Encoding.Unicode); FileExtractResult resTxt = new FileExtractResult("BAG", txtFile, true); resTxt.SetDispaly(false); array.Add(resTxt); } return(array); }
private IExtractResult ComputeByCurrentRaster(IRasterDataProvider currPrd, Action <int, string> progressTracker) { float curNDVI = 0f; 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); } string normalizationFile = string.Empty; AngleParModel angleArg = _argumentProvider.GetArg("Angle") as AngleParModel; if (angleArg != null && angleArg.ApplyN) { if (string.IsNullOrEmpty(angleArg.FileAsatA) || !File.Exists(angleArg.FileAsatA) || string.IsNullOrEmpty(angleArg.FileAsatZ) || !File.Exists(angleArg.FileAsatZ) || string.IsNullOrEmpty(angleArg.FileAsunA) || !File.Exists(angleArg.FileAsunA) || string.IsNullOrEmpty(angleArg.FileAsunZ) || !File.Exists(angleArg.FileAsunZ) || string.IsNullOrEmpty(angleArg.FileLandConvery) || !File.Exists(angleArg.FileLandConvery)) { PrintInfo("归一化处理所需的角度信息、土地覆盖信息填写不正确或不存在,请检查..."); return(null); } normalizationFile = NormalizationProcess(currPrd, progressTracker); if (string.IsNullOrEmpty(normalizationFile) || !File.Exists(normalizationFile)) { PrintInfo("归一化处理失败"); return(null); } } bool normalizationSuccess = angleArg != null && angleArg.ApplyN && !string.IsNullOrEmpty(normalizationFile) && File.Exists(normalizationFile) ? true : false; 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()); Int16 defCloudy = (Int16)_argumentProvider.GetArg("defCloudy"); Int16 defWater = (Int16)_argumentProvider.GetArg("defWater"); Int16 InvaildValue = (Int16)_argumentProvider.GetArg("InvaildValue"); int cloudCH = (int)_argumentProvider.GetArg("CLMBand"); string clmFile = GetClmFile(currPrd); bool isSetMinMax = (bool)_argumentProvider.GetArg("isSetMinMax"); float ndviMax = (float)_argumentProvider.GetArg("NDVIMax"); float ndviMin = (float)_argumentProvider.GetArg("NDVIMin"); float ndviCalcMax = float.MinValue; float ndviCalcMin = float.MaxValue; float PNVIZoom = (float)_argumentProvider.GetArg("PNVIZoom"); //输入文件准备 List <RasterMaper> rms = new List <RasterMaper>(); IRasterDataProvider currRaster = null; IRasterDataProvider clmPrd = null; IRasterDataProvider ndviPrd = null; IFileExtractResult pviFile = null; IExtractResultArray array = new ExtractResultArray("DRT"); if (progressTracker != null) { progressTracker.Invoke(normalizationSuccess ? 77 : 0, "计算改进型垂直干旱指数"); } try { currRaster = normalizationSuccess ? GeoDataDriver.Open(normalizationFile) as IRasterDataProvider : currPrd; if (!normalizationSuccess && (currRaster.BandCount < VisibleCH || currRaster.BandCount < NearInfraredCH || (isAutoCloud && currRaster.BandCount < FarInfrared11CH))) { PrintInfo("请选择正确的数据进行垂直干旱指数计算。"); return(null); } RasterMaper rmCurr = normalizationSuccess ? new RasterMaper(currRaster, new int[] { 1, 2, 3 }) : new RasterMaper(currRaster, new int[] { VisibleCH, NearInfraredCH, FarInfrared11CH }); rms.Add(rmCurr); 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; } bool isContainNDVI = false; string ndviFile = string.Empty; string[] ndviFiles = GetStringArray("SelectedPrimaryFiles"); if (ndviFiles == null || ndviFiles.Length == 0 || string.IsNullOrEmpty(ndviFiles[0]) || !File.Exists(ndviFiles[0])) { isContainNDVI = false; } else { isContainNDVI = true; ndviFile = ndviFiles[0]; } int ndviCH = (int)_argumentProvider.GetArg("NDVIBand"); double ndviZoom = (double)_argumentProvider.GetArg("NDVIBand_Zoom"); if (isContainNDVI && !string.IsNullOrEmpty(ndviFile)) { ndviPrd = GeoDataDriver.Open(ndviFile) as IRasterDataProvider; if (ndviPrd.BandCount < ndviCH) { PrintInfo("请选择正确的植被指数数据通道进行计算。"); return(null); } RasterMaper ndviRm = new RasterMaper(ndviPrd, new int[] { ndviCH }); rms.Add(ndviRm); isContainNDVI = true; } //输出文件准备(作为输入栅格并集处理) string outFileName = GetFileName(new string[] { currRaster.fileName }, _subProductDef.ProductDef.Identify, "PNVI", ".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.RegisterCalcModel(new RasterCalcHandler <Int16, Int16>((rvInVistor, rvOutVistor, aoi) => { int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX; for (int index = 0; index < dataLength; index++) { Int16 visiableValue = rvInVistor[0].RasterBandsData[0][index]; Int16 nearInfraredValue = rvInVistor[0].RasterBandsData[1][index]; Int16 farInfraredVale = rvInVistor[0].RasterBandsData[2][index]; curNDVI = isContainNDVI ? (float)(rvInVistor[2 - (isContainClm ? 0 : 1)].RasterBandsData[0][index] / ndviZoom) : GetNDVI(nearInfraredValue, visiableValue); if (visiableValue == 0 && nearInfraredValue == 0) { rvOutVistor[0].RasterBandsData[0][index] = InvaildValue; } else if (isContainClm && rvInVistor[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 { rvOutVistor[0].RasterBandsData[0][index] = (Int16)(curNDVI * PNVIZoom); if (curNDVI > ndviCalcMax) { ndviCalcMax = curNDVI; } else if (curNDVI < ndviCalcMin) { ndviCalcMin = curNDVI; } } } } })); //执行 rfr.Excute(); pviFile = new FileExtractResult(_subProductDef.Identify, outFileName, true); pviFile.SetDispaly(false); if (normalizationSuccess) { FileExtractResult nrsb = new FileExtractResult(_subProductDef.Identify, normalizationFile, true); nrsb.SetDispaly(false); array.Add(nrsb); } _argumentProvider.SetArg("CursorInfo:Image-NDVIMax", ndviCalcMax); _argumentProvider.SetArg("CursorInfo:Image-NDVIMin", ndviCalcMin); array.Add(pviFile); } } finally { if (clmPrd != null) { clmPrd.Dispose(); } if (ndviPrd != null) { ndviPrd.Dispose(); } } FileExtractResult mpdiFile = null; if (File.Exists(pviFile.FileName)) { mpdiFile = CalcMPDI(pviFile.FileName, ndviCalcMin, ndviCalcMax, currRaster, normalizationSuccess, progressTracker); if (mpdiFile != null) { array.Add(mpdiFile); } } return(array); }
private IExtractResult TSTATAlgorithmStat(string outId, SubProductInstanceDef instance, Dictionary <string, Func <short, bool> > filters, Action <int, string> progressTracker) { string[] files = GetStringArray("SelectedPrimaryFiles"); IStatResult temp = null; List <string> colums = new List <string>(); List <string[]> rowTemp = new List <string[]>(); IStatResult dstResult = null; RasterIdentify rid = null; string dateStr = _argumentProvider.GetArg("tostringtype").ToString(); int fileIndex = 0; float step = 90f / files.Length; try { if (outId == "CCAR") { foreach (string file in files) { if (progressTracker != null) { progressTracker.Invoke((int)Math.Ceiling(fileIndex * step), "正在统计第[" + fileIndex + "]个文件,请稍后..."); } temp = StatRasterToStatResult <short>(instance, new string[] { file }, filters, progressTracker); rid = new RasterIdentify(file); foreach (string[] cols in temp.Rows) { cols[0] = rid.OrbitDateTime.ToString(dateStr); rowTemp.Add(cols); } if (colums.Count == 0) { colums.AddRange(temp.Columns); } } rowTemp.Sort((before, last) => before.First().CompareTo(last.First())); dstResult = new StatResult(null, colums.ToArray(), rowTemp.ToArray()); if (progressTracker != null) { progressTracker.Invoke(95, "正在写入统计信息,请稍后..."); } return(new FileExtractResult("LST", StatResultToFile(files, dstResult, "LST", "T" + outId.Substring(0, 3), "", "", 1, false))); } if (instance.AOIProvider == "省级行政区划" || instance.AOIProvider == "土地利用类型") { string statVector = instance.AOIProvider == "省级行政区划" ? "行政区划" : "土地利用类型"; string title; string[] colDescs; IStatResult[] tempArray = null; IStatResult[] dstResultArray = null; List <string> tempList = null; foreach (string file in files) { fileIndex++; if (progressTracker != null) { progressTracker.Invoke((int)Math.Ceiling(fileIndex * step), "正在统计第[" + fileIndex + "]个文件,请稍后..."); } tempArray = StatProcentRasterToStatResult(file, statVector, filters, null, out title, out colDescs, true); if (dstResultArray == null) { dstResultArray = new IStatResult[tempArray.Length]; } rid = new RasterIdentify(file); for (int i = 0; i < dstResultArray.Length; i++) { try { foreach (string[] cols in tempArray[i].Rows) { tempList = new List <string>(); tempList.AddRange(cols); tempList.Insert(1, rid.OrbitDateTime.ToString(dateStr)); rowTemp.Add(tempList.ToArray()); } if (colums.Count == 0) { tempList = new List <string>(); tempList.AddRange(tempArray[i].Columns); tempList.Insert(1, "日期"); colums.AddRange(tempList.ToArray()); } if (dstResultArray[i] == null) { dstResultArray[i] = new StatResult(null, colums.ToArray(), rowTemp.ToArray()); } else { List <string[]> tempRowsFromArray = new List <string[]>(); tempRowsFromArray.AddRange(dstResultArray[i].Rows); tempRowsFromArray.AddRange(rowTemp.ToArray()); StringArrayComparer comparer = new StringArrayComparer(true); tempRowsFromArray.Sort(comparer); dstResultArray[i] = new StatResult(null, colums.ToArray(), tempRowsFromArray.ToArray()); } } finally { colums.Clear(); rowTemp.Clear(); } } } if (progressTracker != null) { progressTracker.Invoke(95, "正在写入统计信息,请稍后..."); } string outFileIdentify = GetStringArgument("OutFileIdentify"); string[] outFileIdentifys = new string[] { "T" + outFileIdentify.Substring(0, 3), "T" + outFileIdentify.Substring(0, 2) + "P" }; IExtractResultArray array = new ExtractResultArray("LST"); for (int i = 0; i < dstResultArray.Length; i++) { List <RowDisplayDef> rowRulers = new List <RowDisplayDef>(); List <int> displayRowNum = new List <int>(); int count = -1; string befStr = dstResultArray[i].Rows[0].First(); for (int row = 0; row < dstResultArray[i].Rows.Length; row++) { count++; if (dstResultArray[i].Rows[row].First() == befStr) { displayRowNum.Add(count + 3); continue; } AddRowRuler(ref rowRulers, displayRowNum, dstResultArray[i].Rows[row - 1][0], true, false, false); displayRowNum.Clear(); befStr = dstResultArray[i].Rows[row].First(); displayRowNum.Add(count + 3); } AddRowRuler(ref rowRulers, displayRowNum, befStr, true, false, false); array.Add(new FileExtractResult("LST", StatResultToFile(files, dstResultArray[i], "LST", outFileIdentifys[i], "", "", 1, rowRulers, 3, (dstResultArray[i].Columns.Length - 2)))); } return(array); } } finally { if (progressTracker != null) { progressTracker.Invoke(100, "完成统计分析!"); } } PrintInfo("指定的算法\"" + instance.Name + "\"没有实现。"); return(null); }
private IExtractResult HistoryDataLayoutAlgorithm(Action <int, string> progressTracker) { //1.获取到数据 List <string> list = ExportManager.GetInstance().List; //这个针对查询出来的数据出专题图 string[] inputfiles = list.ToArray(); //再加一上基于 同期统计数据的专题图,如果是冬季的,还要再计算一次 StatisticResultManager manager = StatisticResultManager.GetInstance(); List <string> list2 = manager.GetFilePathFromList(); //得到的是基于数据查询的数据又做的统计数据 if (list2.Count != 0) { inputfiles = list2.ToArray(); period = "yes"; Match m = DataReg2.Match(inputfiles[0]); if (m.Success) { Iswinter = "yes"; } } //处理后的数据存储路径 string savePath = _argumentProvider.GetArg("HistoryDataSave") as string; regioNames = _argumentProvider.GetArg("regionNames") as string; string orbitType = _argumentProvider.GetArg("OrbitType") as string; string Str = null; if (orbitType == "Ascend") { Str = "_A_"; } if (orbitType == "Descend") { Str = "_D_"; } //同期统计计算传出来的文件没有分升降轨,这里进行区分 List <string> fnamelist = new List <string>(); foreach (string file in inputfiles) { if (Path.GetFileName(file).Contains(Str)) { fnamelist.Add(file); } } inputfiles = fnamelist.ToArray(); //处理后的数据,用它来出专题图 List <string> afterProcessfiles = new List <string>(); //(插一步,通过这个原始选择的文件名时间信息把专题图名称确定) //2.确定选择区域,没有选或者中国区域不要用裁,如果是其地区首先裁切,并且放到指定文件夹下 aoiContainer = new GeoDo.RSS.Core.VectorDrawing.AOIContainerLayer(); MulRegionsClip muticlip = new MulRegionsClip(); //裁切 MWSSmoothHelp smooth = new MWSSmoothHelp(); //平滑 string regionsname = ""; #region 获得目标区域 aoiContainer = new GeoDo.RSS.Core.VectorDrawing.AOIContainerLayer(); string fieldName; string shapeFilename; int fieldIndex = -1; List <string> fieldValues = new List <string>(); using (frmStatSubRegionTemplates frm = new frmStatSubRegionTemplates()) { frm.listView1.MultiSelect = true; if (frm.ShowDialog() == DialogResult.OK) { Feature[] fets = frm.GetSelectedFeatures(); fets = frm.GetStatFeatures(out fieldName, out shapeFilename, out fieldIndex); if (fets == null) { aoiContainer = null; regionsname = "全国"; } else { string chinafieldValue = fets[0].GetFieldValue(fieldIndex); if (chinafieldValue == "中国") { aoiContainer = null; regionsname = "全国"; } else { foreach (Feature fet in fets) { fieldValues.Add(fet.GetFieldValue(fieldIndex)); //获得选择区域名称 aoiContainer.AddAOI(fet); } foreach (string region in fieldValues) { regionsname += region; } if (regionsname.Contains("西藏") && regionsname.Contains("青海")) { regionsname = "青藏地区"; } if (!string.IsNullOrEmpty(regioNames)) { regionsname = regioNames.Trim(); } } } } else //没有点击确定,返回空 { return(null); } } #endregion if (aoiContainer == null) { //不用裁切,只做中值滤波的平滑处理。 regionsname = "全国"; foreach (string infile in inputfiles) { //创建专题图路径 gxdsave = savePath + "\\" + regionsname + "\\" + "专题图"; if (!System.IO.Directory.Exists(gxdsave))//如果不存在这个路径 { System.IO.Directory.CreateDirectory(gxdsave); } //创建平滑路径 string smoothsave = savePath + "\\" + regionsname + "\\" + "平滑"; if (!System.IO.Directory.Exists(smoothsave)) { System.IO.Directory.CreateDirectory(smoothsave); } //创建平滑\\中值 string filtersave = smoothsave + "\\" + "中值"; if (!System.IO.Directory.Exists(filtersave)) { System.IO.Directory.CreateDirectory(filtersave); } string filterfile = smooth.ComputerMid(infile, 5, filtersave); string hdrfile = Path.GetDirectoryName(filterfile) + "\\" + Path.GetFileNameWithoutExtension(filterfile) + ".hdr"; afterProcessfiles.Add(filterfile); } } else { //创建裁切路径 string clipsave = savePath + "\\" + regionsname + "\\" + "裁切"; if (!System.IO.Directory.Exists(clipsave))//如果不存在这个路径 { System.IO.Directory.CreateDirectory(clipsave); } //创建专题图路径 gxdsave = savePath + "\\" + regionsname + "\\" + "专题图"; if (!System.IO.Directory.Exists(gxdsave))//如果不存在这个路径 { System.IO.Directory.CreateDirectory(gxdsave); } //创建平滑路径 string smoothsave = savePath + "\\" + regionsname + "\\" + "平滑"; if (!System.IO.Directory.Exists(smoothsave)) { System.IO.Directory.CreateDirectory(smoothsave); } //创建平滑\\中值 string filtersave = smoothsave + "\\" + "中值"; if (!System.IO.Directory.Exists(filtersave)) { System.IO.Directory.CreateDirectory(filtersave); } //创建平滑\\插值 string bilisave = smoothsave + "\\" + "插值"; if (!System.IO.Directory.Exists(bilisave)) { System.IO.Directory.CreateDirectory(bilisave); } foreach (string infile in inputfiles) { //加一个条件判断要处理的数据是否已经存在,如果存就不用再做 string newclipfile = Path.Combine(clipsave, Path.GetFileName(infile).Replace("China", regionsname)); if (!File.Exists(newclipfile)) { string clipfile = muticlip.MutiRegionsClip(infile, aoiContainer, clipsave); string hdrfile = Path.GetDirectoryName(clipfile) + "\\" + Path.GetFileNameWithoutExtension(clipfile) + ".hdr"; //重命名 string newhdrfile = Path.Combine(Path.GetDirectoryName(clipfile), Path.GetFileNameWithoutExtension(infile).Replace("China", regionsname) + ".hdr"); FileInfo fi = new FileInfo(clipfile); fi.MoveTo(newclipfile); FileInfo fihdr = new FileInfo(hdrfile); fihdr.MoveTo(newhdrfile); } //裁切后要对数据中值、插值 string filterfile = smooth.ComputerMid(newclipfile, 5, filtersave); string bilifile = smooth.Bilinear(filterfile, 10, bilisave); afterProcessfiles.Add(bilifile); } } //把处理后的afterProcessfiles.ToArray()数组文件名标识变为“HFSD”或“HFWE”。 foreach (string file in afterProcessfiles.ToArray()) { string hdrfile = Path.GetDirectoryName(file) + "\\" + Path.GetFileNameWithoutExtension(file) + ".hdr"; string newfile = ""; string newhdr = ""; if (file.Contains("MWSD")) { newfile = file.Replace("MWSD", "HFSD"); newhdr = hdrfile.Replace("MWSD", "HFSD"); } if (file.Contains("MSWE")) { newfile = file.Replace("MSWE", "HFWE"); newhdr = hdrfile.Replace("MSWE", "HFWE"); } FileInfo fi = new FileInfo(file); if (!File.Exists(newfile)) { fi.MoveTo(newfile); } FileInfo fihdr = new FileInfo(hdrfile); if (!File.Exists(newhdr)) { fihdr.MoveTo(newhdr); } imgfiles.Add(newfile); } IExtractResultArray results = new ExtractResultArray(""); foreach (string arguments in imgfiles.ToArray()) { string product = ""; if (arguments.Contains("HFSD")) { _argumentProvider.SetArg("OutFileIdentify", "HSDI"); product = "雪深"; } if (arguments.Contains("HFWE")) { _argumentProvider.SetArg("OutFileIdentify", "HSWI"); product = "雪水当量"; } //解析文件名确定专题图名称 string filename = Path.GetFileNameWithoutExtension(arguments); if (period == "yes") //同期统计的 { if (Iswinter == "yes") { Match m = DataReg2.Match(filename); string year = ""; if (m.Success) { year = m.Value; } imgname = year.Substring(0, 4) + "年" + "冬季" + regionsname + product + "分布图"; } else { Regex DataReg1 = new Regex(@"(?<year>\d{4})_(?<year>\d{4})", RegexOptions.Compiled); Match m = DataReg1.Match(filename); string year = ""; if (m.Success) { year = m.Value; } //提取年至avg之间的字符 string filetime = filename.Substring(filename.IndexOf(year), filename.Length - 3 - filename.IndexOf(year)); string[] mxchars = filetime.Split(new char[] { '_' }); string mx = "";//月+旬 if (filename.Contains("Xun")) { if (mxchars[3] == "1") { mx = mxchars[2] + "月" + "上旬"; } if (mxchars[3] == "2") { mx = mxchars[2] + "月" + "中旬"; } if (mxchars[3] == "3") { mx = mxchars[2] + "月" + "下旬"; } } if (filename.Contains("Month")) { mx = mxchars[2] + "月"; } imgname = year + "年" + mx + regionsname + product + "分布图"; } } else { Regex DataReg = new Regex(@"(?<year>\d{4})", RegexOptions.Compiled); Match m = DataReg.Match(filename); string year = ""; if (m.Success) { year = m.Value; } //提取年至avg之间的字符 string filetime = filename.Substring(filename.IndexOf(year), filename.Length - 3 - filename.IndexOf(year)); string[] mxchars = filetime.Split(new char[] { '_' }); string mx = "";//月+旬 if (filename.Contains("Xun")) { if (mxchars[2] == "1") { mx = mxchars[1] + "月" + "上旬"; } if (mxchars[2] == "2") { mx = mxchars[1] + "月" + "中旬"; } if (mxchars[2] == "3") { mx = mxchars[1] + "月" + "下旬"; } } if (filename.Contains("Month")) { mx = mxchars[1] + "月"; } if (filetime.Contains("Season")) { mx = mxchars[1] + "季度"; } imgname = year + "年" + mx + regionsname + product + "分布图"; } _argumentProvider.SetArg("SelectedPrimaryFiles", arguments); _argumentProvider.SetArg("fileOpenArgs", arguments); FileExtractResult result = ThemeGraphyResult(null) as FileExtractResult; //增加矢量 string autopath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"SystemData\ProductArgs\MWS\shppath.txt"); string shpFile = ""; if (File.Exists(autopath)) { FileStream fauto = new FileStream(autopath, FileMode.Open, FileAccess.Read); StreamReader rauto = new StreamReader(fauto, Encoding.GetEncoding("gb2312")); shpFile = rauto.ReadLine(); rauto.Close(); fauto.Close(); } else { shpFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"数据引用\基础矢量\行政区划\线\中国边界_线.shp"); } CreateMcd(shpFile); _shpFile = shpFile; _gxdFile = (result as FileExtractResult).FileName; AddShpToGxd(); FileInfo fi = new FileInfo(result.FileName); string newresultfile = Path.Combine(gxdsave, Path.GetFileNameWithoutExtension(arguments) + ".gxd"); if (!File.Exists(newresultfile)) { fi.MoveTo(newresultfile); } else { FileInfo fi1 = new FileInfo(newresultfile); fi1.Delete(); } IFileExtractResult res = new FileExtractResult(_subProductDef.Identify, newresultfile, false); results.Add(res); } return(results); }
private IExtractResult FRAREAlgorithm(Action <int, string> progressTracker) { AngleParModel model = _argumentProvider.GetArg("anglesettings") as AngleParModel; double glintmax = double.Parse(_argumentProvider.GetArg("glint").ToString()); //band int angleband = (int)_argumentProvider.GetArg("angle"); //zoom float anglezoom = float.Parse(_argumentProvider.GetArg("angle_Zoom").ToString()); string rasterfile = _argumentProvider.DataProvider.fileName; IRasterDataProvider outRaster = null; List <RasterMaper> rms = new List <RasterMaper>(); try { IRasterDataProvider sunzinRaster = RasterDataDriver.Open(model.FileAsunZ) as IRasterDataProvider; RasterMaper brmsunz = new RasterMaper(sunzinRaster, new int[] { angleband }); rms.Add(brmsunz); IRasterDataProvider sunainRaster = RasterDataDriver.Open(model.FileAsunA) as IRasterDataProvider; RasterMaper brmsuna = new RasterMaper(sunainRaster, new int[] { angleband }); rms.Add(brmsuna); IRasterDataProvider satzinRaster = RasterDataDriver.Open(model.FileAsatZ) as IRasterDataProvider; RasterMaper brmsatz = new RasterMaper(satzinRaster, new int[] { angleband }); rms.Add(brmsatz); IRasterDataProvider satainRaster = RasterDataDriver.Open(model.FileAsatA) as IRasterDataProvider; RasterMaper brmsata = new RasterMaper(satainRaster, new int[] { angleband }); rms.Add(brmsata); RasterIdentify ri = GetRasterIdentifyID(rasterfile); ri.SubProductIdentify = "FRAM"; string outFileName = ri.ToWksFullFileName(".dat"); IPixelIndexMapper result = null; IPixelFeatureMapper <Int16> resultTag = null; int totalDatalength = 0; Dictionary <int, FireAngleFeature> listfeature = new Dictionary <int, FireAngleFeature>(); outRaster = CreateOutRaster(outFileName, rms.ToArray()); result = PixelIndexMapperFactory.CreatePixelIndexMapper("FIR", outRaster.Width, outRaster.Height, outRaster.CoordEnvelope, outRaster.SpatialRef); //栅格数据映射 RasterMaper[] fileIns = rms.ToArray(); RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) }; //创建处理模型 RasterProcessModel <Int16, UInt16> rfr = null; rfr = new RasterProcessModel <Int16, UInt16>(progressTracker); rfr.SetRaster(fileIns, fileOuts); rfr.RegisterCalcModel(new RasterCalcHandler <Int16, UInt16>((rvInVistor, rvOutVistor, aoi) => { int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX; for (int index = 0; index < dataLength; index++) { double asunz = rvInVistor[0].RasterBandsData[0][index] / anglezoom; double asuna = rvInVistor[1].RasterBandsData[0][index] / anglezoom; double asatz = rvInVistor[2].RasterBandsData[0][index] / anglezoom; double asata = rvInVistor[3].RasterBandsData[0][index] / anglezoom; double glintangle = Math.Acos(Math.Sin(asunz) * Math.Sin(asatz) * Math.Cos(asuna - asata) + Math.Cos(asunz) * Math.Cos(asatz)); if (glintangle != 0) { if (glintangle * 180 / Math.PI < glintmax) { result.Put(totalDatalength + index); } //增加像元信息显示 FireAngleFeature feature = new FireAngleFeature(); feature.SunZ = asunz; feature.SunA = asuna; feature.SatZ = asatz; feature.SatA = asata; feature.Glint = Math.Round(glintangle * 180 / Math.PI, 2); listfeature.Add(totalDatalength + index, feature); } rvOutVistor[0].RasterBandsData[0][index] = Convert.ToUInt16(glintangle * 180 * anglezoom / Math.PI); } totalDatalength += dataLength; })); //执行 rfr.Excute(); result.Tag = new FireAngleCollection("耀斑角信息", listfeature); IExtractResultArray array = new ExtractResultArray("FIR"); array.Add(result); FileExtractResult angleresult = new FileExtractResult(ri.SubProductIdentify, outFileName); angleresult.SetDispaly(false); array.Add(angleresult); return(array); } finally { foreach (RasterMaper rm in rms) { rm.Raster.Dispose(); } if (outRaster != null) { outRaster.Dispose(); } } }