private void btOPTD_Click(object sender, EventArgs e) { ProductColorTable[] tables = ProductColorTableFactory.GetAllColorTables(); ProductColorTable table = ProductColorTableFactory.GetColorTable("FOG", "TIMS"); ExtractProductIdentify exPro = new ExtractProductIdentify(); exPro.ThemeIdentify = "CMA"; exPro.ProductIdentify = "FOG"; exPro.SubProductIdentify = "OPTD"; ThemeDef theme = MonitoringThemeFactory.GetThemeDefByIdentify("CMA"); ProductDef pro = theme.GetProductDefByIdentify("FOG"); SubProductDef sub = pro.GetSubProductDefByIdentify("OPTD"); AlgorithmDef alg = sub.GetAlgorithmDefByIdentify("OPTDAlgorithm"); IArgumentProvider arg = MonitoringThemeFactory.GetArgumentProvider(exPro, "OPTDAlgorithm", "FY3A", "MERSI"); arg.SetArg("OPTDAlgorithm", alg); IRasterDataProvider prd = GetRasterDataProvider("FOG"); arg.DataProvider = prd; arg.SetArg("CSRFile", @"E:\code\SMARTII\SRC\【控制】监测分析框架\testCN\bin\Release\TEMP\FOG_0CSR_FY3A_MERSI_10M_20120614001422_20120615001422.dat"); arg.SetArg("DBLVFile", @"E:\code\SMARTII\SRC\【控制】监测分析框架\testCN\bin\Release\TEMP\FOG_DBLV_FY3A_MERSI_1000M_20120614005135_20120615005135.dat"); IMonitoringSubProduct bin = new SubProductOPTDFOG(sub); IPixelFeatureMapper <Int16> result = bin.Make(null) as IPixelFeatureMapper <Int16>; result.Dispose(); }
public void Put(IPixelFeatureMapper <T> result) { int blockSize = Math.Min(10000, result.Count); List <int> bufferIdx = new List <int>(blockSize); List <T> bufferFeatures = new List <T>(blockSize); int i = 0; int naturalIdx = 0; foreach (int idx in result.Indexes) { if (i == blockSize) { i = 0; Put(bufferIdx.ToArray(), bufferFeatures.ToArray()); bufferIdx.Clear(); bufferFeatures.Clear(); } bufferIdx.Add(idx); bufferFeatures.Add(result.GetValueByIndex(naturalIdx)); i++; naturalIdx++; } if (bufferIdx.Count > 0) { Put(bufferIdx.ToArray(), bufferFeatures.ToArray()); } }
public void Extract(IPixelFeatureMapper <TFeature> extractedPixels) { if (_infoExtracter == null || _featureComputer == null) { return; } _infoExtracter.VisitPixel(_visitBandNos, (idx, values) => { extractedPixels.Put(idx, _featureComputer(idx, values)); }); }
public IExtractResult CompareAnalysisByPixel <T1, T>(string productName, string productIdentify, string extInfos, Func <T1, T1, T> function) { string[] files = GetStringArray("SelectedPrimaryFiles"); if (files == null || files.Length == 0 || files.Length == 1) { return(null); } //文件列表排序 string[] dstFiles = SortFileName(files); string outFileIdentify = GetStringArugment("OutFileIdentify"); object obj = _argumentProvider.GetArg("ThemeGraphyGenerator"); if (obj == null) { return(null); } IThemeGraphGenerator tgg = obj as IThemeGraphGenerator; if (tgg == null) { return(null); } string templatName = GetStringArugment("ThemeGraphTemplateName"); string colorTabelName = GetColorTableName("colortablename"); ExtractResultArray results = new ExtractResultArray(productIdentify + "_COMP"); for (int i = 0; i < dstFiles.Length - 1; i++) { //生成专题图 IPixelFeatureMapper <T> rasterResult = MakeCompareRaster <T1, T>(productIdentify, dstFiles[i], dstFiles[i + 1], function); string aoiTemplateName = string.Empty; Dictionary <string, int[]> aoi = null; GetAOI(out aoiTemplateName, out aoi); if (rasterResult == null) { continue; } RasterIdentify rid = new RasterIdentify(dstFiles[i]); IInterestedRaster <T> iir = new InterestedRaster <T>(rid, rasterResult.Size, rasterResult.CoordEnvelope, rasterResult.SpatialRef); iir.Put(rasterResult); iir.Dispose(); string resultFilename = tgg.Generate(iir.FileName, templatName, MasicAOI(aoi, ref extInfos), extInfos, outFileIdentify, colorTabelName); if (string.IsNullOrEmpty(resultFilename)) { return(null); } FileExtractResult result = new FileExtractResult(outFileIdentify, resultFilename); if (result != null) { results.Add(result); } } return(results); }
private void button14_Click(object sender, EventArgs e) { //构造参数提供者 string fname = @"f:\\FY3A_Mersi_2010_06_24_10_00_1000M_L1B_PRJ_Whole.LDF"; IRasterDataProvider prd = GeoDataDriver.Open(fname) as IRasterDataProvider; ArgumentProvider argprd = new ArgumentProvider(prd, null); //构造判识表达式 //string express = "(band4 + band3) == 0? 0f : (band4 - band3) / (float)(band4 + band3)"; string express = "NDVI(band4,band3)"; int[] bandNos = new int[] { 4, 3 }; //构造栅格计算判识器 IRasterExtracter <UInt16, float> extracter = new SimpleRasterExtracter <UInt16, float>(); extracter.Reset(argprd, bandNos, express); //判识 resultNDVI = new MemPixelFeatureMapper <float>("NDVI", 1000, new Size(prd.Width, prd.Height), prd.CoordEnvelope, prd.SpatialRef); Stopwatch sw = new Stopwatch(); sw.Start(); extracter.Extract(resultNDVI); //sw.Stop(); //Text = sw.ElapsedMilliseconds.ToString(); //判识结果生成二值位图 //IBinaryBitmapBuilder builder = new BinaryBitmapBuilder(); //Size bmSize = new Size(prd.Width / 2, prd.Height / 2); //Bitmap bitmap = builder.CreateBinaryBitmap(bmSize, Color.Red, Color.Transparent); //builder.Fill(idxs, new Size(prd.Width, prd.Height), ref bitmap); //bitmap.Save("f:\\1.png", ImageFormat.Png); //判识结果永久保存 RasterIdentify id = new RasterIdentify(); id.ThemeIdentify = "CMA"; id.ProductIdentify = "FIR"; id.SubProductIdentify = "NDVI"; id.Satellite = "FY3A"; id.Sensor = "MERSI"; id.Resolution = "250M"; id.OrbitDateTime = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0, 0)); id.GenerateDateTime = DateTime.Now; IInterestedRaster <float> iir = new InterestedRaster <float>(id, new Size(prd.Width, prd.Height), prd.CoordEnvelope.Clone()); iir.Put(resultNDVI); iir.Dispose(); sw.Stop(); Text = sw.ElapsedMilliseconds.ToString(); int count = iir.Count(aoi, (v) => { return(v == 1); }); iir.Count(aoi, (v) => { return((int)v); }); }
public override IExtractResult MakeExtProduct(IPixelIndexMapper piexd, Action <int, string> progressTracker) { IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster; int visiBandNo = TryGetBandNo(bandNameRaster, "Visible"); int niBandNo = TryGetBandNo(bandNameRaster, "NearInfrared"); IPixelFeatureMapper <float> bpcd; using (IPixelFeatureMapper <float> ndvi = ComputeNDVIResult(_argumentProvider.DataProvider, piexd, visiBandNo, niBandNo)) { bpcd = CreatPixelCoverRate(ndvi); bpcd.SetDispaly(false); } return(bpcd); }
//通过读取历史判识文件获取AOI private void 能见度计算file_Click(object sender, EventArgs e) { InitExIdentify(); _exPro.SubProductIdentify = "VISY"; _sub = _pro.GetSubProductDefByIdentify("VISY"); _exAlg.Satellite = "FY3A"; _exAlg.Sensor = "VIRR"; AlgorithmDef visiAlg = _sub.GetAlgorithmDefByIdentify("Visibility"); IArgumentProvider visiArg = MonitoringThemeFactory.GetArgumentProvider(_exPro, _exAlg); IRasterDataProvider prd = GetRasterDataProviderBinaryFile(); Dictionary <string, object> args = new Dictionary <string, object>(); IArgumentProvider argPrd = new ArgumentProvider(prd, args); RasterPixelsVisitor <UInt16> raster = new RasterPixelsVisitor <UInt16>(argPrd); List <int> idxs = new List <int>(); raster.VisitPixel(new int[] { 1 }, (index, value) => { if (value[0] != 0) { idxs.Add(index); } }); visiArg.DataProvider = GetRasterDataProviderVIRR(); visiArg.AOI = idxs.ToArray(); visiArg.SetArg("Visibility", visiAlg); SubProductRasterDst subraster = new SubProductRasterDst(_sub); IPixelFeatureMapper <UInt16> rasterResult = subraster.Make(null) as IPixelFeatureMapper <UInt16>; // RasterIdentify id = new RasterIdentify(); id.ThemeIdentify = "CMA"; id.ProductIdentify = "SAND"; id.SubProductIdentify = "VISIBILITY"; id.Satellite = "FY3A"; id.Sensor = "VIRRX"; id.Resolution = "1000M"; id.OrbitDateTime = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0, 0)); id.GenerateDateTime = DateTime.Now; IInterestedRaster <UInt16> iir = new InterestedRaster <UInt16>(id, new Size(prd.Width, prd.Height), prd.CoordEnvelope.Clone()); iir.Put(rasterResult); iir.Dispose(); MessageBox.Show("能见度计算完成!"); }
//通过实时判识结果获取AOI private void 能见度计算_Click(object sender, EventArgs e) { InitExIdentify(); _exAlg.CustomIdentify = "陆地"; _exAlg.Satellite = "FY3A"; _exAlg.Sensor = "VIRR"; AlgorithmDef alg = _sub.GetAlgorithmDefByIdentify("FY3Land"); IArgumentProvider arg = MonitoringThemeFactory.GetArgumentProvider(_exPro, _exAlg); IRasterDataProvider prd = GetRasterDataProviderVIRR(); arg.DataProvider = prd; arg.AOI = GetAOI(prd, true); arg.SetArg("FY3Land", alg); SubProductBinaryDst bin = new SubProductBinaryDst(_sub); IPixelIndexMapper result = bin.Make(null) as IPixelIndexMapper; int[] indxs = result.Indexes.ToArray(); _exPro.SubProductIdentify = "VISY"; _sub = _pro.GetSubProductDefByIdentify("VISY"); _exAlg.CustomIdentify = null; AlgorithmDef visiAlg = _sub.GetAlgorithmDefByIdentify("Visibility"); IArgumentProvider visiArg = MonitoringThemeFactory.GetArgumentProvider(_exPro, _exAlg); visiArg.DataProvider = prd; visiArg.AOI = indxs; visiArg.SetArg("Visibility", visiAlg); SubProductRasterDst raster = new SubProductRasterDst(_sub); IPixelFeatureMapper <UInt16> rasterResult = raster.Make(null) as IPixelFeatureMapper <UInt16>; // RasterIdentify id = new RasterIdentify(); id.ThemeIdentify = "CMA"; id.ProductIdentify = "SAND"; id.SubProductIdentify = "VISIBILITY"; id.Satellite = "FY3A"; id.Sensor = "VIRRX"; id.Resolution = "1000M"; id.OrbitDateTime = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0, 0)); id.GenerateDateTime = DateTime.Now; IInterestedRaster <UInt16> iir = new InterestedRaster <UInt16>(id, new Size(prd.Width, prd.Height), prd.CoordEnvelope.Clone()); iir.Put(rasterResult); iir.Dispose(); MessageBox.Show("能见度计算完成!"); }
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); } }
private void btCSR_Click(object sender, EventArgs e) { //IArgumentProviderFactory fac1 = MifEnvironment.ActiveArgumentProviderFactory; ThemeDef theme1 = MonitoringThemeFactory.GetThemeDefByIdentify("CMA"); // fac1.GetThemeDefByIdentify("CMA"); ProductDef pro1 = theme1.GetProductDefByIdentify("FOG"); //ProductDef pro1 = theme1.GetProductDefByIdentify("ICE"); MonitoringProduct mp = new MonitoringProductFOG(); //MonitoringProduct mp = new MonitoringProductICE(pro1); mp = mp; ExtractProductIdentify exPro = new ExtractProductIdentify(); exPro.ThemeIdentify = "CMA"; exPro.ProductIdentify = "FOG"; exPro.SubProductIdentify = "0CSR"; ExtractAlgorithmIdentify exAlg = new ExtractAlgorithmIdentify(); exAlg.CustomIdentify = null; exAlg.Satellite = "FY3A"; exAlg.Sensor = "MERSI"; exAlg.Resolution = null; //IArgumentProviderFactory fac = MifEnvironment.ActiveArgumentProviderFactory; ThemeDef theme = MonitoringThemeFactory.GetThemeDefByIdentify("CMA"); //fac.GetThemeDefByIdentify("CMA"); ProductDef pro = theme.GetProductDefByIdentify("FOG"); SubProductDef sub = pro.GetSubProductDefByIdentify("0CSR"); AlgorithmDef alg = sub.GetAlgorithmDefByIdentify("BaseOrbitAlgorithm"); IArgumentProvider arg = MonitoringThemeFactory.GetArgumentProvider(exPro, "BaseOrbitAlgorithm", "FY3A", "MERSI"); arg.SetArg("BaseOrbitAlgorithm", alg); IRasterDataProvider prd = GetRasterDataProvider("FOG"); arg.DataProvider = prd; arg.SetArg("OrbitFile", new string[] { prd.fileName }); IMonitoringSubProduct bin = new SubProductCSRFOG(sub); IPixelFeatureMapper <UInt16> result = bin.Make(null) as IPixelFeatureMapper <UInt16>; result.Dispose(); }
private void button16_Click(object sender, EventArgs e) { using (VectorAOITemplate v = VectorAOITemplateFactory.GetAOITemplate("贝尔湖")) //贝尔湖 { Size size; IRasterDataProvider prd; Envelope evp = GetEnvelope(out size, out prd); Stopwatch sw = new Stopwatch(); sw.Start(); aoi = v.GetAOI(evp, size); // int[] reverseAOI = AOIHelper.Reverse(aoi, size); IBinaryBitmapBuilder b = new BinaryBitmapBuilder(); Bitmap bm = b.CreateBinaryBitmap(size, Color.Red, Color.Black); b.Fill(reverseAOI, size, ref bm); // string express = "NDVI(band1,band2)"; int[] bandNos = new int[] { 1, 2 }; //构造栅格计算判识器 ArgumentProvider argprd = new ArgumentProvider(prd, null); argprd.AOI = aoi; IRasterExtracter <UInt16, float> extracter = new SimpleRasterExtracter <UInt16, float>(); extracter.Reset(argprd, bandNos, express); //判识 resultNDVI = new MemPixelFeatureMapper <float>("NDVI", 1000, new Size(prd.Width, prd.Height), prd.CoordEnvelope, prd.SpatialRef); extracter.Extract(resultNDVI); // RasterIdentify id = new RasterIdentify(); id.ThemeIdentify = "CMA"; id.ProductIdentify = "FIR"; id.SubProductIdentify = "NDVI"; id.Satellite = "FY3A"; id.Sensor = "MERSI"; id.Resolution = "250M"; id.OrbitDateTime = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0, 0)); id.GenerateDateTime = DateTime.Now; IInterestedRaster <float> iir = new InterestedRaster <float>(id, new Size(prd.Width, prd.Height), prd.CoordEnvelope.Clone()); iir.Put(resultNDVI); iir.Dispose(); } }
public override IExtractResult MakeExtProduct(IPixelIndexMapper piexd, Action <int, string> progressTracker) { if (piexd == null || this.Tag == null) { return(null); } IPixelFeatureMapper <Int16> resultTag = this.Tag as MemPixelFeatureMapper <Int16>; if (resultTag == null) { return(null); } //生成判识结果文件 IInterestedRaster <Int16> iir = null; IInterestedRaster <Int16> iirFIFLT = null; RasterIdentify id = new RasterIdentify(_argumentProvider.DataProvider.fileName); id.ThemeIdentify = "CMA"; id.ProductIdentify = "FIR"; id.SubProductIdentify = _identify; id.GenerateDateTime = DateTime.Now; iir = new InterestedRaster <Int16>(id, new Size(_argumentProvider.DataProvider.Width, _argumentProvider.DataProvider.Height), _argumentProvider.DataProvider.CoordEnvelope.Clone()); int[] idxs = piexd.Indexes.ToArray(); iir.Put(idxs, 1); id.SubProductIdentify = "FIFLT"; id.GenerateDateTime = DateTime.Now; iirFIFLT = new InterestedRaster <Int16>(id, new Size(_argumentProvider.DataProvider.Width, _argumentProvider.DataProvider.Height), _argumentProvider.DataProvider.CoordEnvelope.Clone()); iirFIFLT.Put(resultTag); List <RasterMaper> rms = new List <RasterMaper>(); IRasterDataProvider FIRLPrd = null; IRasterDataProvider FIFLTPrd = null; try { FIRLPrd = iir.HostDataProvider; RasterMaper fiflRm = new RasterMaper(FIRLPrd, new int[] { 1 }); rms.Add(fiflRm); FIFLTPrd = iirFIFLT.HostDataProvider; RasterMaper fifltRm = new RasterMaper(FIFLTPrd, new int[] { 1 }); rms.Add(fifltRm); string outFileName = GetFileName(new string[] { _argumentProvider.DataProvider.fileName }, _subProductDef.ProductDef.Identify, "FIFL", ".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.SetFeatureAOI(_argumentProvider.AOIs); rfr.RegisterCalcModel(new RasterCalcHandler <Int16, Int16>((rvInVistor, rvOutVistor, aoi) => { int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX; if (rvInVistor[0].RasterBandsData == null || rvInVistor[1].RasterBandsData == null || rvInVistor[0].RasterBandsData[0] == null || rvInVistor[1].RasterBandsData[0] == null) { return; } // if (_argumentProvider.AOIs == null) for (int index = 0; index < dataLength; index++) { if (rvInVistor[0].RasterBandsData[0][index] == 0) { rvOutVistor[0].RasterBandsData[0][index] = (Int16)0; } else { rvOutVistor[0].RasterBandsData[0][index] = rvInVistor[1].RasterBandsData[0][index]; } } //else if (_argumentProvider.AOIs != null && aoi != null && aoi.Length != 0) //{ // for (int i = 0; i < aoi.Length; i++) // if (rvInVistor[0].RasterBandsData[0][aoi[i]] == 0) // rvOutVistor[0].RasterBandsData[0][aoi[i]] = (Int16)0; // else // rvOutVistor[0].RasterBandsData[0][aoi[i]] = rvInVistor[1].RasterBandsData[0][aoi[i]]; //} })); //执行 rfr.Excute(); FileExtractResult res = new FileExtractResult("FIFL", outFileName, true); res.SetDispaly(false); return(res); } } finally { iir.Dispose(); if (File.Exists(iir.FileName)) { File.Delete(iir.FileName); } iirFIFLT.Dispose(); if (File.Exists(iirFIFLT.FileName)) { File.Delete(iirFIFLT.FileName); } } }
private static void DisplayPixelFeatureMapper(ISmartSession session, IMonitoringSubProduct subProduct, IExtractResult restult, bool openFile) { int extHeaderSize = 0; object header = null; GetExtHeader(subProduct, out extHeaderSize, out header); if (restult is IPixelFeatureMapper <float> ) { IPixelFeatureMapper <float> ifm = restult as IPixelFeatureMapper <float>; RasterIdentify rid = GetRasterIdentifyID(session); if (!string.IsNullOrEmpty(ifm.Name) && ifm.Name != rid.SubProductIdentify) { rid.SubProductIdentify = ifm.Name; } //文件已存在,并且使用感兴趣区域时,使用更新感兴趣区域值的方式。 IInterestedRaster <float> iir = new InterestedRaster <float>(rid, ifm.Size, ifm.CoordEnvelope, ifm.SpatialRef, extHeaderSize); subProduct.SetExtHeader(iir, header); iir.Put(ifm); iir.Dispose(); TryOrbitToWorkspace(session); //if (openFile && NeedOpenFile()) // TryOpenFile(session, iir.FileName); RecordFileForAfterProcess(iir.FileName); TrySaveFileToWorkspace(subProduct, session, iir.FileName, restult, null); } else if (restult is IPixelFeatureMapper <int> ) { IPixelFeatureMapper <int> ifm = restult as IPixelFeatureMapper <int>; RasterIdentify rid = GetRasterIdentifyID(session); IInterestedRaster <int> iir = new InterestedRaster <int>(rid, ifm.Size, ifm.CoordEnvelope, ifm.SpatialRef, extHeaderSize); iir.Put(ifm); iir.Dispose(); TryOrbitToWorkspace(session); if (openFile && NeedOpenFile()) { TryOpenFile(session, iir.FileName); } RecordFileForAfterProcess(iir.FileName); TrySaveFileToWorkspace(subProduct, session, iir.FileName, restult, null); } else if (restult is IPixelFeatureMapper <UInt16> ) { IPixelFeatureMapper <UInt16> ifm = restult as IPixelFeatureMapper <UInt16>; RasterIdentify rid = GetRasterIdentifyID(session); IInterestedRaster <UInt16> iir = new InterestedRaster <UInt16>(rid, ifm.Size, ifm.CoordEnvelope, ifm.SpatialRef, extHeaderSize); iir.Put(ifm); iir.Dispose(); TryOrbitToWorkspace(session); //if (openFile && NeedOpenFile()) // TryOpenFile(session, iir.FileName); RecordFileForAfterProcess(iir.FileName); TrySaveFileToWorkspace(subProduct, session, iir.FileName, restult, null); } else if (restult is IPixelFeatureMapper <Int16> ) { IPixelFeatureMapper <Int16> ifm = restult as IPixelFeatureMapper <Int16>; RasterIdentify rid = GetRasterIdentifyID(session); IInterestedRaster <Int16> iir = new InterestedRaster <Int16>(rid, ifm.Size, ifm.CoordEnvelope, ifm.SpatialRef, extHeaderSize); iir.Put(ifm); iir.Dispose(); TryOrbitToWorkspace(session); //if (openFile && NeedOpenFile()) // TryOpenFile(session, iir.FileName); RecordFileForAfterProcess(iir.FileName); TrySaveFileToWorkspace(subProduct, session, iir.FileName, restult, null); } ClearExtHeader(subProduct); }
public IExtractResult GetBAG() { double visiBandRoom = (double)_argumentProvider.GetArg("Visible_Zoom"); double niBandRoom = (double)_argumentProvider.GetArg("NearInfrared_Zoom"); bool needcloud = (bool)_argumentProvider.GetArg("isAppCloud"); UCSetNearTool uccontrl = _argumentProvider.GetArg("UCSetNearTool") as UCSetNearTool; if (uccontrl.ckbone.Checked) { uccontrl.btnGetAOIIndex(null, null); } MinNear = double.Parse(uccontrl.txtnearmin.Text) * 100;//放大调节 跟界面参数设置有关 IRasterDataProvider prd = _argumentProvider.DataProvider; if (prd == null) { PrintInfo("未能获取当前影像数据。"); return(null); } IBandNameRaster bandNameRaster = prd as IBandNameRaster; int visiBandNo = TryGetBandNo(bandNameRaster, "Visible"); int niBandNo = TryGetBandNo(bandNameRaster, "NearInfrared"); int shortBandNo = TryGetBandNo(bandNameRaster, "ShortInfrared"); if (visiBandNo == -1 || niBandNo == -1 || visiBandRoom == -1 || niBandRoom == -1) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } string express = string.Format("band{0}/{1}f" + " >= " + MinNear, niBandNo, niBandRoom); string cloudexpress = GetCloudExpress(); if (needcloud) { express = string.Format("{0} && ({1})", express, cloudexpress); } int[] bandNos = new int[] { visiBandNo, niBandNo, shortBandNo }; IThresholdExtracter <UInt16> extracter = new SimpleThresholdExtracter <UInt16>(); extracter.Reset(_argumentProvider, bandNos, express); int width = prd.Width; int height = prd.Height; IPixelIndexMapper memResult = PixelIndexMapperFactory.CreatePixelIndexMapper("BAG", width, height, prd.CoordEnvelope, prd.SpatialRef); extracter.Extract(memResult); memResult.Tag = new BagFeatureCollection("蓝藻辅助信息", GetDisplayInfo(memResult, visiBandNo, niBandNo)); //计算NDVI文件 IPixelFeatureMapper <float> ndvi = null; try { ndvi = ComputeNDVIResult(_argumentProvider.DataProvider, memResult, visiBandNo, niBandNo); IExtractResultBase bPCDResult = CreatPixelCoverRate(ndvi); ExtractResultArray results = new ExtractResultArray("BAG_BINS"); results.Add(memResult); //results.Add(ndvi); results.Add(bPCDResult); return(results); } finally { if (ndvi != null) { ndvi.Dispose(); } } }
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); }
public override IExtractResult Make(Action <int, string> progressTracker, IContextMessage contextMessage) { _contextMessage = contextMessage; if (_argumentProvider == null || _argumentProvider.DataProvider == null) { return(null); } string algname = _argumentProvider.GetArg("AlgorithmName").ToString(); if (algname == "BAGExtract_New") { //return GetBAG(); return(GetCloudBAG()); } if (!string.IsNullOrEmpty(algname)) { double visiBandRoom = (double)_argumentProvider.GetArg("Visible_Zoom"); double niBandRoom = (double)_argumentProvider.GetArg("NearInfrared_Zoom"); if (algname == "BAGExtract") { MinNDVI = (double)_argumentProvider.GetArg("NDVIMin"); MaxNDVI = (double)_argumentProvider.GetArg("NDVIMax"); } else if (algname == "BAGExtract_Test") { UCSetNDVITool uccontrl = _argumentProvider.GetArg("ucSetNDVITool") as UCSetNDVITool; if (uccontrl.ckbaoi.Checked) { uccontrl.btnGetAOIIndex(null, null); } else { MinNDVI = uccontrl.txtndvimin.Value; MaxNDVI = uccontrl.txtndvimax.Value; } } IRasterDataProvider prd = _argumentProvider.DataProvider; if (prd == null) { PrintInfo("未能获取当前影像数据。"); return(null); } IBandNameRaster bandNameRaster = prd as IBandNameRaster; int visiBandNo = TryGetBandNo(bandNameRaster, "Visible"); int niBandNo = TryGetBandNo(bandNameRaster, "NearInfrared"); if (visiBandNo == -1 || niBandNo == -1 || visiBandRoom == -1 || niBandRoom == -1) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } string express = string.Format(@"({0}==0||{1}==0 )? false :((float)(band{3}/{1}f - band{2}/{0}f) / (band{2}/{0}f+ band{3}/{1}f) < {5}) && ((float)(band{3} /{1}f- band{2}/{0}f) / (band{3}/{1}f + band{2}/{0}f) > {4})", visiBandRoom, niBandRoom, visiBandNo, niBandNo, MinNDVI, MaxNDVI); int[] bandNos = new int[] { visiBandNo, niBandNo }; IThresholdExtracter <UInt16> extracter = new SimpleThresholdExtracter <UInt16>(); extracter.Reset(_argumentProvider, bandNos, express); int width = prd.Width; int height = prd.Height; IPixelIndexMapper memResult = PixelIndexMapperFactory.CreatePixelIndexMapper("BAG", width, height, prd.CoordEnvelope, prd.SpatialRef); extracter.Extract(memResult); memResult.Tag = new BagFeatureCollection("蓝藻辅助信息", GetDisplayInfo(memResult, visiBandNo, niBandNo)); //计算NDVI文件 IPixelFeatureMapper <float> ndvi = null; try { ndvi = ComputeNDVIResult(_argumentProvider.DataProvider, memResult, visiBandNo, niBandNo); IExtractResultBase bPCDResult = CreatPixelCoverRate(ndvi); ExtractResultArray results = new ExtractResultArray("BAG_BINS"); results.Add(memResult); //results.Add(ndvi); results.Add(bPCDResult); return(results); } finally { if (ndvi != null) { ndvi.Dispose(); } } } else { PrintInfo("指定的算法\"" + algname + "\"没有实现。"); return(null); } }
private IExtractResult FIRFMack(Action <int, string> progressTracker) { IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster; int NearInfrared = TryGetBandNo(bandNameRaster, "NearInfrared"); int CoverageBand = (int)_argumentProvider.GetArg("CoverageBand"); double NearInfraredZoom = (double)_argumentProvider.GetArg("NearInfrared_Zoom"); double CoverageZoom = (double)_argumentProvider.GetArg("CoverageBand_Zoom"); float NearInfraredMax = (float)_argumentProvider.GetArg("NearInfraredMax"); float CoverageMin = (float)_argumentProvider.GetArg("CoverageMin"); float FIRLZoom = (float)_argumentProvider.GetArg("FIRFZoom"); if (NearInfrared == -1 || CoverageBand == -1) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } string coverageFile = _argumentProvider.GetArg("coverageFile") == null ? null : _argumentProvider.GetArg("coverageFile").ToString(); if (string.IsNullOrEmpty(coverageFile)) { PrintInfo("请设置背景农田百分比数据!"); return(null); } float maxAvgValue; float minAvgValue; string[] nearInfValues = _argumentProvider.GetArg("NearInfraredValues") as string[]; if (nearInfValues == null || nearInfValues.Count() != 2) { return(null); } if (!float.TryParse(nearInfValues[0], out maxAvgValue) || !float.TryParse(nearInfValues[1], out minAvgValue)) { return(null); } if (maxAvgValue == minAvgValue) { return(null); } float dltValue = maxAvgValue - minAvgValue; List <RasterMaper> rms = new List <RasterMaper>(); IRasterDataProvider curPrd = _argumentProvider.DataProvider; IRasterDataProvider coveragePrd = null; try { RasterMaper nearRm = new RasterMaper(curPrd, new int[] { NearInfrared }); rms.Add(nearRm); coveragePrd = RasterDataDriver.Open(coverageFile) as IRasterDataProvider; if (coveragePrd.BandCount < CoverageBand) { PrintInfo("请选择正确的农田百分比数据文件通道值!"); return(null); } RasterMaper coverageRm = new RasterMaper(coveragePrd, new int[] { CoverageBand }); rms.Add(coverageRm); string outFileName = GetFileName(new string[] { curPrd.fileName }, _subProductDef.ProductDef.Identify, _identify, ".dat", null); IPixelIndexMapper result = null; IPixelFeatureMapper <Int16> resultTag = null; int totalDatalength = 0; float tempValue = 0; using (IRasterDataProvider outRaster = CreateOutRaster(outFileName, rms.ToArray())) { result = PixelIndexMapperFactory.CreatePixelIndexMapper("FIR", outRaster.Width, outRaster.Height, outRaster.CoordEnvelope, outRaster.SpatialRef); if (this.Tag == null || (this.Tag as MemPixelFeatureMapper <Int16>) == null) { resultTag = new MemPixelFeatureMapper <Int16>("FIFLT", 1000, new Size(outRaster.Width, outRaster.Height), outRaster.CoordEnvelope, outRaster.SpatialRef); } else { resultTag = this.Tag as MemPixelFeatureMapper <Int16>; } RasterMaper[] fileIns = rms.ToArray(); RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) }; //创建处理模型 RasterProcessModel <Int16, Int16> rfr = null; rfr = new RasterProcessModel <Int16, Int16>(progressTracker); rfr.SetRaster(fileIns, fileOuts); rfr.SetFeatureAOI(_argumentProvider.AOIs); rfr.RegisterCalcModel(new RasterCalcHandlerFun <short, short>((rvInVistor, rvOutVistor, aoi) => { int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX; if (rvInVistor[0].RasterBandsData == null || rvInVistor[1].RasterBandsData == null || rvInVistor[0].RasterBandsData[0] == null || rvInVistor[1].RasterBandsData[0] == null) { totalDatalength += dataLength; return(false); } if (_argumentProvider.AOIs == null) { for (int index = 0; index < dataLength; index++) { if (IsFirA(rvInVistor, index, NearInfraredZoom, NearInfraredMax)) { result.Put(totalDatalength + index); tempValue = (maxAvgValue - rvInVistor[0].RasterBandsData[0][index]) / dltValue; if (tempValue < rvInVistor[1].RasterBandsData[0][index] / CoverageZoom) { resultTag.Put(totalDatalength + index, tempValue < 0 ? (Int16)0 : (tempValue > 1 ? (Int16)(FIRLZoom) : (Int16)(tempValue * FIRLZoom))); } else { resultTag.Put(totalDatalength + index, (Int16)(rvInVistor[1].RasterBandsData[0][index] / CoverageZoom * FIRLZoom)); } } } } else if (_argumentProvider.AOIs != null && aoi != null && aoi.Length != 0) { int indexFromAOI = 0; for (int i = 0; i < aoi.Length; i++) { indexFromAOI = aoi[i]; if (IsFirA(rvInVistor, indexFromAOI, NearInfraredZoom, NearInfraredMax)) { result.Put(totalDatalength + indexFromAOI); tempValue = (maxAvgValue - rvInVistor[0].RasterBandsData[0][aoi[i]]) / dltValue; if (tempValue < rvInVistor[1].RasterBandsData[0][aoi[i]] / CoverageZoom) { resultTag.Put(totalDatalength + indexFromAOI, tempValue < 0 ? (Int16)0 : (tempValue > 1 ? (Int16)(FIRLZoom) : (Int16)(tempValue * FIRLZoom))); } else { resultTag.Put(totalDatalength + indexFromAOI, (Int16)(rvInVistor[1].RasterBandsData[0][aoi[i]] / CoverageZoom * FIRLZoom)); } } } } totalDatalength += dataLength; return(false); })); //执行 rfr.Excute(); this.Tag = resultTag; return(result); } } finally { if (coveragePrd != null) { coveragePrd.Dispose(); } } }
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(); } } }
private void 沙尘能见度_Click(object sender, EventArgs e) { //首先进行沙尘判识,得出判识出的沙尘区域 string fname = @"E:\第二张盘\01_沙尘\2011年04月30日\FY3A_VIRRX_GBAL_L1_20110430_0305_1000M_MS_PRJ_DXX.LDF"; //Dictionary<string, object> args = new Dictionary<string, object>(); //args.Add("a", 28); //args.Add("b", 78); //args.Add("c", 245); //args.Add("d", 293); //args.Add("f", 0); //args.Add("g", 20); //args.Add("h", 15); //args.Add("i", 250); IRasterDataProvider prd = GeoDataDriver.Open(fname) as IRasterDataProvider; //ArgumentsProvider argprd = new ArgumentsProvider(prd, args); //string extractExpress = "((band2/10f) > var_a) && (band2/10f < var_b) && (band5/10f > var_c) && (band5/10f < var_d) && " // + "(band6/10f > var_a) && ((band6 - band2)>var_f) && ((band6/10f - band5/10f + var_i)>var_h)"; //band2:可见光,0.525~0.575(波长范围) //band5:远红外,10.3~11.55 //band6:短波红外,1.60~1.69 //int[] exBandNos = new int[] { 2, 5, 6 }; //IThresholdExtracter<UInt16> thrExtracter = new SimpleThresholdExtracter<UInt16>(); //thrExtracter.Reset(argprd, exBandNos, extractExpress); //extractResult = new MemPixelIndexMapper("SAND", 1000); //thrExtracter.Extract(extractResult); //idxs = extractResult.Indexes.ToArray(); //获取到判识结果 //将判识结果作为AOI传入进行能见度计算 string express = "(UInt16)Math.Round(1000 * Math.Pow(Math.E,(var_visibleA + var_visibleB * band1/10f + var_visibleC * band2/10f + var_visibleD * band6/10f + var_visibleE * band4/10f + var_visibleF *(band6/10f - band4/10f + var_shortFar))),0)"; //express = " 80 "; //string express = "1000*Math.Pow(Math.E,(44.7603 +0.181571 * band2/10f -0.332972 * band4/10f + 0.122736 * band6/10f -0.144287 * band5/10f -0.114465 *(band6/10f - band5/10f + 253)))"; Dictionary <string, object> args = new Dictionary <string, object>(); args.Add("visibleA", 44.7603); args.Add("visibleB", 0.181571); args.Add("visibleC", -0.332972); args.Add("visibleD", 0.122736); args.Add("visibleE", -0.144287); args.Add("visibleF", -0.114465); args.Add("shortFar", 253); int[] bandNos = new int[] { 1, 2, 6, 4 }; ArgumentProvider argProvider = new ArgumentProvider(prd, args); //argProvider.AOI = idxs; IRasterExtracter <UInt16, UInt16> extracter = new SimpleRasterExtracter <UInt16, UInt16>(); extracter.Reset(argProvider, bandNos, express); result = new MemPixelFeatureMapper <UInt16>("Visibility", 1000, new Size(prd.Width, prd.Height), prd.CoordEnvelope, prd.SpatialRef); Stopwatch sw = new Stopwatch(); sw.Start(); extracter.Extract(result); RasterIdentify id = new RasterIdentify(); id.ThemeIdentify = "CMA"; id.ProductIdentify = "SAND"; id.SubProductIdentify = "VISIBILITY"; id.Satellite = "FY3A"; id.Sensor = "VIRRX"; id.Resolution = "1000M"; id.OrbitDateTime = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0, 0)); id.GenerateDateTime = DateTime.Now; IInterestedRaster <UInt16> iir = new InterestedRaster <UInt16>(id, new Size(prd.Width, prd.Height), prd.CoordEnvelope.Clone()); iir.Put(result); iir.Dispose(); sw.Stop(); Text = sw.ElapsedMilliseconds.ToString(); }
private IPixelFeatureMapper <float> CreatPixelCoverRate(IPixelFeatureMapper <float> ndviResult) { if (ndviResult == null) { return(null); } //生成NDVI结果文件 IRasterDataProvider ndviDataProvider = null; IInterestedRaster <float> iir = null; try { RasterIdentify id = new RasterIdentify(); id.ThemeIdentify = "CMA"; id.ProductIdentify = "BAG"; id.SubProductIdentify = "BPCD"; id.Sensor = _argumentProvider.DataProvider.DataIdentify.Sensor; id.Satellite = _argumentProvider.DataProvider.DataIdentify.Satellite; id.OrbitDateTime = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0, 0)); id.GenerateDateTime = DateTime.Now; iir = new InterestedRaster <float>(id, new Size(_argumentProvider.DataProvider.Width, _argumentProvider.DataProvider.Height), _argumentProvider.DataProvider.CoordEnvelope.Clone()); iir.Put(ndviResult); ndviDataProvider = iir.HostDataProvider; double dst; dst = MaxNDVI - MinNDVI; //判断是否使用端元值计算 NDVISettingItem[] settings = _argumentProvider.GetArg("NDVISetting") as NDVISettingItem[]; if (settings != null) { ResetArgNDVIMaxMin(settings, ref MinNDVI, ref dst); } IPixelFeatureMapper <float> memresult = new MemPixelFeatureMapper <float>("BPCD", 1000, new Size(ndviDataProvider.Width, ndviDataProvider.Height), ndviDataProvider.CoordEnvelope, ndviDataProvider.SpatialRef); ArgumentProvider ap = new ArgumentProvider(ndviDataProvider, null); RasterPixelsVisitor <float> visitor = new RasterPixelsVisitor <float>(ap); visitor.VisitPixel(new int[] { 1 }, (index, values) => { if (values[0] == -9999f) { memresult.Put(index, -9999); } else if (dst == 0) { memresult.Put(index, -9999); } else { memresult.Put(index, (float)((values[0] - MinNDVI) / dst)); } }); iir.Dispose(); return(memresult); } finally { if (ndviDataProvider != null) { ndviDataProvider.Dispose(); } if (File.Exists(iir.FileName)) { File.Delete(iir.FileName); } } }