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); } RasterIdentify rid = new RasterIdentify(_argumentProvider.DataProvider.fileName); rid.ProductIdentify = _subProductDef.ProductDef.Identify; rid.SubProductIdentify = _subProductDef.Identify; string dstfilename = rid.ToWksFullFileName(".txt"); if (File.Exists(dstfilename)) { File.Delete(dstfilename); } if (!string.IsNullOrEmpty(ucAnlysisTool.txtInfos.Text)) { File.WriteAllLines(dstfilename, new string[] { ucAnlysisTool.txtInfos.Text }, Encoding.Unicode); FileExtractResult resTxt = new FileExtractResult("LST", dstfilename, true); resTxt.SetDispaly(false); return(resTxt); } return(null); }
private IExtractResult StateUHPI(int NormalLevel, string[] files, Dictionary <string, StatInfo> result) { float sum = 0; List <string[]> valueItems = new List <string[]>(); string DateStr = GetStringArgument("DateStr"); foreach (string key in result.Keys) { foreach (UInt16 level in result[key].UHPI.Keys) { sum += level * ((float)result[key].UHPI[level] / result[key].totalCount); } valueItems.Add(new string[] { DataIdentifyMatcher.GetOrbitDateTime(key).AddHours(8).ToString(DateStr), Math.Round((1f / NormalLevel) * sum, 2).ToString() }); sum = 0; } string title = "统计日期:" + DateTime.Now.ToShortDateString(); string[] columns = new string[] { "日期", "比例指数" }; IStatResult statResult = new StatResult(title, columns, valueItems.ToArray()); string filename = StatResultToFile(files, statResult, "UHE", "UHPI", "比例指数", string.Empty, 1, false); FileExtractResult fileResult = new FileExtractResult("UHPI", filename); fileResult.Add2Workspace = true; fileResult.SetDispaly(false); return(fileResult); }
public void ExportInvocation(string dtmi, string expectedDeps, TestHelpers.ClientType clientType) { string targetRepo = string.Empty; if (clientType == TestHelpers.ClientType.Local) { targetRepo = $"--repo \"{TestHelpers.TestLocalModelRepository}\""; } (int returnCode, string standardOut, string standardError) = ClientInvokator.Invoke($"export --dtmi \"{dtmi}\" {targetRepo}"); Assert.AreEqual(Handlers.ReturnCodes.Success, returnCode); Assert.False(standardError.Contains(Outputs.DefaultErrorToken)); FileExtractResult extractResult = ParsingUtils.ExtractModels(standardOut); List <string> modelsResult = extractResult.Models; string[] expectedDtmis = $"{dtmi},{expectedDeps}".Split(",", StringSplitOptions.RemoveEmptyEntries); Assert.True(modelsResult.Count == expectedDtmis.Length); foreach (string model in modelsResult) { string targetId = ParsingUtils.GetRootId(model); Assert.True(expectedDtmis.Contains(targetId)); } }
/// <summary> /// 监测示意图 /// </summary> /// <param name="session"></param> /// <param name="argument">"template:沙尘监测示意图,监测示意图,DST,MCSI"</param> public static void DisplayMonitorShow(ISmartSession session, string argument) { string subIdentify = null; try { //MonitorShowSettings setting = GetMonitorShowSettings(); //if (setting == null) // return ; //MonitorShowSettings.CurrentSettings = setting; MonitorShowDisplay msd = new MonitorShowDisplay(); string fname = msd.DisplayMonitorBitmap(session, argument, out subIdentify); if (string.IsNullOrEmpty(fname)) { return; } IExtractResult er = new FileExtractResult(subIdentify, fname) as IExtractResult; if (er == null) { return; } DisplayResultClass.DisplayResult(session, null, er, false); } finally { //if (MonitorShowSettings.CurrentSettings != null) // MonitorShowSettings.CurrentSettings = null; } }
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); }
/// <summary> /// 生成动画 /// </summary> /// <param name="session"></param> /// <param name="argument">template:沙尘动画示意专题图,动画示意专题图,productIdentify, subProductIdentify</param> public static void CreatAVI(ISmartSession session, string argument) { string[] fnames = GetFilesByWorkspace(session); if (fnames == null || fnames.Length == 0) { return; } string tempArg = null; string wndName = null; string productIdentify = null; string subIdentify = null; ParserArgument(argument, ref tempArg, ref wndName, ref productIdentify, ref subIdentify); IAVILayerDisplay aviDis = new AVILayerDisplay(); if (subIdentify == "CMED") { aviDis.IsCustom = true; } string outputFname = null; aviDis.DisplayAvi(session, wndName, fnames, tempArg, subIdentify, out outputFname); IExtractResult er = new FileExtractResult(subIdentify, outputFname) as IExtractResult; if (er == null) { return; } DisplayResultClass.DisplayResult(session, null, er, false); }
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); }
private void ActiveWorkSpace(string filename) { if (_mSession != null && _mSession.ActiveMonitoringSubProduct != null) { FileExtractResult result = new FileExtractResult(_subProductIdentify, filename, true); DisplayResultClass.DisplayResult(_session, _mSession.ActiveMonitoringSubProduct, result, false); } }
public IFileExtractResult ClipSNWResult(string filename, string area) { inputFileName = filename; using (IRasterDataProvider raster = GeoDataDriver.Open(filename) as IRasterDataProvider) { _resolutionX = raster.ResolutionX; _resolutionY = raster.ResolutionY; _fileSize = new Size(raster.Width, raster.Height); _fileEnvelope = raster.CoordEnvelope; _activeSpatialRef = raster.SpatialRef; _activeCoordType = raster.CoordType; raster.Dispose(); } _outsizeRegion = new CoordEnvelope(_fileEnvelope.MinX, _fileEnvelope.MaxX, _fileEnvelope.MinY, _fileEnvelope.MaxY); OutDir = Path.GetDirectoryName(filename); string hdrfile = Path.Combine(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename) + ".hdr"); List <Feature> fets = new List <Feature>(); IVectorFeatureDataReader dr = null; if (area == "中国区") { url = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "数据引用\\基础矢量\\行政区划\\面\\中国边界.shp"); } else { url = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "数据引用\\基础矢量\\行政区划\\面\\省级行政区域_面.shp"); } dr = VectorDataReaderFactory.GetUniversalDataReader(url) as IVectorFeatureDataReader; Feature[] temp = null; temp = dr.FetchFeatures(); fets.AddRange(temp); Feature[] features = null; features = fets.ToArray(); _blockName = area; int index = GetFeatureIndx(area); _vectorFeature = features[index];//_selectFeature //string fieldValue = _vectorFeature.GetFieldValue(fieldIndex); evp = GetMaskEnvelope(_vectorFeature.Geometry as ShapePolygon); BlockDefWithAOI outEnvelope; Size size; List <BlockDefWithAOI> blockList = new List <BlockDefWithAOI>(); GetArgs(out outEnvelope, out size, out OutDir, out filename); envelopes = new BlockDefWithAOI[] { outEnvelope }; aoiIndex = GetFeatureAOIIndex(); blockList.AddRange(envelopes); blockList[0].AOIIndexes = aoiIndex; string[] put = RasterClipT(inputFileName, blockList.ToArray(), OutDir, "Cut"); //put[0] = OutDir + put[0]; string getpath = Path.GetDirectoryName(put[0]); IFileExtractResult res = new FileExtractResult("MWS", put[0], true); res.SetDispaly(false); return(res); }
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 { } }
public override IExtractResult Make(Action <int, string> progressTracker, IContextMessage contextMessage) { _contextMessage = contextMessage; if (_argumentProvider == null) { return(null); } if (_argumentProvider.GetArg("AlgorithmName") == null) { return(null); } if (_argumentProvider.GetArg("AlgorithmName").ToString() == "FLDC") { if (_argumentProvider.GetArg("SelectedPrimaryFiles") == null) { return(null); } string[] binWater = _argumentProvider.GetArg("SelectedPrimaryFiles") as string[]; if (_argumentProvider.GetArg("BackWaterFile") == null) { return(null); } string backWaterPath = _argumentProvider.GetArg("BackWaterFile").ToString(); if (!File.Exists(backWaterPath)) { return(null); } for (int i = 0; i < binWater.Length; i++) { if (!File.Exists(binWater[i])) { return(null); } } if (string.IsNullOrEmpty(backWaterPath) || string.Equals(binWater, backWaterPath)) { return(null); } //生成判识结果数据统计数据集 FileExtractResult dblvCount = GreateDBLVCount(binWater, progressTracker); //背景水体可能为DAT/MVG/SHP格式文件 switch (Path.GetExtension(backWaterPath).ToUpper()) { case ".DAT": return(CompareDATFile(backWaterPath, dblvCount, progressTracker)); case ".SHP": return(CompareSHPFile(backWaterPath, dblvCount, progressTracker)); case ".MVG": return(null); } } return(null); }
public override IExtractResult Make(Action <int, string> progressTracker) { if (_argumentProvider == null) { return(null); } string outFileIdentify = GetStringArgument("OutFileIdentify"); string algname = _argumentProvider.GetArg("AlgorithmName").ToString(); string[] statFileNames = GetStringArray("SelectedPrimaryFiles"); string extinfo = GetStringArgument("extinfo"); if (string.IsNullOrEmpty(algname) || statFileNames == null || statFileNames.Count() == 0) { return(null); } foreach (string fileName in statFileNames) { if (!File.Exists(fileName)) { return(null); } } if (algname == "0SDC") { RasterIdentify rid = new RasterIdentify(statFileNames[0]); if (rid != null) { _dayCount = GetDayCount(rid.OrbitDateTime.Month, rid.OrbitDateTime.Year); } else { _dayCount = 30; } string degreeFileName = GetSNWDegree(statFileNames); object aioObj = _argumentProvider.GetArg("AOI"); string title = null; StatResultItem[] result = DegreeStat(degreeFileName, aioObj, ref title); if (File.Exists(degreeFileName)) { File.Delete(degreeFileName); } FileExtractResult fileResult = null; string filename = StatResultToFile(statFileNames, result, "SNW", outFileIdentify, title, extinfo); fileResult = new FileExtractResult("0SDC", filename); return(fileResult); } return(null); }
private IFileExtractResult GenrateIInterested(MemPixelFeatureMapper <UInt16> result, IRasterDataProvider currPrd, string subProductIndentify) { RasterIdentify id = new RasterIdentify(currPrd.fileName.ToUpper()); id.ThemeIdentify = "CMA"; id.ProductIdentify = "UHE"; id.SubProductIdentify = subProductIndentify; id.IsOutput2WorkspaceDir = true; using (IInterestedRaster <UInt16> iir = new InterestedRaster <UInt16>(id, new Size(currPrd.Width, currPrd.Height), currPrd.CoordEnvelope.Clone(), currPrd.SpatialRef)) { iir.Put(result); IFileExtractResult fileResult = new FileExtractResult(subProductIndentify, iir.FileName); fileResult.SetDispaly(false); return(fileResult); } }
private IExtractResult StateAreaCol(int NormalLevel, string[] files, Dictionary <string, StatInfo> result, int HILevel) { string[] normalDesc = GetStringArray("NormalDesc"); List <string[]> valueItems = new List <string[]>(); List <string> temp = null; List <string> columnList = new List <string>(); columnList.Add("日期"); string DateStr = GetStringArgument("DateStr"); for (UInt16 col = 0; col < HILevel; col++) { columnList.Add(normalDesc == null || col >= normalDesc.Length ? (NormalLevel - col).ToString() : normalDesc[col]); } IRasterDataProvider rdp = GeoDataDriver.Open(files[0]) as IRasterDataProvider; double areaBase = 0f; areaBase = GetAreaBase(rdp, areaBase); foreach (string key in result.Keys) { temp = new List <string>(); temp.Add(DataIdentifyMatcher.GetOrbitDateTime(key).AddHours(8).ToString(DateStr)); for (UInt16 level = 0; level < HILevel; level++) { if (!result[key].UHPI.ContainsKey((UInt16)(NormalLevel - level))) { temp.Add("0"); } else { temp.Add(Math.Round(result[key].UHPI[(UInt16)(NormalLevel - level)] * areaBase / Math.Pow(10, 6), 2).ToString()); } } valueItems.Add(temp.ToArray()); } string title = "统计日期:" + DateTime.Now.ToShortDateString() + " 面积单位:平方公里"; string[] columns = columnList.ToArray(); IStatResult statResult = new StatResult(title, columns, valueItems.ToArray()); string filename = StatResultToFile(files, statResult, "UHE", "UHAR", "热岛面积", string.Empty, 1, false, 1); FileExtractResult fileResult = new FileExtractResult("UHAR", filename); fileResult.Add2Workspace = true; fileResult.SetDispaly(false); return(fileResult); }
public void ExportOutFile(string dtmi, string outfilePath) { string qualifiedPath = Path.GetFullPath(outfilePath); (int returnCode, _, string standardError) = ClientInvokator.Invoke($"export -o \"{qualifiedPath}\" --dtmi \"{dtmi}\" --repo \"{TestHelpers.TestLocalModelRepository}\""); Assert.AreEqual(Handlers.ReturnCodes.Success, returnCode); Assert.False(standardError.Contains(Outputs.DefaultErrorToken)); FileExtractResult extractResult = ParsingUtils.ExtractModels(new FileInfo(qualifiedPath)); List <string> modelsResult = extractResult.Models; string targetId = ParsingUtils.GetRootId(modelsResult[0]); Assert.AreEqual(dtmi, targetId); }
private IExtractResult CompareAlgorithm() { string compareFile = _argumentProvider.GetArg("CompareFile").ToString(); string file = _argumentProvider.GetArg("MainFile").ToString(); if (file == null && string.IsNullOrEmpty(file)) { return(null); } string outFileIdentify = GetStringArgument("OutFileIdentify"); string productIdentify = _subProductDef.ProductDef.Identify; IPixelFeatureMapper <Int16> rasterResult = MakeCompareRaster <float, Int16>(productIdentify, compareFile, file, (fstFileValue, sedFileValue) => { if (fstFileValue > 0f && sedFileValue == 1f) { return(1); } else if (fstFileValue == 0f && sedFileValue == 1f) { return(4); } else if (fstFileValue > 0f && sedFileValue == 0f) { return(5); } else { return(0); } }, false); if (rasterResult == null) { return(null); } else { RasterIdentify rid = GetRasterIdentifyID(new RasterIdentify(new string[] { compareFile, file })); IInterestedRaster <Int16> iir = new InterestedRaster <Int16>(rid, rasterResult.Size, rasterResult.CoordEnvelope, null); iir.Put(rasterResult); iir.Dispose(); FileExtractResult result = new FileExtractResult(outFileIdentify, iir.FileName); result.SetDispaly(false); return(result); } }
internal IFileExtractResult GeneratorKB(IArgumentProvider argProvider, Dictionary <int, FireAreaFeature> features) { DateTime orbitDateTime = DateTime.MinValue; string saveFilename = GetFALTFilenameKB(argProvider, out orbitDateTime); List <string[]> excelInfos = new List <string[]>(); string[] columns = new string[] { "火区号", "中心经度", "中心纬度", "火点像元个数", "像元覆盖面积(平方公里)", "明火面积(公顷)", "省地县", "林地", "草地", "农田", "其他" }; List <string> listTemp = new List <string>(); for (int i = 0; i < features.Count; i++) { listTemp.Add((features[i].FireReaIndex + 1).ToString()); listTemp.Add(features[i].Longitude.ToString()); listTemp.Add(features[i].Latitude.ToString()); listTemp.Add(features[i].FireCount.ToString("#")); listTemp.Add(features[i].FireArea.ToString("#0.000")); listTemp.Add(features[i].SecondryFireArea.ToString("#0.000")); listTemp.Add(string.IsNullOrEmpty(features[i].XJName) ? @"\" : features[i].XJName); listTemp.Add(features[i].WoodlandPercent == 0 ? @"\" : (features[i].WoodlandPercent * 100 + "%")); listTemp.Add(features[i].GrasslandPercent == 0 ? @"\" : (features[i].GrasslandPercent * 100 + "%")); listTemp.Add(features[i].FarmlandPercent == 0 ? @"\" : (features[i].FarmlandPercent * 100 + "%")); listTemp.Add(features[i].OtherPercent == 0 ? @"\" : (features[i].OtherPercent * 100 + "%")); excelInfos.Add(listTemp.ToArray()); listTemp.Clear(); } IStatResult result = new StatResult("火区信息统计结果", columns, excelInfos.ToArray()); using (StatResultToExcelFile excelControl = new StatResultToExcelFile()) { excelControl.Init(); excelControl.Add(true, "火区信息数据统计", result, false, 0); excelControl.WinExcelControl.SetCellValue(2, 2, 2, 12, 0, masExcelAlignType.Center, "火情信息快报", null); string timestring = string.Format("时间:{0}(北京时)", orbitDateTime.AddHours(8).ToString("yyyy年MM月dd日 HH:mm")); excelControl.WinExcelControl.SetCellValue(3, 2, 3, 6, 0, masExcelAlignType.Left, timestring, null); excelControl.WinExcelControl.SetCellValue(3, 7, 3, 12, 0, masExcelAlignType.Right, "国家卫星气象中心", null); excelControl.WinExcelControl.SetCellValue(4, 2, 4, 12, 1, masExcelAlignType.Center, "火区信息数据统计", null); excelControl.SaveFile(saveFilename); } IFileExtractResult resultFile = new FileExtractResult("FRIK", saveFilename); resultFile.SetDispaly(false); return(resultFile); }
private void SaveToShp() { try { if (_iceFeatures == null || _iceFeatures.Count == 0) { MsgBox.ShowInfo("没有绘制的海冰冰缘线"); return; } string iceLineShpFileName = GetIceLineShpFileName(); TryExportIceLine(_iceFeatures.Keys.ToArray(), iceLineShpFileName); //TryExport2ShapeFile(_iceFeatures.Keys.ToArray(), iceLineShpFileName, enumShapeType.Polyline); IExtractResult result = new FileExtractResult("IEDG", iceLineShpFileName, true); IMonitoringSubProduct msp = (_session.MonitoringSession as IMonitoringSession).ActiveMonitoringSubProduct; //by chennan 修正冰缘线结果显示为多个图层问题 //DisplayResultClass.DisplayResult(_session, msp, result, false); string iceControlPointShpFileName = GeoDo.RSS.MIF.Prds.ICE.IceEdgeFileNameHelper.GetIceEdgeControlInfoFilename(iceLineShpFileName); //Path.ChangeExtension(iceLineShpFileName, ".controlpoint.shp"); TryExportIceControlPoint(_iceFeatures.Values.ToArray(), iceControlPointShpFileName); StringBuilder str = new StringBuilder(); str.AppendLine("冰缘线导出成功:"); str.AppendLine(iceLineShpFileName); //by chennan 记录导出时的冰缘线图层名,用于关闭窗体时删除相应图层 linLayerName.Add(Path.GetFileNameWithoutExtension(iceLineShpFileName)); str.AppendLine(iceControlPointShpFileName); //if (ExportToShapeFile != null) // ExportToShapeFile(iceLineShpFileName); ActiveWorkSpace(iceLineShpFileName); MsgBox.ShowInfo(str.ToString()); } catch (Exception ex) { } finally { } }
private IExtractResult StateAreaRow(int NormalLevel, string[] files, Dictionary <string, StatInfo> result, int HILevel) { string[] normalDesc = GetStringArray("NormalDesc"); string DateStr = GetStringArgument("DateStr"); List <string[]> valueItems = new List <string[]>(); IRasterDataProvider rdp = GeoDataDriver.Open(files[0]) as IRasterDataProvider; double areaBase = 0f; areaBase = GetAreaBase(rdp, areaBase); int col = 0; List <string> columnList = new List <string>(); columnList.Add("日期"); for (int row = 0; row < HILevel; row++) { valueItems.Add(new string[result.Count + 1]); valueItems[row][0] = normalDesc == null || row >= normalDesc.Length ? (NormalLevel - row).ToString() : normalDesc[row]; } foreach (string key in result.Keys) { col++; columnList.Add(DataIdentifyMatcher.GetOrbitDateTime(key).AddHours(8).ToString(DateStr)); for (int row = 0; row < HILevel; row++) { for (UInt16 level = (UInt16)(NormalLevel - row), num = 0; num < HILevel; num++) { valueItems[row][col] = Math.Round(result[key].UHPI[level] * areaBase / Math.Pow(10, 6), 2).ToString(); } } } string title = "统计日期:" + DateTime.Now.ToShortDateString() + " 面积单位:平方公里"; string[] columns = columnList.ToArray(); IStatResult statResult = new StatResult(title, columns, valueItems.ToArray()); string filename = StatResultToFile(files, statResult, "UHE", "UHAR", "热岛面积", string.Empty, 1, false, 1); FileExtractResult fileResult = new FileExtractResult("UHAR", filename); fileResult.Add2Workspace = true; fileResult.SetDispaly(false); return(fileResult); }
private IExtractResultBase ComputeSingleFile(string fname, IRasterExtracter <ushort, short> extracter, int[] bandNos, string express) { using (IRasterDataProvider prd = GeoDataDriver.Open(fname) as IRasterDataProvider) { if (prd == null) { return(null); } int bandCount = prd.BandCount; foreach (int band in bandNos) { if (bandCount == 0 || bandCount == 1) { PrintInfo("请选择正确的局地文件进行计算。"); return(null); } if (bandCount < band) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误!"); return(null); } } IArgumentProvider aPrd = new ArgumentProvider(prd, null); extracter.Reset(aPrd, bandNos, express); string filename = string.Empty; using (IPixelFeatureMapper <Int16> resultNDVI = new MemPixelFeatureMapper <Int16>(_identify, prd.Width * prd.Height, new System.Drawing.Size(prd.Width, prd.Height), prd.CoordEnvelope, prd.SpatialRef)) { extracter.Extract(resultNDVI); RasterIdentify rid = GetRasterIdentify(fname); using (InterestedRaster <Int16> iir = new InterestedRaster <Int16>(rid, new System.Drawing.Size(prd.Width, prd.Height), prd.CoordEnvelope)) { iir.Put(resultNDVI); filename = iir.FileName; } IFileExtractResult ndviResult = new FileExtractResult(_identify, filename); ndviResult.SetDispaly(false); return(ndviResult); } } }
public void ExportInvocationWithModelFile(string modelFilePath, string expectedDeps) { string qualifiedModelFilePath = Path.GetFullPath(Path.Combine(TestHelpers.TestLocalModelRepository, modelFilePath)); (int returnCode, string standardOut, string standardError) = ClientInvokator.Invoke($"export --model-file \"{qualifiedModelFilePath}\" --repo \"{TestHelpers.TestLocalModelRepository}\""); Assert.AreEqual(Handlers.ReturnCodes.Success, returnCode, standardError); Assert.False(standardError.Contains(Outputs.DefaultErrorToken)); FileExtractResult extractResult = ParsingUtils.ExtractModels(standardOut); List <string> modelsResult = extractResult.Models; string[] expectedDtmis = expectedDeps.Split(",", StringSplitOptions.RemoveEmptyEntries); Assert.True(modelsResult.Count == expectedDtmis.Length); foreach (string model in modelsResult) { string targetId = ParsingUtils.GetRootId(model); Assert.True(expectedDtmis.Contains(targetId)); } }
/// <summary> /// 生成Txt火区信息列表 /// </summary> /// <param name="argProvider"></param> /// <param name="features"></param> /// <returns></returns> /* * internal IFileExtractResult Generator(IArgumentProvider argProvider, Dictionary<int, FireAreaFeature> features) * { * DateTime orbitDateTime = DateTime.MinValue; * string saveFilename = GetFALTFilename(argProvider, out orbitDateTime); * using (StreamWriter sw = new StreamWriter(saveFilename, false, Encoding.UTF8)) * { * foreach (FireSubareaColumnHeader item in FireSubareaColumnHeaderDef.FireSubarea) * { * sw.Write(item.Caption); * sw.Write("\t"); * } * sw.WriteLine(); * for (int i = 0; i < features.Count; i++) * { * sw.Write(features[i].FireReaIndex); * sw.Write("\t"); * sw.Write(DegreeConvert(features[i].Longitude)); * sw.Write("\t"); * sw.Write(DegreeConvert(features[i].Latitude)); * sw.Write("\t"); * sw.Write(features[i].FireCount.ToString("#").PadRight(10)); * sw.Write("\t"); * sw.Write(features[i].FireArea.ToString("#0.000").PadRight(10)); * sw.Write("\t"); * sw.Write(features[i].SecondryFireArea.ToString("#0.000").PadRight(10)); * sw.Write("\t"); * sw.Write(string.IsNullOrEmpty(features[i].XJName) ? @"\".PadRight(30) : features[i].XJName.PadRight(30)); * sw.Write("\t"); * sw.Write(features[i].WoodlandPercent == 0 ? @"\".PadRight(20) : (features[i].WoodlandPercent * 100 + "%").PadRight(10)); * sw.Write("\t"); * sw.Write(features[i].GrasslandPercent == 0 ? @"\".PadRight(20) : (features[i].GrasslandPercent * 100 + "%").PadRight(10)); * sw.Write("\t"); * sw.Write(features[i].FarmlandPercent == 0 ? @"\".PadRight(20) : (features[i].FarmlandPercent * 100 + "%").PadRight(10)); * sw.Write("\t"); * sw.Write(features[i].OtherPercent == 0 ? @"\".PadRight(20) : (features[i].OtherPercent * 100 + "%").PadRight(10)); * sw.Write("\t"); * sw.WriteLine(); * } * } * IFileExtractResult result = new FileExtractResult("FRIL", saveFilename); * result.SetDispaly(false); * return result; * } */ /// <summary> /// 生成Excel火区信息列表 /// </summary> /// <param name="argProvider"></param> /// <param name="features"></param> /// <returns></returns> internal IFileExtractResult Generator(IArgumentProvider argProvider, Dictionary <int, FireAreaFeature> features) { DateTime orbitDateTime = DateTime.MinValue; string saveFilename = GetFALTFilename(argProvider, out orbitDateTime); List <string[]> excelInfos = new List <string[]>(); string[] columns = new string[] { "火区号", "中心经度", "中心纬度", "火点像元个数", "像元覆盖面积(平方公里)", "明火面积(公顷)", "省地县", "林地", "草地", "农田", "其他" }; List <string> listTemp = new List <string>(); for (int i = 0; i < features.Count; i++) { listTemp.Add((features[i].FireReaIndex + 1).ToString()); listTemp.Add(features[i].Longitude.ToString()); listTemp.Add(features[i].Latitude.ToString()); listTemp.Add(features[i].FireCount.ToString("#")); listTemp.Add(features[i].FireArea.ToString("#0.000")); listTemp.Add(features[i].SecondryFireArea.ToString("#0.000")); listTemp.Add(string.IsNullOrEmpty(features[i].XJName) ? @"\" : features[i].XJName); listTemp.Add(features[i].WoodlandPercent == 0 ? @"\" : (features[i].WoodlandPercent * 100 + "%")); listTemp.Add(features[i].GrasslandPercent == 0 ? @"\" : (features[i].GrasslandPercent * 100 + "%")); listTemp.Add(features[i].FarmlandPercent == 0 ? @"\" : (features[i].FarmlandPercent * 100 + "%")); listTemp.Add(features[i].OtherPercent == 0 ? @"\" : (features[i].OtherPercent * 100 + "%")); excelInfos.Add(listTemp.ToArray()); listTemp.Clear(); } IStatResult result = new StatResult("火区信息统计结果", columns, excelInfos.ToArray()); using (StatResultToExcelFile excelControl = new StatResultToExcelFile()) { excelControl.Init(); excelControl.Add(true, "火区信息数据统计", result, false, 0); excelControl.SaveFile(saveFilename); } IFileExtractResult resultFile = new FileExtractResult("FRIL", saveFilename); resultFile.SetDispaly(false); return(resultFile); }
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); }
public IFileExtractResult ExportILSTToExcel(string saveFileName) { string[] lineInfos = File.ReadAllLines(saveFileName, Encoding.Default); List <string[]> excelInfos = new List <string[]>(); string[] columns = new string[] { "火区号", "中心经度", "中心纬度", "火点像元个数", "像元覆盖面积(平方公里)", "明火面积(公顷)", "省地县", "林地", "草地", "农田", "其他" }; for (int i = 1; i < lineInfos.Length; i++) { excelInfos.Add(lineInfos[i].Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries)); } IStatResult result = new StatResult("火区信息统计结果", columns, excelInfos.ToArray()); using (StatResultToExcelFile excelControl = new StatResultToExcelFile()) { excelControl.Init(); excelControl.Add(true, "火区信息数据统计", result, false, 0); saveFileName = Path.Combine(Path.GetDirectoryName(saveFileName), Path.GetFileNameWithoutExtension(saveFileName) + ".XLSX"); excelControl.SaveFile(saveFileName); } IFileExtractResult resultFile = new FileExtractResult("FRIL", saveFileName); resultFile.SetDispaly(false); return(resultFile); }
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); }
/// <summary> /// 判识结果保存事件 /// </summary> /// <param name="piexd">判识结果</param> /// <param name="progressTracker"></param> /// <returns></returns> /// 原始影像和判识结果读取到一个结果集中,分为输入输出两个,输出的就是需要保存的结果 public override IExtractResult MakeExtProduct(IPixelIndexMapper piexd, Action <int, string> progressTracker) { //生成判识结果文件 IInterestedRaster <UInt16> iir = null; RasterIdentify id = new RasterIdentify(_argumentProvider.DataProvider.fileName); id.ThemeIdentify = "CMA"; id.ProductIdentify = "FOG"; id.SubProductIdentify = _identify; id.GenerateDateTime = DateTime.Now; iir = new InterestedRaster <UInt16>(id, piexd.Size, piexd.CoordEnvelope); int[] idxs = piexd.Indexes.ToArray(); iir.Put(idxs, 1); //原始影像raster IRasterDataProvider sourceraster = _argumentProvider.DataProvider as IRasterDataProvider; List <RasterMaper> listRaster = new List <RasterMaper>(); RasterMaper rmsoure = new RasterMaper(sourceraster, GetBandArray(sourceraster.BandCount)); RasterMaper rmpiexd = new RasterMaper(iir.HostDataProvider, new int[] { 1 }); int totalbandcount = sourceraster.BandCount; listRaster.Add(rmpiexd); listRaster.Add(rmsoure); try { string outFileName = GetFileName(new string[] { _argumentProvider.DataProvider.fileName }, _subProductDef.ProductDef.Identify, "SRDA", ".ldf", null); 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[1].RasterBandsData == null || rvInVistor[0].RasterBandsData[0] == null || rvInVistor[1].RasterBandsData[0] == null) { return; } // if (_argumentProvider.AOIs == null) for (int index = 0; index < dataLength; index++) { if (rvInVistor[0].RasterBandsData[0][index] == 1) { for (int i = 0; i < totalbandcount; i++) { rvOutVistor[0].RasterBandsData[i][index] = rvInVistor[1].RasterBandsData[i][index]; } } } } )); //执行 rfr.Excute(0); } string dstfilename = outFileName.Replace(".ldf", ".dat"); if (File.Exists(dstfilename)) { File.Delete(dstfilename); } File.Move(outFileName, dstfilename); FileExtractResult res = new FileExtractResult("FOG", dstfilename, true); res.SetDispaly(false); return(res); } finally { iir.Dispose(); if (File.Exists(iir.FileName)) { File.Delete(iir.FileName); } } }
public static IExtractResult AVGProcessor(Action <int, string> progressTracker, IContextMessage contextMessage, bool add2Workspace, string[] fileNames, int bandNo, string subProIdentify, UInt16[] cloudValues, UInt16[] waterValues, string outFileName) { List <RasterMaper> rms = new List <RasterMaper>(); try { for (int i = 0; i < fileNames.Length; i++) { IRasterDataProvider inRaster = RasterDataDriver.Open(fileNames[i]) as IRasterDataProvider; if (inRaster.BandCount < bandNo) { PrintInfo(contextMessage, "请选择正确的数据进行平均值合成。"); return(null); } RasterMaper rm = new RasterMaper(inRaster, new int[] { bandNo }); 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 <ushort, ushort> rfr = null; rfr = new RasterProcessModel <ushort, ushort>(progressTracker); rfr.SetRaster(fileIns, fileOuts); rfr.RegisterCalcModel(new RasterCalcHandler <ushort, ushort>((rvInVistor, rvOutVistor, aoi) => { int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX; ushort[] sumData = new ushort[dataLength]; ushort[] countData = new ushort[dataLength]; if (cloudValues != null && cloudValues.Length > 0) { foreach (RasterVirtualVistor <ushort> rv in rvInVistor) { if (rv.RasterBandsData == null) { continue; } ushort[] dt = rv.RasterBandsData[0]; if (dt != null) { for (int index = 0; index < dataLength; index++) { if (IsNanValue(dt[index], cloudValues) || IsNanValue(dt[index], waterValues)) { sumData[index] = (sumData[index] == 0 && countData[index] == 0) ? dt[index] : sumData[index]; continue; } else { if (IsNanValue(sumData[index], cloudValues) || IsNanValue(dt[index], waterValues) && countData[index] == 0) { sumData[index] = 0; } if (dt[index] == 0) { continue; } sumData[index] += dt[index]; countData[index]++; } } } } } for (int index = 0; index < dataLength; index++) { if (countData[index] != 0) { rvOutVistor[0].RasterBandsData[0][index] = (ushort)(sumData[index] / countData[index]); } else { rvOutVistor[0].RasterBandsData[0][index] = sumData[index]; } } })); //执行 rfr.Excute(); FileExtractResult res = new FileExtractResult(subProIdentify, outFileName, add2Workspace); res.SetDispaly(false); return(res); } } finally { foreach (RasterMaper rm in rms) { rm.Raster.Dispose(); } } }
private IExtractResult LAODAlgorithm(Action <int, string> progressTracker) { IRasterOperator <Int16> roper = new RasterOperator <Int16>(); string[] files = GetStringArray("SelectedPrimaryFiles"); if (files == null || files.Length == 0) { return(null); } string[] argFileArg = _argumentProvider.GetArg("RegionFileName") as string[]; string argFileName = argFileArg[0]; if (string.IsNullOrEmpty(argFileName)) { PrintInfo("请设置等级参数文件!"); return(null); } SortedDictionary <float, float[]> levelRegions = GetArgFileRegion(argFileName); if (levelRegions == null || levelRegions.Count == 0) { return(null); } string AODFile = Convert.ToString(_argumentProvider.GetArg("AODFile")); if (string.IsNullOrWhiteSpace(AODFile)) { return(null); } string[] aodFiles = AODFile.Split(new char[] { ',' }); if (aodFiles.Length != 2) { return(null); } string aodFile = aodFiles[0]; int bandNo = 1; IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster; int aodNo = TryGetBandNo(bandNameRaster, "AODNO"); List <RasterMaper> rms = new List <RasterMaper>(); try { IRasterDataProvider dblv = RasterDataDriver.Open(files[0]) as IRasterDataProvider; RasterMaper rmDBLV = new RasterMaper(dblv, new int[] { bandNo }); rms.Add(rmDBLV); IRasterDataProvider aod = RasterDataDriver.Open(aodFile) as IRasterDataProvider; if (aod.BandCount < bandNo) { PrintInfo("请选择正确的AOD数据进行定量产品计算。"); return(null); } RasterMaper rmAOD = new RasterMaper(aod, new int[] { aodNo }); rms.Add(rmAOD); //输出文件准备(作为输入栅格并集处理) RasterIdentify ri = GetRasterIdentifyID(files); string outFileName = MifEnvironment.GetTempDir() + "\\" + ri.ToWksFileName(".dat"); bool isVaild = false; 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++) { if (rvInVistor[0].RasterBandsData != null && rvInVistor[0].RasterBandsData[0] != null && rvInVistor[0].RasterBandsData[0][index] != 0) { if (rvInVistor[1].RasterBandsData != null && rvInVistor[1].RasterBandsData[0] != null) { foreach (float minValue in levelRegions.Keys) { if (rvInVistor[1].RasterBandsData[0][index] >= minValue && rvInVistor[1].RasterBandsData[0][index] < levelRegions[minValue][0]) { rvOutVistor[0].RasterBandsData[0][index] = (Int16)levelRegions[minValue][1]; isVaild = true; } } if (!isVaild) { rvOutVistor[0].RasterBandsData[0][index] = (Int16)1; } isVaild = false; } } } })); //执行 rfr.Excute(); if (File.Exists(outFileName)) { string dstFilename = ri.ToWksFullFileName(".dat"); CopyFileToDstDir(outFileName, dstFilename); FileExtractResult res = new FileExtractResult(_subProductDef.Identify, dstFilename, true); res.SetDispaly(false); CreateThemegrahic(dstFilename); return(res); } return(null); } } finally { foreach (RasterMaper rm in rms) { rm.Raster.Dispose(); } } }
private IFileExtractResult ComputeSnowDepth(string inputFileName, int[] bandNos, string[] argFiles, double[] sdParas) { List <RasterMaper> rms = null; IRasterDataProvider outRaster = null; RasterProcessModel <Int16, double> rfr = null; try { rms = new List <RasterMaper>(); IRasterDataProvider inRaster = GeoDataDriver.Open(inputFileName) as IRasterDataProvider; RasterMaper fileIn = new RasterMaper(inRaster, bandNos); rms.Add(fileIn); foreach (string file in argFiles) { IRasterDataProvider argRaster = GeoDataDriver.Open(file) as IRasterDataProvider; RasterMaper argRm = new RasterMaper(argRaster, new int[] { 1 }); rms.Add(argRm); } string depthFileName = GetFileName(new string[] { inputFileName }, _subProductDef.ProductDef.Identify, "MWSD", ".dat", null); outRaster = CreateOutRaster(depthFileName, enumDataType.Double, rms.ToArray(), inRaster.ResolutionX); RasterMaper fileOut = new RasterMaper(outRaster, new int[] { 1 }); RasterMaper[] fileIns = rms.ToArray(); RasterMaper[] fileOuts = new RasterMaper[] { fileOut }; rfr = new RasterProcessModel <Int16, double>(); rfr.SetRaster(fileIns, fileOuts); rfr.RegisterCalcModel(new RasterCalcHandler <Int16, double>((rvInVistor, rvOutVistor, aoi) => { if (rvInVistor[0].RasterBandsData[0] != null && rvInVistor[1].RasterBandsData[0] != null && rvInVistor[2].RasterBandsData[0] != null && rvInVistor[3].RasterBandsData[0] != null && rvInVistor[4].RasterBandsData[0] != null) { int dataLength = rvInVistor[0].RasterBandsData[0].Length; int[] type = new int[dataLength]; double[] sdtmp = new double[dataLength]; for (int i = 0; i < dataLength; i++) { //type type[i] = NO_SCATTER; double ch10v = btValue(rvInVistor[0].RasterBandsData[0][i]); double ch10h = btValue(rvInVistor[0].RasterBandsData[1][i]); double ch18v = btValue(rvInVistor[0].RasterBandsData[2][i]); double ch18h = btValue(rvInVistor[0].RasterBandsData[3][i]); double ch23v = btValue(rvInVistor[0].RasterBandsData[4][i]); double ch23h = btValue(rvInVistor[0].RasterBandsData[5][i]); double ch36v = btValue(rvInVistor[0].RasterBandsData[6][i]); double ch36h = btValue(rvInVistor[0].RasterBandsData[7][i]); double ch89v = btValue(rvInVistor[0].RasterBandsData[8][i]); double ch89h = btValue(rvInVistor[0].RasterBandsData[9][i]); double si1 = ch23v - ch89v; double si2 = ch18v - ch36v; if (si1 >= 5 || si2 >= 5) { if (ch23v <= 260) { if (ch18v - ch36v >= 20) { if (si1 - si2 >= WET_FACTOR) { type[i] = THICK_DRY_SNOW; } else { type[i] = THICK_WET_SNOW; } } else { if (si1 - si2 >= 8) { type[i] = THIN_DRY_SNOW; } else { if (si1 - si2 <= WET_FACTOR1) { type[i] = VERY_THICK_WET_SNOW; } else { if (ch18v - ch18h <= 6 && ch18v - ch36v >= 10) { type[i] = THIN_WET_SNOW_OR_FOREST_SNOW; } else { type[i] = NO_SNOW; } } } } } else { type[i] = NO_SNOW; } } else { type[i] = NO_SNOW; } //sdtmp double sdFarmland = sdParas[0] + sdParas[1] * (ch18v - ch36h) + sdParas[2] * (ch89v - ch89h); double sdGrass = sdParas[3] + sdParas[4] * (ch18h - ch36h) - sdParas[5] * (ch18v - ch18h) + sdParas[6] * (ch10v - ch89h) - sdParas[7] * (ch18v - ch89h); double sdBaren = sdParas[8] + sdParas[9] * (ch36h - ch89h) - sdParas[10] * (ch10v - ch89v); double sdForest = sdParas[11] + sdParas[12] * (ch18h - ch36v) - sdParas[13] * (ch18v - ch18h) + sdParas[14] * (ch89v - ch89h); sdtmp[i] = (rvInVistor[1].RasterBandsData[0][i] * sdBaren + rvInVistor[2].RasterBandsData[0][i] * sdGrass + rvInVistor[3].RasterBandsData[0][i] * sdForest + rvInVistor[4].RasterBandsData[0][i] * sdFarmland) / 10000; //原地类百分比文件扩大了10000倍 //设置输出数据值 if (type[i] == NO_SNOW || type[i] == THICK_WET_SNOW || type[i] == THIN_WET_SNOW_OR_FOREST_SNOW || type[i] == VERY_THICK_WET_SNOW) { sdtmp[i] = 0.0; } if (sdtmp[i] < 0) { sdtmp[i] = 0; } else { sdtmp[i] = sdtmp[i]; } rvOutVistor[0].RasterBandsData[0][i] = sdtmp[i]; } } //输出 })); rfr.Excute(); IFileExtractResult res = new FileExtractResult(_subProductDef.Identify, depthFileName, true); res.SetDispaly(false); return(res); } finally { if (outRaster != null) { outRaster.Dispose(); } if (rms != null && rms.Count > 0) { foreach (RasterMaper rm in rms) { if (rm.Raster != null) { rm.Raster.Dispose(); } } } } }
private IFileExtractResult ComputeSnowSWE(string filenameDensity, string depthFileName) { List <RasterMaper> rms = null; IRasterDataProvider outRaster = null; RasterProcessModel <double, double> rfr = null; try { rms = new List <RasterMaper>(); IRasterDataProvider inRaster1 = GeoDataDriver.Open(depthFileName) as IRasterDataProvider; RasterMaper fileIn1 = new RasterMaper(inRaster1, new int[] { 1 }); rms.Add(fileIn1); IRasterDataProvider inRaster2 = GeoDataDriver.Open(filenameDensity) as IRasterDataProvider; RasterMaper fileIn2 = new RasterMaper(inRaster2, new int[] { 1 }); rms.Add(fileIn2); string sweFileName = GetFileName(new string[] { depthFileName }, _subProductDef.ProductDef.Identify, "MSWE", ".dat", null); outRaster = CreateOutRaster(sweFileName, enumDataType.Double, rms.ToArray(), inRaster2.ResolutionX); RasterMaper fileOut = new RasterMaper(outRaster, new int[] { 1 }); RasterMaper[] fileIns = rms.ToArray(); RasterMaper[] fileOuts = new RasterMaper[] { fileOut }; rfr = new RasterProcessModel <double, double>(); rfr.SetRaster(fileIns, fileOuts); rfr.RegisterCalcModel(new RasterCalcHandler <double, double>((rvInVistor, rvOutVistor, aoi) => { if (rvInVistor[0].RasterBandsData[0] != null && rvInVistor[1].RasterBandsData[0] != null) { int dataLength = rvInVistor[0].SizeY * rvInVistor[0].SizeX; double[] swetmp = new double[dataLength]; for (int i = 0; i < dataLength; i++) { swetmp[i] = rvInVistor[0].RasterBandsData[0][i] * rvInVistor[1].RasterBandsData[0][i] * 10; if (swetmp[i] < 0) { swetmp[i] = 0; } rvOutVistor[0].RasterBandsData[0][i] = swetmp[i]; } } })); rfr.Excute(); IFileExtractResult res = new FileExtractResult(_subProductDef.Identify, sweFileName, true); res.SetDispaly(false); return(res); } finally { if (outRaster != null) { outRaster.Dispose(); } if (rms != null && rms.Count > 0) { foreach (RasterMaper rm in rms) { if (rm.Raster != null) { rm.Raster.Dispose(); } } } } }