public void ApplyResult(IPixelIndexMapper dltResult) { if (dltResult == null) { return; } TryExtCursorInfoForFeaturesDisplay(dltResult); // IArgumentProvider argprd = _currentSubProduct.ArgumentProvider; string name = GetName(_currentProduct, _currentSubProduct); IPixelIndexMapper result = _resultObjects[name].BinaryValues; if (argprd != null && argprd.AOI != null) { result.Remove(argprd.AOI); foreach (int idx in dltResult.Indexes) { result.Put(idx); } } else { result.Reset(); foreach (int idx in dltResult.Indexes) { result.Put(idx); } } UpdateLayer(_resultObjects[name]); _isUpdated = true; }
private int[] MergeFirePoints(IPixelIndexMapper result, int[] firePoints, int[] filteredAOI) { int[] resultIndex = null; UpdateFirePoints(ref firePoints); if (firePoints == null) { resultIndex = filteredAOI; } else { if (filteredAOI == null) { result.Put(firePoints); resultIndex = firePoints; } else { List <int> firePointsArray = new List <int>(); firePointsArray.AddRange(firePoints); List <int> filteredAOIArray = new List <int>(); filteredAOIArray.AddRange(filteredAOI); resultIndex = firePointsArray.Union(filteredAOI).ToArray <int>(); result.Put(resultIndex); } } return(resultIndex); }
private unsafe void WriteResampledResult(Bitmap newBitmap, int offsetX, int offsetY, IPixelIndexMapper mapper, int[] aoi) { BitmapData pData = newBitmap.LockBits(new Rectangle(0, 0, newBitmap.Width, newBitmap.Height), ImageLockMode.ReadOnly, newBitmap.PixelFormat); List <int> indexies = new List <int>(); try { byte *ptr0 = (byte *)pData.Scan0; byte *ptr = ptr0; int stride = pData.Stride; int height = newBitmap.Height; int width = newBitmap.Width; int oWidth = mapper.Size.Width; int pixelWidth = 3; int curIndex = 0; for (int r = 0; r < height; r++, ptr = ptr0 + r * stride) { for (int c = 0; c < width; c++, ptr += pixelWidth) { if (*ptr == 255)//blue { curIndex = (r + offsetY) * oWidth + c + offsetX; indexies.Add(curIndex); } } } if (indexies.Count == 0) { return; } if (aoi == null) { mapper.Put(indexies.ToArray()); } else { mapper.Remove(aoi); var intersect = aoi.Intersect(indexies); if (intersect != null && intersect.Count() != 0) { mapper.Put(intersect.ToArray()); } } } finally { newBitmap.UnlockBits(pData); } }
private unsafe IPixelIndexMapper CreataPixelMapper(string currDBLV, out List <int> vertifyIndexiex) { IPixelIndexMapper dblvInfo = null; vertifyIndexiex = new List <int>(); using (IRasterDataProvider gd = GeoDataDriver.Open(currDBLV) as IRasterDataProvider) { string fiifFile = GetFirePointIndeiex.GetFireIndexiexFilename(currDBLV); dblvInfo = PixelIndexMapperFactory.CreatePixelIndexMapper("FIR", gd.Width, gd.Height, gd.CoordEnvelope, gd.SpatialRef); int[] indexiex = null; if (!string.IsNullOrEmpty(fiifFile)) { GetFirePointIndeiex.ReadFireIndexiexFilename(_argumentProvider, out indexiex); dblvInfo.Put(indexiex); } Int16[] dataBlock = new Int16[gd.Width * gd.Height]; IRasterBand band = gd.GetRasterBand(1); fixed(Int16 *buffer = dataBlock) { IntPtr ptr = new IntPtr(buffer); band.Read(0, 0, gd.Width, gd.Height, ptr, enumDataType.Int16, gd.Width, gd.Height); } int length = dataBlock.Length; if (string.IsNullOrEmpty(fiifFile)) { for (int i = 0; i < length; i++) { if (dataBlock[i] == (Int16)1) { dblvInfo.Put(i); vertifyIndexiex.Add(i); } } } else { for (int i = 0; i < length; i++) { if (dataBlock[i] == (Int16)1) { vertifyIndexiex.Add(i); } } } } return(dblvInfo); }
public unsafe IExtractResult Do(string productIdentify, string subProductIdentify, IRasterDataProvider dataProvider, string filename, out string error) { error = string.Empty; if (!CanDo(productIdentify, subProductIdentify, filename, out error)) { return(null); } if (_transDef == null) { _transDef = (new MVGXMLParser()).GetTransDef(); } ProductDef product = _transDef.GetProductBySmartProductIdentify(productIdentify); SubProductDef subProduct = product.GetSubProductBySmartIdentfy(subProductIdentify); IGeoDataProvider provider = GeoDataDriver.Open(filename, enumDataProviderAccess.ReadOnly, null); if (provider != null) { MvgDataProvider mvgProvider = provider as MvgDataProvider; if (mvgProvider == null) { error = "MVG转换尚不支持文件【" + Path.GetFileName(filename) + "】!"; return(null); } float xResolution = dataProvider.ResolutionX, mvgXResolution = (float)mvgProvider.CoordEnvelope.Width / mvgProvider.Width; float yResolution = dataProvider.ResolutionY, mvgYResolution = (float)mvgProvider.CoordEnvelope.Height / mvgProvider.Height; int width = dataProvider.Width, mvgWidth = mvgProvider.Width; double minX = dataProvider.CoordEnvelope.MinX, mvgMinX = mvgProvider.CoordEnvelope.MinX; double maxY = dataProvider.CoordEnvelope.MaxY, mvgMaxY = mvgProvider.CoordEnvelope.MaxY; int xIndex = 0; int yIndex = 0; if (dataProvider.DataType == enumDataType.UInt16) { Int16[] dataBlock = new Int16[mvgProvider.Width * mvgProvider.Height]; fixed(Int16 *buffer = dataBlock) { IntPtr ptr = new IntPtr(buffer); mvgProvider.Read(0, 0, mvgProvider.Width, mvgProvider.Height, ptr, enumDataType.Int16, mvgProvider.Width, mvgProvider.Height, 1, new int[] { 1 }, enumInterleave.BSQ); } Dictionary <Int16, Int16> dic = subProduct.GetTableDic <Int16, Int16>(); IPixelIndexMapper map = PixelIndexMapperFactory.CreatePixelIndexMapper(productIdentify + "_" + subProductIdentify, width, dataProvider.Height, dataProvider.CoordEnvelope, dataProvider.SpatialRef); RasterPixelsVisitor <UInt16> visitor = new RasterPixelsVisitor <UInt16>(new ArgumentProvider(dataProvider, null)); visitor.VisitPixel(new int[] { 1 }, (index, values) => { xIndex = (int)Math.Round((minX + (index % width * xResolution) - mvgMinX) / mvgXResolution); yIndex = (int)Math.Round((mvgMaxY - (maxY - (index / width * yResolution))) / mvgYResolution); if (xIndex >= 0 && yIndex >= 0 && yIndex * mvgWidth + xIndex < dataBlock.Length) { if (dic.ContainsKey(dataBlock[yIndex * mvgWidth + xIndex])) { map.Put(index); } } }); return(map); } } return(null); }
public void ApplyAdsorb(int[] aoi) { string name = GetName(_currentProduct, _currentSubProduct); IPixelIndexMapper result = _resultObjects[name].BinaryValues; result.Put(aoi); UpdateLayer(_resultObjects[name]); _isUpdated = true; }
public void Extract(IPixelIndexMapper extractedPixels) { if (_infoExtracter == null || _boolFunc == null) { return; } _infoExtracter.VisitPixel(_visitBandNos, (idx, values) => { if (_boolFunc(idx, values)) { extractedPixels.Put(idx); } }); }
//魔术棒 private void HandleAdsorb(object result) { GeometryOfDrawed geometry = result as GeometryOfDrawed; IRasterDataProvider prd = GetRasterDataProvider(_canvasViewer); using (IVectorAOIGenerator gen = new VectorAOIGenerator()) { int[] aoi = gen.GetAOI(geometry.RasterPoints.Clone() as PointF[], geometry.Types, new Size(prd.Width, prd.Height)); string name = GetName(_currentProduct, _currentSubProduct); IPixelIndexMapper mapper = _resultObjects[name].BinaryValues; mapper.Put(aoi); UpdateLayer(_resultObjects[name]); } }
private IExtractResult GenerateExtractResult(string gfrFile, IRasterDataProvider dataPrd) { IPixelIndexMapper result = PixelIndexMapperFactory.CreatePixelIndexMapper("FIR", dataPrd.Width, dataPrd.Height, dataPrd.CoordEnvelope, dataPrd.SpatialRef); Dataset _dataset = Gdal.Open(gfrFile, Access.GA_ReadOnly); if (_dataset.RasterCount == 0) { return(result); } else { CoordEnvelope envelope = dataPrd.CoordEnvelope.Clone(); double maxX = envelope.MaxX; double minX = envelope.MinX; double maxY = envelope.MaxY; double minY = envelope.MinY; using (IVectorFeatureDataReader dr = VectorDataReaderFactory.GetUniversalDataReader(gfrFile) as IVectorFeatureDataReader) { Feature[] features = dr.FetchFeatures(); for (int i = 0; i < features.Length; i++) { double x, y; if (double.TryParse(features[i].FieldValues[4], out x) && double.TryParse(features[i].FieldValues[3], out y)) { if (IsInRange(minX, maxX, x) && IsInRange(minY, maxY, y)) { int index = GetIndex(x, y); if (index >= result.Count) { break; } result.Put(index); } } } } return(result); } }
private void DoFilters(IArgumentProvider argProvider, out Dictionary <int, PixelFeature> features, Action <int, string> progressTracker) { features = null; ICandidatePixelFilter filter = null; int[] aoi = argProvider.AOI; Size size = new Size(argProvider.DataProvider.Width, argProvider.DataProvider.Height); Rectangle aoiRect = AOIHelper.ComputeAOIRect(aoi, size); int[] filteredAOI = null; if (progressTracker != null) { progressTracker.Invoke(5, "正在过滤高温象元,请稍候..."); } //4% 高温像元(中红外通道) CreateArgument.PrintInfo(_contextMessage, "[开始]x%高温像元过滤..."); filter = CreateArgument.CreateHighTmpXPercentFilter(argProvider, _contextMessage); if (filter == null) { return; } filteredAOI = filter.Filter(argProvider.DataProvider, aoiRect, aoi); //by chennan 20130402 感兴趣内计算 UpdateFilteredAOIByAOI(ref filteredAOI, argProvider.AOI); if (filteredAOI != null) { _waitingFirPixels.Put(filteredAOI); CreateArgument.PrintInfo(_contextMessage, " x%高温点个数:" + filteredAOI.Length.ToString()); } CreateArgument.PrintInfo(_contextMessage, "[完成]x%高温像元过滤。"); if (progressTracker != null) { progressTracker.Invoke(10, "正在提取陆地高温点,请稍候..."); } //陆地高温点判识 CreateArgument.PrintInfo(_contextMessage, "[开始]陆地高温点过滤..."); filter = CreateArgument.CreateLandHighTmpFilter(argProvider, _contextMessage); //by chennan 20130402 感兴趣内计算 UpdateFilteredAOIByAOI(ref filteredAOI, argProvider.AOI); if (filter != null) { aoiRect = AOIHelper.ComputeAOIRect(filteredAOI, size); filteredAOI = filter.Filter(argProvider.DataProvider, aoiRect, filteredAOI); if (filteredAOI != null) { _candidateFirPixels.Put(filteredAOI); _waitingFirPixels.Remove(filteredAOI); CreateArgument.PrintInfo(_contextMessage, " 陆地高温点个数:" + filteredAOI.Length.ToString() + ",候选像元个数:" + _candidateFirPixels.Indexes.Count().ToString()); } } CreateArgument.PrintInfo(_contextMessage, "[完成]陆地高温点过滤。"); if (progressTracker != null) { progressTracker.Invoke(20, "正在提取异常高温点,请稍候..."); } //异常高温点判识 CreateArgument.PrintInfo(_contextMessage, "[开始]邻域内异常高温点过滤..."); filter = CreateArgument.CreateAbnormalHighTmpFile(argProvider, _contextMessage); //by chennan 20130402 感兴趣内计算 UpdateFilteredAOIByAOI(ref filteredAOI, argProvider.AOI); if (filter != null) { filteredAOI = _waitingFirPixels.Indexes.ToArray(); aoiRect = AOIHelper.ComputeAOIRect(filteredAOI, size); filteredAOI = filter.Filter(argProvider.DataProvider, aoiRect, filteredAOI); //by chennan 20130402 感兴趣内计算 UpdateFilteredAOIByAOI(ref filteredAOI, argProvider.AOI); if (filteredAOI != null) { _candidateFirPixels.Put(filteredAOI); _waitingFirPixels.Remove(filteredAOI); CreateArgument.PrintInfo(_contextMessage, " 异常高温点个数:" + filteredAOI.Length.ToString() + ",候选像元个数:" + _candidateFirPixels.Indexes.Count().ToString()); } } CreateArgument.PrintInfo(_contextMessage, "[完成]邻域内异常高温点过滤。"); if (progressTracker != null) { progressTracker.Invoke(30, "正在提取疑似高温点,请稍候..."); } //疑似火点判识 CreateArgument.PrintInfo(_contextMessage, "[开始]疑似火点判识..."); DoubtFirPixelFilter doubtFilter = CreateArgument.CreateDoubtFilter(argProvider, _contextMessage); if (doubtFilter == null) { return; } filteredAOI = _candidateFirPixels.Indexes.ToArray(); aoiRect = AOIHelper.ComputeAOIRect(filteredAOI, size); filteredAOI = doubtFilter.Filter(argProvider, aoiRect, filteredAOI); //by chennan 20130402 感兴趣内计算 UpdateFilteredAOIByAOI(ref filteredAOI, argProvider.AOI); if (filteredAOI == null) { CreateArgument.PrintInfo(_contextMessage, " 没有监测出疑似火点"); _candidateFirPixels.Reset(); return; } _candidateFirPixels.Reset(); _candidateFirPixels.Put(filteredAOI); CreateArgument.PrintInfo(_contextMessage, "[完成]疑似火点判识。"); CreateArgument.PrintInfo(_contextMessage, " 监测出疑似火点:" + filteredAOI.Length.ToString()); if (progressTracker != null) { progressTracker.Invoke(50, "正在计算背景温度,请稍候..."); } //背景温度计算 CreateArgument.PrintInfo(_contextMessage, "[开始]背景亮温计算..."); BackTmpComputer backTmpComputer = CreateArgument.CreateBackTmpComputer(argProvider, doubtFilter as IBackTmpComputerHelper, _contextMessage); if (backTmpComputer == null) { return; } aoiRect = AOIHelper.ComputeAOIRect(filteredAOI, size); features = backTmpComputer.Compute(argProvider, aoiRect, filteredAOI); //记录火点特征集合 _candidateFirPixels.Tag = new FirFeatureCollection("火点像元特征", features); CreateArgument.PrintInfo(_contextMessage, " 为" + features.Count.ToString() + "个疑似火点计算了背景亮温"); CreateArgument.PrintInfo(_contextMessage, "[完成]背景亮温计算。"); if (progressTracker != null) { progressTracker.Invoke(70, "正在进行火点确认,请稍候..."); } //火点确认 CreateArgument.PrintInfo(_contextMessage, "[开始]火点确认..."); VertifyFirPixelFiter vertifyFilter = CreateArgument.CreateVertifyFilter(argProvider, _contextMessage); if (vertifyFilter == null) { return; } filteredAOI = vertifyFilter.Filter(argProvider, features); _candidateFirPixels.Reset(); if (filteredAOI != null && filteredAOI.Length > 0) { _candidateFirPixels.Put(filteredAOI); CreateArgument.PrintInfo(_contextMessage, " 确认火点数:" + filteredAOI.Length.ToString()); GetFirePointIndeiex.WriteFireIndexiexFilename(argProvider, features.Keys.ToArray()); } CreateArgument.PrintInfo(_contextMessage, "[完成]火点确认。"); }
private IPixelIndexMapper GenerateHistoryResultByAOI(IPixelIndexMapper pixelMapper, int[] drawedAOI) { if (drawedAOI == null || drawedAOI.Length < 1) { return(null); } if (lstFiles.Items.Count < 1) { return(null); } foreach (string file in lstFiles.Items) { if (!File.Exists(file)) { return(null); } } using (IRasterDataProvider prd = GeoDataDriver.Open(_currentRasterFile) as IRasterDataProvider) { List <int> aoiList = new List <int>(); aoiList.AddRange(drawedAOI); IPixelIndexMapper result = PixelIndexMapperFactory.CreatePixelIndexMapper("FLD", prd.Width, prd.Height, prd.CoordEnvelope, prd.SpatialRef); if (pixelMapper != null && pixelMapper.Indexes.Count() > 0) { foreach (int i in pixelMapper.Indexes) { if (aoiList.Contains(i)) { result.Put(i); } } } // IInterestedRaster <Int16> iir = null; try { RasterIdentify id = new RasterIdentify(); id.ThemeIdentify = "CMA"; id.ProductIdentify = "FLD"; id.SubProductIdentify = "DBLV"; iir = new InterestedRaster <Int16>(id, new Size(prd.Width, prd.Height), prd.CoordEnvelope.Clone()); int[] idxs = result.Indexes.ToArray(); iir.Put(idxs, 1); } finally { iir.Dispose(); } Dictionary <string, FilePrdMap> filePrdMap = new Dictionary <string, FilePrdMap>(); filePrdMap.Add("currentDBLV", new FilePrdMap(iir.FileName, 1, new VaildPra(Int16.MinValue, Int16.MaxValue), new int[] { 1 })); int index = 0; foreach (string file in lstFiles.Items) { filePrdMap.Add("dblv" + index, new FilePrdMap(file, 1, new VaildPra(Int16.MinValue, Int16.MaxValue), new int[] { 1 })); index++; } ITryCreateVirtualPrd tryVPrd = new TryCreateVirtualPrdByMultiFile(); IVirtualRasterDataProvider vrd = tryVPrd.CreateVirtualRasterPRD(ref filePrdMap); if (vrd == null) { if (filePrdMap != null && filePrdMap.Count > 0) { foreach (FilePrdMap value in filePrdMap.Values) { if (value.Prd != null) { value.Prd.Dispose(); } } } return(null); } try { ArgumentProvider ap = new ArgumentProvider(vrd, null); RasterPixelsVisitor <float> rpVisitor = new RasterPixelsVisitor <float>(ap); int historyCount = lstFiles.Items.Count; int[] bandNos = new int[historyCount + 1]; for (int i = 0; i < bandNos.Length; i++) { bandNos[i] = i + 1; } int[] difArray = new int[historyCount]; rpVisitor.VisitPixel(new Rectangle(0, 0, prd.Width, prd.Height), drawedAOI, bandNos, (idx, values) => { for (int i = 0; i < historyCount; i++) { if (values[0] != values[i + 1]) { difArray[i]++; } } }); int min = difArray[0], minIndex = 0; for (int i = 1; i < difArray.Length; i++) { if (min > difArray[i]) { min = difArray[i]; minIndex = i; } } rpVisitor.VisitPixel(bandNos, (idx, values) => { if (values[minIndex + 1] == 1) { if (!aoiList.Contains(idx)) { result.Put(idx); } } }); return(result); } finally { vrd.Dispose(); if (File.Exists(iir.FileName)) { File.Delete(iir.FileName); } } } }
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 IPixelIndexMapper GenerateHistoryResultByAOI(IPixelIndexMapper pixelMapper, string historyFile, int[] drawedAOI) { if (!File.Exists(historyFile) || drawedAOI == null || drawedAOI.Length < 1) { return(null); } IRasterDataProvider historyPrd = null; IRasterDataProvider prd = null; string outFileName = null; try { historyPrd = GeoDataDriver.Open(historyFile) as IRasterDataProvider; prd = GeoDataDriver.Open(_currentRasterFile) as IRasterDataProvider; IPixelIndexMapper result = PixelIndexMapperFactory.CreatePixelIndexMapper("FLD", prd.Width, prd.Height, prd.CoordEnvelope, prd.SpatialRef); if (pixelMapper != null && pixelMapper.Indexes.Count() > 0) { foreach (int i in pixelMapper.Indexes) { result.Put(i); } } List <RasterMaper> rms = new List <RasterMaper>(); RasterMaper rm = new RasterMaper(prd, new int[] { 1 }); RasterMaper oldRm = new RasterMaper(historyPrd, new int[] { 1 }); rms.AddRange(new RasterMaper[] { rm, oldRm }); using (IRasterDataProvider outRaster = GetTempOutRaster(historyFile, prd)) { //栅格数据映射 RasterMaper[] fileIns = rms.ToArray(); RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) }; //创建处理模型 RasterProcessModel <short, short> rfr = null; rfr = new RasterProcessModel <short, short>(null); rfr.SetRaster(fileIns, fileOuts); rfr.RegisterCalcModel(new RasterCalcHandler <short, short>((rvInVistor, rvOutVistor, aoi) => { int y = rvInVistor[0].IndexY * rvInVistor[0].Raster.Width; //修改aoi区域超出索引问题 int length = rvInVistor[1].RasterBandsData[0].Length; foreach (int i in drawedAOI) { //修改aoi区域超出索引问题 if (i < y || i - y >= length) { continue; } if (rvInVistor[1].RasterBandsData[0][i - y] == 1) { rvOutVistor[0].RasterBandsData[0][i - y] = 1; result.Put(i); } } })); rfr.Excute(); } return(result); } finally { if (historyPrd != null) { historyPrd.Dispose(); } if (prd != null) { prd.Dispose(); } if (File.Exists(outFileName)) { File.Delete(outFileName); } } }
public unsafe IExtractResult Do(string productIdentify, string subProductIdentify, IRasterDataProvider dataProvider, string filename, out string error) { error = string.Empty; if (!CanDo(productIdentify, subProductIdentify, filename, out error)) { return(null); } if (_transDef == null) { _transDef = (new DATXMLParser()).GetTransDef(); } ProductDef product = _transDef.GetProductBySmartProductIdentify(productIdentify); SubProductDef subProduct = product.GetSubProductBySmartIdentfy(subProductIdentify); IPixelIndexMapper map = null; RasterMaper[] fileIns = null; RasterMaper[] fileOuts = null; string outRasterFile = null; IRasterDataProvider dblvPrd = null; try { dblvPrd = GeoDataDriver.Open(filename) as IRasterDataProvider; Dictionary <Int16, Int16> dic = subProduct.GetTableDic <Int16, Int16>(); //创建临时与当前影像大小一致的Int16类型文件 int index = 0; using (IRasterDataProvider outRaster = GetTempRaster(dataProvider, "MEM", enumDataType.Int16)) { outRasterFile = outRaster.fileName; map = PixelIndexMapperFactory.CreatePixelIndexMapper(productIdentify + "_" + subProductIdentify, dataProvider.Width, dataProvider.Height, dataProvider.CoordEnvelope, dataProvider.SpatialRef); List <RasterMaper> rms = new List <RasterMaper>(); RasterMaper rm = new RasterMaper(dataProvider, new int[] { 1 }); RasterMaper oldRm = new RasterMaper(dblvPrd, new int[] { 1 }); rms.AddRange(new RasterMaper[] { rm, oldRm }); //栅格数据映射 fileIns = rms.ToArray(); fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) }; //创建处理模型 RasterProcessModel <Int16, Int16> rfr = new RasterProcessModel <Int16, Int16>(null); rfr.SetRaster(fileIns, fileOuts); rfr.RegisterCalcModel(new RasterCalcHandlerFun <Int16, Int16>((rvInVistor, rvOutVistor, aoi) => { if (rvInVistor[1].RasterBandsData[0] == null) { index += rvInVistor[0].RasterBandsData[0].Length; return(false); } else { for (int i = 0; i < rvInVistor[1].RasterBandsData[0].Length; i++) { if (dic.ContainsKey(rvInVistor[1].RasterBandsData[0][i])) { map.Put(index + i); } } index += rvInVistor[0].RasterBandsData[0].Length; return(true); } })); rfr.Excute(-1); } } finally { if (dblvPrd != null) { dblvPrd.Dispose(); } foreach (RasterMaper item in fileOuts) { if (item.Raster != null) { item.Raster.Dispose(); } } if (File.Exists(outRasterFile)) { File.Delete(outRasterFile); } } return(map.Indexes == null || map.Indexes.Count() == 0 ? null : map); }
public IExtractResult GetCloudBAG() { double niBandRoom = (double)_argumentProvider.GetArg("NearInfrared_Zoom"); bool needcloud = (bool)_argumentProvider.GetArg("isAppCloud"); UCSetNearTool uccontrl = _argumentProvider.GetArg("UCSetNearTool") as UCSetNearTool; if (uccontrl.ckbone.Checked) { uccontrl.btnGetAOIIndex(null, null); } string cloudfile = GetClmFile(_argumentProvider.DataProvider); bool isexistcloud = File.Exists(cloudfile); MinNear = double.Parse(uccontrl.txtnearmin.Text) * 100;//放大调节 跟界面参数设置有关 IRasterDataProvider prd = _argumentProvider.DataProvider; if (prd == null) { PrintInfo("未能获取当前影像数据。"); return(null); } IBandNameRaster bandNameRaster = prd as IBandNameRaster; int niBandNo = TryGetBandNo(bandNameRaster, "NearInfrared"); if (niBandNo == -1 || niBandRoom == -1) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } List <RasterMaper> rms = new List <RasterMaper>(); rms.Add(new RasterMaper(_argumentProvider.DataProvider, new int[] { niBandNo })); if (isexistcloud) { rms.Add(new RasterMaper(GeoDataDriver.Open(cloudfile) as IRasterDataProvider, new int[] { 1 })); } RasterIdentify rid = new RasterIdentify(_argumentProvider.DataProvider); rid.ProductIdentify = "BAG"; rid.SubProductIdentify = "DBLV"; string outfile = rid.ToPrjWksFullFileName(".dat"); IRasterDataProvider outRaster = null; outRaster = CreateOutRaster(outfile, rms.ToArray(), enumDataType.Int16); IPixelIndexMapper result = PixelIndexMapperFactory.CreatePixelIndexMapper("BAG", _argumentProvider.DataProvider.Width, _argumentProvider.DataProvider.Height, _argumentProvider.DataProvider.CoordEnvelope, _argumentProvider.DataProvider.SpatialRef); try { RasterProcessModel <Int16, Int16> rfr = null; RasterMaper[] fileIns = rms.ToArray(); RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) }; rfr = new RasterProcessModel <Int16, Int16>(); int totalindex = 0; rfr.SetRaster(fileIns, fileOuts); rfr.SetArgumentProviderAOI(_argumentProvider.AOI); rfr.RegisterCalcModel(new RasterCalcHandlerFun <Int16, Int16>((rvInVistor, rvOutVistor, aoi) => { if (rvInVistor[0].RasterBandsData[0] != null && rvInVistor[1].RasterBandsData[0] != null) { int dataLength = rvInVistor[0].SizeY * rvInVistor[0].SizeX; for (int i = 0; i < aoi.Length; i++) { int index = aoi[i]; if (rvInVistor[0].RasterBandsData[0][index] / niBandRoom > MinNear) { if (needcloud) { if (!isexistcloud) { result.Put(totalindex + index); continue; } else if (rvInVistor[1].RasterBandsData[0][index] == 0)//非云 { result.Put(totalindex + index); } else { //rvOutVistor[0].RasterBandsData[0][aoi[i]] = -9999;// 云 这里是否需要配置一下? } } else { result.Put(totalindex + index); //rvOutVistor[0].RasterBandsData[0][aoi[i]] = 1; } } else { } } totalindex = totalindex += dataLength; } return(false); })); rfr.Excute(); return(result); } catch (Exception ex) { return(null); } finally { outRaster.Dispose(); } }
private 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(); } } }