private unsafe void FillBand() { float[][] bandValues = new float[1][]; bandValues[0] = new float[_width * _height]; IArrayRasterDataProvider dataProvider = new ArrayRasterDataProvider <float>( _fileName, bandValues, _width, _height, _coordEnvelope, _spatialRef); float val; int row = _height - 1; float res = _resolutionX;//or _resolutionY float minX = (float)_coordEnvelope.MinX; float maxY = (float)_coordEnvelope.MaxY; _fs = new FileStream(_fileName, FileMode.Open, FileAccess.Read); _stReader = new StreamReader(_fs, Encoding.Default); fixed(float *ptr0 = bandValues[0]) { float *ptr = ptr0; while (!_stReader.EndOfStream) { string sLine = _stReader.ReadLine(); string[] parts = sLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < parts.Length; i++) { float.TryParse(parts[i], out val); ptr = ptr0 + row * _width + i; *ptr = val; } row--; } } _rasterBands.Add(dataProvider.GetRasterBand(1)); }
private unsafe void FillBand() { float[][] bandValues = new float[1][]; bandValues[0] = new float[_width * _height]; IArrayRasterDataProvider dataProvider = new ArrayRasterDataProvider <float>( _fileName, bandValues, _width, _height, _coordEnvelope, _spatialRef); float lon, lat, val; int col = 0, row = 0; float res = _resolutionX;//or _resolutionY float minX = (float)_coordEnvelope.MinX; float maxY = (float)_coordEnvelope.MaxY; _fs = new FileStream(_fileName, FileMode.Open, FileAccess.Read); _stReader = new StreamReader(_fs, Encoding.ASCII); fixed(float *ptr0 = bandValues[0]) { float *ptr = ptr0; while (!_stReader.EndOfStream) { string sLine = _stReader.ReadLine(); string[] parts = sLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); float.TryParse(parts[0], out lon); float.TryParse(parts[1], out lat); float.TryParse(parts[2], out val); lon -= 180; col = (int)((lon - minX) / _resolutionX); row = (int)((maxY - lat) / _resolutionY); ptr = ptr0 + row * _width + col; *ptr = val; } } _rasterBands.Add(dataProvider.GetRasterBand(1)); }
private IRasterDataProvider GetArrayDataProvider() { float[] bandValue1 = new float[] { 7.3f, 7.55f, 7.8f, 8.4f, 10.5f, 12.3f, 12.8f }; float[] bandValue2 = new float[] { 39.84f, 41.14f, 41.34f, 41.14f, 44, 51, 50.5f }; int width = 1; int height = 7; IRasterDataProvider prd = new ArrayRasterDataProvider <float>("统计数组", new float[][] { bandValue1, bandValue2 }, width, height); return(prd); }
public IExtractResult OutputLAI(IRasterDataProvider angleRaster, string L2LSRFile, bool isNeedPrj = true) { int outwidth = angleRaster.Width, outheight = angleRaster.Height; IRasterDataProvider mainRaster = null; try { #region 建立输出文件 RasterIdentify datid = new RasterIdentify(Path.GetFileName(L2LSRFile)); datid.ProductIdentify = "VGT"; datid.SubProductIdentify = "0LAI"; float outResolution = 0.01f; if (datid.Resolution == "1000M") { outResolution = 0.01f; } else if (datid.Resolution == "5000M") { outResolution = 0.05f; } string laiFileName = datid.ToWksFullFileName(".ldf"); FileExtractResult result = null; if (isNeedPrj) { mainRaster = new ArrayRasterDataProvider <UInt16>("Array", output, outwidth, outheight); HDF4FilePrjSettings setting = new HDF4FilePrjSettings(); setting.LocationFile = angleRaster; setting.OutFormat = "LDF"; setting.OutResolutionX = setting.OutResolutionY = outResolution; Dictionary <string, double> exargs = new Dictionary <string, double>(); exargs.Add("FillValue", laiFillVlue); setting.ExtArgs = new object[] { exargs }; HDF4FileProjector projector = new HDF4FileProjector(); GeoDo.RasterProject.PrjEnvelope mainPrj = null; projector.ComputeDstEnvelope(angleRaster, GeoDo.Project.SpatialReference.GetDefault(), out mainPrj, null); if (mainPrj != null) { setting.OutEnvelope = mainPrj; setting.OutPathAndFileName = laiFileName; projector.Project(mainRaster, setting, GeoDo.Project.SpatialReference.GetDefault(), null); if (_progressTracker != null) { _progressTracker(100, "LAI数据投影完成!"); } } else { return(null); } } else { if (!CreateRaster(laiFileName, 1, enumDataType.UInt16, angleRaster)) { return(null); } } string resultFile = Path.Combine(Path.GetDirectoryName(laiFileName), Path.GetFileNameWithoutExtension(laiFileName) + ".dat"); if (File.Exists(laiFileName)) { if (File.Exists(resultFile)) { File.Delete(resultFile); } File.Move(laiFileName, resultFile); result = new FileExtractResult("0LAI", resultFile, true); } else { result = new FileExtractResult("0LAI", laiFileName, true); } result.SetDispaly(true); return(result); #endregion } catch (System.Exception ex) { //_progressTracker(0, ex.Message); PrintInfo(ex.Message); return(null); } finally { if (mainRaster != null) { mainRaster.Dispose(); } } }
public List <string[]> SeriesStaticAOI(string[] filesL, int bandNumL, string[] fillvalueL, out Dictionary <DateTime, string> filedate, Action <int, string> progressCallback) { int[] aoiIndex; Size fileSize; int aoilength; int count = 0; IRasterDataProvider arrayPrd = null; List <string[]> resultList = new List <string[]>(); filedate = new Dictionary <DateTime, string>(); DateTime t = DateTime.MinValue; try { foreach (string file in filesL) { enumDataType datatype = enumDataType.Unknow; using (IRasterDataProvider dataPrd = GeoDataDriver.Open(file) as IRasterDataProvider) { datatype = dataPrd.DataType; fileSize = new Size(dataPrd.Width, dataPrd.Height); //创建AOI(基于数据的地理范围) aoiIndex = GetAOI(dataPrd.CoordEnvelope, _aoiContainer, fileSize); if (aoiIndex == null || aoiIndex.Length <= 0) { throw new ArgumentException("矢量AOI区域设置无效或范围不合法!"); } } aoilength = aoiIndex.Length; count = 0; arrayPrd = null; switch (datatype) { case enumDataType.Float: float[][] rasterbandsF = new float[1][]; { rasterbandsF[0] = GetHistArrayAOI <float>(new string[] { file }, bandNumL, fileSize.Width, fileSize.Height, datatype, aoiIndex, fillvalueL, out count); arrayPrd = new ArrayRasterDataProvider <float>("Array", rasterbandsF, aoilength, 1); } break; case enumDataType.Int16: short[][] rasterbandsS = new short[1][]; { rasterbandsS[0] = GetHistArrayAOI <short>(new string[] { file }, bandNumL, fileSize.Width, fileSize.Height, datatype, aoiIndex, fillvalueL, out count); arrayPrd = new ArrayRasterDataProvider <short>("Array", rasterbandsS, aoilength, 1); } break; case enumDataType.Byte: Byte[][] rasterbandsB = new Byte[1][]; { rasterbandsB[0] = GetHistArrayAOI <Byte>(new string[] { file }, bandNumL, fileSize.Width, fileSize.Height, datatype, aoiIndex, fillvalueL, out count); arrayPrd = new ArrayRasterDataProvider <Byte>("Array", rasterbandsB, aoilength, 1); } break; default: throw new ArgumentException("暂不支持" + datatype.ToString() + "类型的统计!"); } if (arrayPrd.Width == 0 || arrayPrd.Height == 0) { throw new ArgumentException("创建待统计数据失败!" + file); } double[] values; if (CloudParaFileStatics.ComputeMinMaxAvg(arrayPrd, datatype, new int[] { bandNumL }, null, out values, progressCallback)) { string date; GetFileTime(file, out date, out t); if (!filedate.ContainsKey(t)) { filedate.Add(t, date); } resultList.Add(new string[] { date, values[1].ToString("f2") }); if (progressCallback != null) { progressCallback(-1, Path.GetFileName(file) + "统计完成!"); } } } return(resultList); } finally { if (arrayPrd != null) { arrayPrd.Dispose(); } } }
public Dictionary <int, RasterQuickStatResult> FilesHistoStatAOI(string[] files, int[] bands, string[] fillValues, string min = null, string max = null, Action <int, string> progressCallback = null) { foreach (int b in bands) { if (!CheckFiles(files, b)) { throw new ArgumentException("输入文件错误!band" + b + "大小或类型不一致!"); } } if (StatRegionSet.UseVectorAOIRegion) { PrjEnvelope RegionEnv = StatRegionSet.AOIPrjEnvelope; _aoiContainer = StatRegionSet.AoiContainer; _VectorAOIName = StatRegionSet.AOIName; if (RegionEnv == null || RegionEnv.Height <= 0 || RegionEnv.Width <= 0) { throw new ArgumentException("矢量AOI区域设置无效或范围不合法!"); } } CoordEnvelope outerEnv = null; Size fileSize; enumDataType datatype = enumDataType.Unknow; using (IRasterDataProvider dataPrd = GeoDataDriver.Open(files[0]) as IRasterDataProvider) { datatype = dataPrd.DataType; outerEnv = dataPrd.CoordEnvelope; fileSize = new Size(dataPrd.Width, dataPrd.Height); } //创建AOI(基于数据的地理范围) int[] aoi = GetAOI(outerEnv, _aoiContainer, fileSize); if (aoi == null || aoi.Length <= 0) { throw new ArgumentException("矢量AOI区域设置无效或范围不合法!"); } if (progressCallback != null) { progressCallback(3, "开始读取波段数据..."); } int aoilength = aoi.Length; int count = 0; IRasterDataProvider arrayPrd = null; switch (datatype) { case enumDataType.Float: float[][] rasterbandsF = new float[bands.Max()][]; if (min != null && max != null) { foreach (int b in bands) { rasterbandsF[b - 1] = GetHistArrayBetweenAOI <float>(files, b, fileSize.Width, fileSize.Height, datatype, min, max, aoi, fillValues, out count); } arrayPrd = new ArrayRasterDataProvider <float>("Array", rasterbandsF, count, 1); } else { foreach (int b in bands) { rasterbandsF[b - 1] = GetHistArrayAOI <float>(files, b, fileSize.Width, fileSize.Height, datatype, aoi, fillValues, out count); } arrayPrd = new ArrayRasterDataProvider <float>("Array", rasterbandsF, aoilength, 1); } break; case enumDataType.Int16: short[][] rasterbandsS = new short[bands.Max()][]; if (min != null && max != null) { foreach (int b in bands) { rasterbandsS[b - 1] = GetHistArrayBetweenAOI <short>(files, b, fileSize.Width, fileSize.Height, datatype, min, max, aoi, fillValues, out count); } arrayPrd = new ArrayRasterDataProvider <short>("Array", rasterbandsS, count, 1); } else { foreach (int b in bands) { rasterbandsS[b - 1] = GetHistArrayAOI <short>(files, b, fileSize.Width, fileSize.Height, datatype, aoi, fillValues, out count); } arrayPrd = new ArrayRasterDataProvider <short>("Array", rasterbandsS, aoilength, 1); } break; case enumDataType.Byte: Byte[][] rasterbandsB = new Byte[bands.Max()][]; if (min != null && max != null) { foreach (int b in bands) { rasterbandsB[b - 1] = GetHistArrayBetweenAOI <Byte>(files, b, fileSize.Width, fileSize.Height, datatype, min, max, aoi, fillValues, out count); } arrayPrd = new ArrayRasterDataProvider <Byte>("Array", rasterbandsB, count, 1); } else { foreach (int b in bands) { rasterbandsB[b - 1] = GetHistArrayAOI <Byte>(files, b, fileSize.Width, fileSize.Height, datatype, aoi, fillValues, out count); } arrayPrd = new ArrayRasterDataProvider <Byte>("Array", rasterbandsB, aoilength, 1); } break; default: throw new ArgumentException("暂不支持" + datatype.ToString() + "类型的统计!"); } try { if (arrayPrd.Width == 0 || arrayPrd.Height == 0) { throw new ArgumentException("创建待统计数据失败!"); } if (progressCallback != null) { progressCallback(5, "开始统计波段数据..."); } return(DoStat(arrayPrd, bands, null, progressCallback)); } finally { if (arrayPrd != null) { arrayPrd.Dispose(); } } }