private string[] LdfOptions(FilePrjSettings prjSettings, ISpatialReference dstSpatial, float resolutionX, float resolutionY, DataIdentify dataIdentify) { List <string> options = new List <string>(); options.Add("INTERLEAVE=BSQ"); options.Add("VERSION=LDF"); options.Add("SPATIALREF=" + dstSpatial.ToProj4String()); options.Add("MAPINFO={" + 1 + "," + 1 + "}:{" + prjSettings.OutEnvelope.MinX + "," + prjSettings.OutEnvelope.MaxY + "}:{" + resolutionX + "," + resolutionY + "}"); options.Add("SENSOR=NOM"); if (dataIdentify != null) { string satellite = dataIdentify.Satellite; DateTime dt = dataIdentify.OrbitDateTime; bool asc = dataIdentify.IsAscOrbitDirection; if (!string.IsNullOrWhiteSpace(satellite)) { options.Add("SATELLITE=" + satellite); } if (dt != DateTime.MinValue && dt != DateTime.MaxValue) { options.Add("DATETIME=" + dt.ToString("yyyy/MM/dd HH:mm")); } } return(options.ToArray()); }
private IRasterBand[] GetDstRasterBand(IRasterDataProvider dstRaster, FilePrjSettings prjSettings, int beginBandIndex) { IRasterBand[] bands = new IRasterBand[prjSettings.OutBandNos.Length]; int[] bandNos = prjSettings.OutBandNos; for (int i = beginBandIndex; i < bandNos.Length + beginBandIndex; i++) { if (dstRaster is IBandNameRaster) { int newBand = -1; if ((dstRaster as IBandNameRaster).TryGetBandNoFromBandName(bandNos[i], out newBand)) { bands[i] = dstRaster.GetRasterBand(newBand); } else { bands[i] = dstRaster.GetRasterBand(bandNos[i]); } } else { bands[i] = dstRaster.GetRasterBand(bandNos[i]); } } return(bands); }
private IRasterDataProvider CreateOutFile(FilePrjSettings prjSettings, ISpatialReference dstSpatial, DataIdentify dataIdentify) { float resolutionX = prjSettings.OutResolutionX; float resolutionY = prjSettings.OutResolutionY; string[] options = null; string outformat = string.IsNullOrWhiteSpace(prjSettings.OutFormat) ? ".ldf" : prjSettings.OutFormat.ToLower(); string driver = ""; if (outformat == ".tif" || outformat == ".tiff") { driver = "GDAL"; options = new string[] { "DRIVERNAME=GTiff", "TFW=YES", "WKT=" + dstSpatial.ToWKTString(), "GEOTRANSFORM=" + string.Format("{0},{1},{2},{3},{4},{5}", prjSettings.OutEnvelope.MinX, resolutionX, 0, prjSettings.OutEnvelope.MaxY, 0, -resolutionY) }; } else { driver = "LDF"; options = LdfOptions(prjSettings, dstSpatial, resolutionX, resolutionY, dataIdentify); List <string> opts = new List <string>(options); opts.Add("BANDNAMES=" + BandNameString(prjSettings.OutBandNos)); options = opts.ToArray(); } Size outSize = prjSettings.OutEnvelope.GetSize(resolutionX, resolutionY); int bandCount = prjSettings.OutBandNos.Length; string filename = prjSettings.OutPathAndFileName; return(CreateOutFile(driver, filename, bandCount, outSize, enumDataType.Int16, options)); }
public override void Project(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, ISpatialReference dstSpatialRef, Action <int, string> progressCallback) { if (srcRaster == null) { throw new ArgumentNullException("srcRaster"); } if (prjSettings == null) { throw new ArgumentNullException("prjSettings"); } FY3_VIRR_PrjSettings fy3prjSettings = prjSettings as FY3_VIRR_PrjSettings; TryCreateDefaultArgs(srcRaster, fy3prjSettings, ref dstSpatialRef); DoSession(srcRaster, dstSpatialRef, fy3prjSettings, progressCallback); if (prjSettings.OutEnvelope == null || prjSettings.OutEnvelope == PrjEnvelope.Empty) { prjSettings.OutEnvelope = _maxPrjEnvelope; } //地理坐标投影,下面简单的对地理坐标投影的范围作了限制,不大严谨,仅适合目前的状况。 if (dstSpatialRef.ProjectionCoordSystem == null && (prjSettings.OutEnvelope.MaxY > 80 || prjSettings.OutEnvelope.MaxY < -80)) { throw new Exception(string.Format("高纬度数据,不适合投影为等经纬度数据[{0}]", _maxPrjEnvelope)); } Project(srcRaster, fy3prjSettings, dstSpatialRef, progressCallback); }
private void ReadExtArgs(FilePrjSettings prjSettings) { try { if (prjSettings.ExtArgs != null && prjSettings.ExtArgs.Length != 0) { foreach (object arg in prjSettings.ExtArgs) { if (arg is Dictionary <string, double> ) { Dictionary <string, double> exAtg = arg as Dictionary <string, double>; if (exAtg.ContainsKey("GeoSlope")) { _geoSlope = exAtg["GeoSlope"]; } if (exAtg.ContainsKey("GeoIntercept")) { _geoIntercept = exAtg["GeoIntercept"]; } } } } } catch { } }
/// <summary> /// 针对某些经纬度数据集,使用整型数据表达的数据提供支持 /// 如xzoom=0.0001,xzoom=0.0001 /// 需要在读取经度后,将其数据*0.0001还原为真实的经纬度值 /// </summary> /// <param name="prjSettings"></param> private void ReadExtArgs(FilePrjSettings prjSettings) { if (prjSettings.ExtArgs != null && prjSettings.ExtArgs.Length != 0) { foreach (object arg in prjSettings.ExtArgs) { if (arg is Dictionary <string, double> ) { Dictionary <string, double> exAtg = arg as Dictionary <string, double>; if (exAtg.ContainsKey("xzoom")) { _xzoom = exAtg["xzoom"]; } if (exAtg.ContainsKey("yzoom")) { _yzoom = exAtg["yzoom"]; } if (exAtg.ContainsKey("FillValue")) { _fillValue = exAtg["FillValue"]; } } } } }
public override void Project(RSS.Core.DF.IRasterDataProvider srcRaster, FilePrjSettings prjSettings, Project.ISpatialReference dstSpatialRef, Action <int, string> progressCallback) { try { ReadyArgs(srcRaster, prjSettings, dstSpatialRef, progressCallback); IRasterDataProvider outwriter = null; try { Size outSize = _prjSettings.OutSize; string[] options = new string[] { "INTERLEAVE=BSQ", "VERSION=LDF", "WITHHDR=TRUE", "SPATIALREF=" + _dstSpatialRef.ToProj4String(), "MAPINFO={" + 1 + "," + 1 + "}:{" + _prjSettings.OutEnvelope.MinX + "," + _prjSettings.OutEnvelope.MaxY + "}:{" + _outResolutionX + "," + _outResolutionY + "}" }; outwriter = CreateOutFile(_outfilename, _dstBandCount, outSize, srcRaster.DataType, options); //ReadyAngleFiles(_angleDataProvider, _outfilename, _prjSettings, outSize, options); ProjectRaster(srcRaster, outwriter, 0, progressCallback); } catch (IOException ex) { if (ex.Message == "磁盘空间不足。\r\n" && File.Exists(_outfilename)) { File.Delete(_outfilename); } throw ex; } finally { if (outwriter != null) { outwriter.Dispose(); outwriter = null; } } } catch { EndSession(); TryDeleteCurCatch(); throw; } finally { if (_curSession == null) { EndSession(); if (prjSettings.IsClearPrjCache) { TryDeleteCurCatch(); } } } }
public override void Project(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, ISpatialReference dstSpatialRef, Action <int, string> progressCallback) { if (srcRaster == null) { throw new ArgumentNullException("srcRaster"); } if (prjSettings == null) { throw new ArgumentNullException("prjSettings"); } EOS_MODIS_PrjSettings eosPrjSettings = prjSettings as EOS_MODIS_PrjSettings; if (eosPrjSettings.LocationFile == null) { throw new ArgumentNullException("prjSettings.LocationFile", "EOS投影未设置经纬度坐标(MOD03.hdf)文件"); } if (progressCallback != null) { progressCallback(0, "准备相关参数"); } string fileType = CheckFile(srcRaster); switch (fileType) { case "1000": TryCreateDefaultArgsKM(srcRaster, eosPrjSettings, ref dstSpatialRef); DoSession(srcRaster, dstSpatialRef, eosPrjSettings, progressCallback); if (prjSettings.OutEnvelope == null || prjSettings.OutEnvelope == PrjEnvelope.Empty) { prjSettings.OutEnvelope = _maxPrjEnvelope; } Project(srcRaster, eosPrjSettings, dstSpatialRef, progressCallback); break; case "0500": TryCreateDefaultArgsHKM(srcRaster, eosPrjSettings, ref dstSpatialRef); DoSession(srcRaster, dstSpatialRef, eosPrjSettings, progressCallback); if (prjSettings.OutEnvelope == null || prjSettings.OutEnvelope == PrjEnvelope.Empty) { prjSettings.OutEnvelope = _maxPrjEnvelope; } Project0500(srcRaster, _locationSize, eosPrjSettings, dstSpatialRef, progressCallback); break; case "0250": TryCreateDefaultArgsQKM(srcRaster, eosPrjSettings, ref dstSpatialRef); break; default: throw new NotSupportedException("不能识别该投影文件为受支持的EOS轨道数据" + srcRaster.fileName); } }
private void ReadySession(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, ISpatialReference dstSpatialRef, Action <int, string> progressCallback) { if (_curSession == null || _curSession != srcRaster || _isBeginSession) { Size srcSize = new Size(srcRaster.Width, srcRaster.Height); if (progressCallback != null) { progressCallback(_readyProgress++, "投影准备"); } _rasterDataBands = TryCreateRasterDataBands(srcRaster, prjSettings, progressCallback); _isBeginSession = false; } }
/// <summary> /// 投影主要方法 /// </summary> /// <param name="srcRaster"></param> /// <param name="prjSettings"></param> /// <param name="dstSpatialRef"></param> /// <param name="progressCallback"></param> /// <param name="dataSets"></param> /// <param name="hdf5attrs"></param> /// <param name="outfilename"></param> public void ProjectNew(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, ISpatialReference dstSpatialRef, Action <int, string> progressCallback, Dictionary <string, H5T.H5Type> dataSets) { ISpatialReference srcSpatialRef = srcRaster.SpatialRef; _projectionTransform = ProjectionTransformFactory.GetProjectionTransform(srcSpatialRef, dstSpatialRef); ArgsCheck(srcRaster, prjSettings, dstSpatialRef); ReadySession(srcRaster, prjSettings, dstSpatialRef, progressCallback); if (prjSettings.OutEnvelope == null || prjSettings.OutEnvelope == PrjEnvelope.Empty) { PrjEnvelope dstEnvelope = null; float srcResolutionX = srcRaster.ResolutionX; float srcResolutionY = srcRaster.ResolutionY; double srcLeftTopX = srcRaster.CoordEnvelope.MinX; double srcLeftTopY = srcRaster.CoordEnvelope.MaxY; int srcWidth = srcRaster.Width; int srcHeight = srcRaster.Height; Size srcSize = new Size(srcWidth, srcHeight); int wSample = 1; int hSample = 1; if (srcWidth > 1000) { wSample = srcWidth / 1000; } if (srcHeight > 1000) { hSample = srcHeight / 1000; } double[] xs = new double[(srcWidth / wSample) * (srcHeight / hSample)]; double[] ys = new double[(srcWidth / wSample) * (srcHeight / hSample)]; int index = 0;//非真实的索引号,采样后的 for (int rowInx = 0; rowInx <= (srcHeight - hSample); rowInx += hSample) { for (int colInx = 0; colInx <= (srcWidth - wSample); colInx += wSample) { xs[index] = srcLeftTopX + colInx * srcResolutionX; ys[index] = srcLeftTopY - rowInx * srcResolutionY; index++; } } _rasterProjector.ComputeDstEnvelope(srcSpatialRef, xs, ys, srcSize, dstSpatialRef, out dstEnvelope, null); prjSettings.OutEnvelope = dstEnvelope; } GC.Collect(); ProjectRaster(srcRaster, prjSettings, progressCallback, dataSets); }
private IRasterDataProvider CreateOutFile(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, ISpatialReference dstSpatial, enumDataType dataType) { float resolutionX = prjSettings.OutResolutionX; float resolutionY = prjSettings.OutResolutionY; string[] options = null; string outformat = string.IsNullOrWhiteSpace(prjSettings.OutFormat) ? "LDF" : prjSettings.OutFormat.ToUpper(); string driver = ""; if (outformat == "TIFF") { driver = "GDAL"; options = new string[] { "DRIVERNAME=GTiff", "TFW=YES", "WKT=" + dstSpatial.ToWKTString(), "GEOTRANSFORM=" + string.Format("{0},{1},{2},{3},{4},{5}", prjSettings.OutEnvelope.MinX, resolutionX, 0, prjSettings.OutEnvelope.MaxY, 0, -resolutionY) }; } else if (outformat == "MEM") { driver = "MEM"; options = new string[] { "INTERLEAVE=BSQ", "VERSION=MEM", "WITHHDR=TRUE", "SPATIALREF=" + dstSpatial.ToProj4String(), "MAPINFO={" + 1 + "," + 1 + "}:{" + prjSettings.OutEnvelope.MinX + "," + prjSettings.OutEnvelope.MaxY + "}:{" + resolutionX + "," + resolutionY + "}" }; } else { driver = "LDF"; options = new string[] { "INTERLEAVE=BSQ", "VERSION=LDF", "SPATIALREF=" + dstSpatial.ToProj4String(), "MAPINFO={" + 1 + "," + 1 + "}:{" + prjSettings.OutEnvelope.MinX + "," + prjSettings.OutEnvelope.MaxY + "}:{" + resolutionX + "," + resolutionY + "}", "BANDNAMES=" + BandNameString(srcRaster, prjSettings.OutBandNos) }; } Size outSize = prjSettings.OutEnvelope.GetSize(resolutionX, resolutionY); int bandCount = prjSettings.OutBandNos.Length; string filename = prjSettings.OutPathAndFileName; return(CreateOutFile(driver, filename, bandCount, outSize, dataType, options)); }
private FY3L2L3FilePrjSettings ArgsCheck(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, Action <int, string> progressCallback) { if (srcRaster == null) { throw new ArgumentNullException("srcRaster", "待投影数据为空"); } if (prjSettings == null) { throw new ArgumentNullException("prjSettings", "投影参数为空"); } FY3L2L3FilePrjSettings _prjSettings = prjSettings as FY3L2L3FilePrjSettings; if (_prjSettings.LocationFile == null) { throw new ArgumentNullException("prjSettings.LocationFile", "L2L3级轨道数据投影未设置经纬度数据集文件"); } return(_prjSettings); }
///针对FY2E,投影波段,设置为1,2,3,4,5[NOMChannelVIS],6[NOMCloudClassification] private IRasterBand[] GetSrcRasterBand(IRasterDataProvider srcRaster, FilePrjSettings prjSettings) { IRasterBand[] bands = new IRasterBand[prjSettings.OutBandNos.Length]; int[] bandNos = prjSettings.OutBandNos; if (bandNos.Length == 1 && bandNos[0] == 5) { IRasterBand[] bs = srcRaster.BandProvider.GetBands("NOMChannelVIS1KM"); if (bs != null) { bands[0] = bs[0]; bands[0].BandNo = 5; _srcImgResolution = 0.01f; } } else { for (int i = 0; i < bandNos.Length; i++) { if (bandNos[i] <= 4) { bands[i] = srcRaster.GetRasterBand(bandNos[i]); } else if (bandNos[i] == 5) { IRasterBand[] bs = srcRaster.BandProvider.GetBands("NOMChannelVIS1KM"); if (bs != null) { bands[i] = bs[0]; bands[i].BandNo = 5; } } else if (bandNos[i] == 6) { IRasterBand[] bs = srcRaster.BandProvider.GetBands("NOMCloudClassification"); if (bs != null) { bands[i] = bs[0]; bands[i].BandNo = 6; } } } } return(bands); }
public override IRasterDataProvider Project(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, IRasterDataProvider dstRaster, int beginBandIndex, Action <int, string> progressCallback) { try { ReadyArgs(srcRaster, prjSettings, dstRaster.SpatialRef, progressCallback); string[] angleOptions = LdfOptions(prjSettings, dstRaster.SpatialRef, _outResolutionX, _outResolutionY, srcRaster.DataIdentify); ReadyAngleFiles(srcRaster, _outfilename, prjSettings, _dstSize, angleOptions); ProjectToLDF(srcRaster, dstRaster, beginBandIndex, progressCallback); return(dstRaster); } catch (IOException ex) { if (ex.Message == "磁盘空间不足。\r\n" && File.Exists(_outfilename)) { File.Delete(_outfilename); } TryDeleteCurCatch(); throw ex; } catch { EndSession(); TryDeleteCurCatch(); throw; } finally { if (dstRaster != null) { dstRaster.Dispose(); dstRaster = null; } EndSession(); if (prjSettings.IsClearPrjCache) { TryDeleteCurCatch(); } } }
public override IRasterDataProvider Project(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, IRasterDataProvider dstRaster, int beginBandIndex, Action <int, string> progressCallback) { return(base.Project(srcRaster, prjSettings, dstRaster, beginBandIndex, progressCallback)); }
private IRasterBand[] TryCreateRasterDataBands(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, Action <int, string> progressCallback) { List <IRasterBand> rasterBands = new List <IRasterBand>(); for (int i = 0; i < prjSettings.OutBandNos.Length; i++) { if (progressCallback != null) { progressCallback(_readyProgress++, "投影准备"); } int bandNo = prjSettings.OutBandNos[i]; IRasterBand band = srcRaster.GetRasterBand(bandNo); rasterBands.Add(band); } return(rasterBands.ToArray()); }
private void ArgsCheck(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, ISpatialReference dstSpatialRef) { if (srcRaster == null) { throw new ArgumentNullException("srcRaster"); } if (prjSettings == null) { throw new ArgumentNullException("prjSettings"); } if (dstSpatialRef == null) { throw new ArgumentNullException("dstSpatialRef"); } if (srcRaster.SpatialRef == null) { throw new ArgumentNullException("srcRaster.SpatialRef"); } if (string.IsNullOrWhiteSpace(prjSettings.OutFormat)) { if (srcRaster.Driver.Name == "MEM") { prjSettings.OutFormat = "MEM"; } //else if (srcRaster.Driver.Name == "GDAL") //{ //} else { prjSettings.OutFormat = "LDF"; } } if (prjSettings.OutResolutionX == 0f || prjSettings.OutResolutionY == 0f) { if ((dstSpatialRef.ProjectionCoordSystem == null && srcRaster.SpatialRef.ProjectionCoordSystem == null) || (dstSpatialRef.ProjectionCoordSystem != null && srcRaster.SpatialRef.ProjectionCoordSystem != null)) { prjSettings.OutResolutionX = srcRaster.ResolutionX; prjSettings.OutResolutionY = srcRaster.ResolutionY; } else if (dstSpatialRef.ProjectionCoordSystem != null && srcRaster.SpatialRef.ProjectionCoordSystem == null) { prjSettings.OutResolutionX = srcRaster.ResolutionX * 100000F; prjSettings.OutResolutionY = srcRaster.ResolutionY * 100000F; } else if (dstSpatialRef.ProjectionCoordSystem == null && srcRaster.SpatialRef.ProjectionCoordSystem != null) { prjSettings.OutResolutionX = srcRaster.ResolutionX / 100000F; prjSettings.OutResolutionY = srcRaster.ResolutionY / 100000F; } } if (prjSettings.OutBandNos == null || prjSettings.OutBandNos.Length == 0) { List <int> bandNoList = new List <int>(); for (int i = 1; i <= srcRaster.BandCount; i++) { bandNoList.Add(i); } prjSettings.OutBandNos = bandNoList.ToArray(); } }
public void RastAndProject <T>(Size outSize, H5T.H5Type ht5type, H5FileId fileId, string dataset, Action <int, string> progressCallback, int outWidth, int outHeight, int rowStep, IRasterDataProvider srcRaster, FilePrjSettings prjSettings, int bandnum, T fillValue, HDF5.Hdf5Operator ope) { T[,] data = new T[outSize.Height, outSize.Width]; // 定义数据集操作部分 long[] dims = new long[2]; dims[0] = Convert.ToInt64(outSize.Height); dims[1] = Convert.ToInt64(outSize.Width); H5DataSpaceId dspaceId = H5S.create_simple(2, dims); // Define datatype for the data in the file. H5DataTypeId dtypeId = H5T.copy(ht5type); // Create the data set DATASETNAME. H5DataSetId dsetId = H5D.create(fileId, dataset, dtypeId, dspaceId); for (int oRow = 0; oRow < outHeight; oRow += rowStep) { #region 分块读取数据集 if (progressCallback != null) { percent++; progress = percent * 100 / progressCount; progressCallback(progress, string.Format("投影完成{0}%", progress)); } if (oRow + rowStep > outHeight) { rowStep = outHeight - oRow; } Size outStepSize = new Size(outWidth, rowStep); double[] xs = new double[outWidth * rowStep]; double[] ys = new double[outWidth * rowStep]; double oY = oRow * prjSettings.OutResolutionY; Parallel.For(0, rowStep, j => { double x; double y; int index; y = prjSettings.OutEnvelope.LeftTop.Y - j * prjSettings.OutResolutionY - oY; for (int i = 0; i < outWidth; i++) { x = prjSettings.OutEnvelope.LeftTop.Y + i * prjSettings.OutResolutionX; index = i + j * outWidth; xs[index] = x; ys[index] = y; } }); _projectionTransform.InverTransform(xs, ys); PrjEnvelope tEnvelope = PrjEnvelope.GetEnvelope(xs, ys, null); tEnvelope.Extend(srcRaster.ResolutionX, srcRaster.ResolutionY * 4); PrjEnvelope srcEnvelope = new PrjEnvelope(srcRaster.CoordEnvelope.MinX, srcRaster.CoordEnvelope.MaxX, srcRaster.CoordEnvelope.MinY, srcRaster.CoordEnvelope.MaxY); tEnvelope = PrjEnvelope.Intersect(tEnvelope, srcEnvelope); if (tEnvelope == null || tEnvelope.IsEmpty) { continue; } Size tSize = tEnvelope.GetSize(srcRaster.ResolutionX, srcRaster.ResolutionY); int tBeginRow = -1, tEndRow = -1, tBeginCol = -1, tEndCol = -1; int oBeginRow = -1, oEndRow = -1, oBeginCol = -1, oEndCol = -1; PrjBlockHelper.ComputeBeginEndRowCol(srcEnvelope, new Size(srcRaster.Width, srcRaster.Height), tEnvelope, tSize, ref oBeginRow, ref oBeginCol, ref oEndRow, ref oEndCol, ref tBeginRow, ref tBeginCol, ref tEndRow, ref tEndCol); int srcStepWidth = oEndCol - oBeginCol; int srcStepHeight = oEndRow - oBeginRow; Size srcStepSize = new Size(srcStepWidth, srcStepHeight); T[] srcBandData = new T[srcStepWidth * srcStepHeight]; T[] dstBandData = new T[outWidth * rowStep]; double srcStepLeftTopX = tEnvelope.MinX; double srcStepLeftTopY = tEnvelope.MaxY; double srcStepRightBottomX = tEnvelope.MaxX; double srcStepRightBottomY = tEnvelope.MinY; UInt16[] rows = new UInt16[outWidth * rowStep]; //正向查找表 UInt16[] cols = new UInt16[outWidth * rowStep]; //正向查找表 if (progressCallback != null) { percent++; progress = percent * 100 / progressCount; progressCallback(progress, string.Format("投影完成{0}%", progress)); } Parallel.For(0, rowStep, j => { double x; double y; int index; for (int i = 0; i < outWidth; i++) { index = i + j * outWidth; x = xs[index]; y = ys[index]; if (x >= srcStepLeftTopX && x <= srcStepRightBottomX && y <= srcStepLeftTopY && y >= srcStepRightBottomY) { cols[index] = (UInt16)((x - srcStepLeftTopX) / srcRaster.ResolutionX + 0.5); rows[index] = (UInt16)((srcStepLeftTopY - y) / srcRaster.ResolutionY + 0.5); } } }); xs = null; ys = null; #endregion //分块读取不同波段数据 ReadBandData <T>(srcBandData, bandnum, oBeginCol, oBeginRow, srcStepWidth, srcStepHeight, GetSysDataType(ht5type)); //投影不同分块的数据集 _rasterProjector.Project <T>(srcBandData, srcStepSize, rows, cols, outStepSize, dstBandData, fillValue, 0, null); for (int i = 0; i < outStepSize.Width; i++) { for (int j = 0; j < outStepSize.Height; j++) { int index = j * outStepSize.Width + i; data[j + oRow, i] = dstBandData[index]; } } rows = null; rows = null; srcBandData = null; dstBandData = null; } H5D.write(dsetId, dtypeId, new H5Array <T>(data)); //写数据集属性 //Dictionary<string, string> dsetkeyvalue = ope.GetAttributes(dataset); //foreach (string key in dsetkeyvalue.Keys) //{ // string value = dsetkeyvalue[key]; // HDFAttributeDef attrdef = new HDFAttributeDef(key, typeof(string), dsetkeyvalue[key].Length, value); // WriteHdfAttributes.WriteHdfAttribute(dsetId, attrdef); //} H5D.close(dsetId); }
/// <summary> /// 投影 /// </summary> /// <param name="srcRaster"></param> /// <param name="prjSettings"></param> /// <param name="dstRaster"></param> /// <param name="beginBandIndex"></param> /// <param name="progressCallback"></param> /// <returns></returns> public override IRasterDataProvider Project(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, RSS.Core.DF.IRasterDataProvider dstRaster, int beginBandIndex, Action <int, string> progressCallback) { if (dstRaster == null) { return(null); } try { _dstSpatialRef = dstRaster.SpatialRef; CoordEnvelope coordEnv = dstRaster.CoordEnvelope; prjSettings.OutEnvelope = PrjEnvelope.CreateByLeftTop(coordEnv.MinX, coordEnv.MaxY, coordEnv.Width, coordEnv.Height); ReadyArgs(srcRaster, prjSettings, dstRaster.SpatialRef, progressCallback); string outfilename = _prjSettings.OutPathAndFileName; try { Size outSize = new Size(dstRaster.Width, dstRaster.Height); string[] options = new string[] { "INTERLEAVE=BSQ", "VERSION=LDF", "WITHHDR=TRUE", "SPATIALREF=" + _dstSpatialRef.ToProj4String(), "MAPINFO={" + 1 + "," + 1 + "}:{" + _prjSettings.OutEnvelope.MinX + "," + _prjSettings.OutEnvelope.MaxY + "}:{" + dstRaster.ResolutionX + "," + dstRaster.ResolutionY + "}" , "BANDNAMES=" + BandNameString(_prjSettings.OutBandNos) }; //ReadyAngleFiles(_angleDataProvider, outfilename, _prjSettings, outSize, options); ProjectRaster(srcRaster, dstRaster, beginBandIndex, progressCallback); return(dstRaster); } catch (IOException ex) { if (ex.Message == "磁盘空间不足。\r\n" && File.Exists(outfilename)) { File.Delete(outfilename); } throw ex; } finally { if (dstRaster != null) { dstRaster.Dispose(); dstRaster = null; } } } catch { EndSession(); TryDeleteCurCatch(); throw; } finally { if (_curSession == null) { EndSession(); if (prjSettings.IsClearPrjCache) { TryDeleteCurCatch(); } } } }
/// <summary> /// 投影操作-重载方法 /// </summary> /// <typeparam name="T">传递的数据集数据类型</typeparam> /// <param name="srcRaster">原始的数据驱动</param> /// <param name="prjSettings">投影设置类对象</param> /// <param name="progressCallback">回调</param> /// <param name="outhdf5name">导出的hdf5</param> /// <param name="fillValue">填充值?</param> private void ProjectRaster(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, Action <int, string> progressCallback, Dictionary <string, H5T.H5Type> dataSets) { enumDataType dataType = enumDataType.UInt16; PrjEnvelope outEnvelope = prjSettings.OutEnvelope; float outResolutionX = prjSettings.OutResolutionX; float outResolutionY = prjSettings.OutResolutionY; Size outSize = prjSettings.OutSize; int outWidth = outSize.Width; int outHeight = outSize.Height; int outBandCount = prjSettings.OutBandNos.Length; if (progressCallback != null) { progressCallback(_readyProgress++, "投影准备"); } int srcHeight = srcRaster.Height; int srcWidth = srcRaster.Width; PrjPoint outLeftTopPoint = outEnvelope.LeftTop; float srcResolutionX = srcRaster.ResolutionX; float srcResolutionY = srcRaster.ResolutionY; Size srcSize = new Size(srcWidth, srcHeight); double outLtPointX = outLeftTopPoint.X; double outLtPointY = outLeftTopPoint.Y; PrjEnvelope srcEnvelope = new PrjEnvelope(srcRaster.CoordEnvelope.MinX, srcRaster.CoordEnvelope.MaxX, srcRaster.CoordEnvelope.MinY, srcRaster.CoordEnvelope.MaxY); long mem = MemoryHelper.GetAvalidPhyMemory(); #if !WIN64 mem = mem < 800 * 1024 * 1024 ? mem : 800 * 1024 * 1024; #endif long maxLimit = mem / (6 * 8 * 2); int rowStep = (int)(maxLimit / outWidth); if (rowStep == 0) { rowStep = 1; } if (rowStep > outHeight) { rowStep = outHeight; } int stepCount = (int)(Math.Ceiling((double)outHeight / rowStep)); int progressCount = outBandCount * stepCount + stepCount * 2; H5FileId fileId = H5F.create(prjSettings.OutPathAndFileName, H5F.CreateMode.ACC_TRUNC); List <string> listdatasets = new List <string>(); foreach (string name in dataSets.Keys) { listdatasets.Add(name); } HDF5.Hdf5Operator oper = new HDF5.Hdf5Operator(srcRaster.fileName); for (int bandnum = 0; bandnum < outBandCount; bandnum++) { enumDataType systype = enumDataType.Unknow; H5T.H5Type h5filetype = dataSets[listdatasets[bandnum]]; systype = GetSysDataType(dataSets[listdatasets[bandnum]]); switch (systype) { case enumDataType.Int16: RastAndProject <Int16>(outSize, h5filetype, fileId, listdatasets[bandnum], progressCallback, outWidth, outHeight, rowStep, srcRaster, prjSettings, bandnum, 0, oper); break; case enumDataType.Int32: RastAndProject <Int32>(outSize, h5filetype, fileId, listdatasets[bandnum], progressCallback, outWidth, outHeight, rowStep, srcRaster, prjSettings, bandnum, 0, oper); break; case enumDataType.Int64: RastAndProject <Int64>(outSize, h5filetype, fileId, listdatasets[bandnum], progressCallback, outWidth, outHeight, rowStep, srcRaster, prjSettings, bandnum, 0, oper); break; case enumDataType.UInt16: RastAndProject <UInt16>(outSize, h5filetype, fileId, listdatasets[bandnum], progressCallback, outWidth, outHeight, rowStep, srcRaster, prjSettings, bandnum, 0, oper); break; case enumDataType.UInt32: RastAndProject <UInt32>(outSize, h5filetype, fileId, listdatasets[bandnum], progressCallback, outWidth, outHeight, rowStep, srcRaster, prjSettings, bandnum, 0, oper); break; case enumDataType.UInt64: RastAndProject <UInt64>(outSize, h5filetype, fileId, listdatasets[bandnum], progressCallback, outWidth, outHeight, rowStep, srcRaster, prjSettings, bandnum, 0, oper); break; case enumDataType.Double: RastAndProject <Double>(outSize, h5filetype, fileId, listdatasets[bandnum], progressCallback, outWidth, outHeight, rowStep, srcRaster, prjSettings, bandnum, 0, oper); break; case enumDataType.Float: RastAndProject <Single>(outSize, h5filetype, fileId, listdatasets[bandnum], progressCallback, outWidth, outHeight, rowStep, srcRaster, prjSettings, bandnum, 0, oper); break; case enumDataType.Byte: RastAndProject <Byte>(outSize, h5filetype, fileId, listdatasets[bandnum], progressCallback, outWidth, outHeight, rowStep, srcRaster, prjSettings, bandnum, 0, oper); break; default: break; } } Dictionary <string, string> filekeyvalue = oper.GetAttributes(); foreach (string key in filekeyvalue.Keys) { string value = filekeyvalue[key]; HDFAttributeDef attrdef = new HDFAttributeDef(key, typeof(string), filekeyvalue[key].Length, value); WriteHdfAttributes.WriteHdfAttribute(fileId, attrdef); } //写四角坐标信息 HDFAttributeDef lefttopx = new HDFAttributeDef("Left-Top Latitude", typeof(string), prjSettings.OutEnvelope.LeftTop.Y.ToString().Length, prjSettings.OutEnvelope.LeftTop.Y.ToString()); WriteHdfAttributes.WriteHdfAttribute(fileId, lefttopx); HDFAttributeDef lefttopy = new HDFAttributeDef("Left-Top Longtitude", typeof(string), prjSettings.OutEnvelope.LeftTop.X.ToString().Length, prjSettings.OutEnvelope.LeftTop.X.ToString()); WriteHdfAttributes.WriteHdfAttribute(fileId, lefttopy); HDFAttributeDef boottomrightx = new HDFAttributeDef("Bottom-Right Latitude", typeof(string), prjSettings.OutEnvelope.RightBottom.Y.ToString().Length, prjSettings.OutEnvelope.RightBottom.Y.ToString()); WriteHdfAttributes.WriteHdfAttribute(fileId, boottomrightx); HDFAttributeDef boottomrighty = new HDFAttributeDef("Bottom-Right Longtitude", typeof(string), prjSettings.OutEnvelope.RightBottom.X.ToString().Length, prjSettings.OutEnvelope.RightBottom.X.ToString()); WriteHdfAttributes.WriteHdfAttribute(fileId, boottomrighty); //投影信息 string projtype = "Geopraphic Latitude longtitude"; HDFAttributeDef projecttype = new HDFAttributeDef("Projection Type", typeof(string), projtype.Length, projtype); WriteHdfAttributes.WriteHdfAttribute(fileId, projecttype); H5F.close(fileId); }
private void ProjectRaster <T>(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, Action <int, string> progressCallback, IRasterDataProvider prdWriter, T fillValue, double dataWeight, float zoom) { enumDataType dataType = prdWriter.DataType; PrjEnvelope outEnvelope = prjSettings.OutEnvelope; float outResolutionX = prjSettings.OutResolutionX; float outResolutionY = prjSettings.OutResolutionY; Size outSize = prjSettings.OutSize; int outWidth = outSize.Width; int outHeight = outSize.Height; int outBandCount = prjSettings.OutBandNos.Length; if (progressCallback != null) { progressCallback(_readyProgress++, "投影准备"); } int srcHeight = srcRaster.Height; int srcWidth = srcRaster.Width; PrjPoint outLeftTopPoint = outEnvelope.LeftTop; float srcResolutionX = srcRaster.ResolutionX; float srcResolutionY = srcRaster.ResolutionY; Size srcSize = new Size(srcWidth, srcHeight); double outLtPointX = outLeftTopPoint.X; double outLtPointY = outLeftTopPoint.Y; PrjEnvelope srcEnvelope = new PrjEnvelope(srcRaster.CoordEnvelope.MinX, srcRaster.CoordEnvelope.MaxX, srcRaster.CoordEnvelope.MinY, srcRaster.CoordEnvelope.MaxY); long mem = MemoryHelper.GetAvalidPhyMemory(); #if !WIN64 mem = mem < 800 * 1024 * 1024 ? mem : 800 * 1024 * 1024; #endif long maxLimit = mem / (6 * 8 * 2); int rowStep = (int)(maxLimit / outWidth); if (rowStep == 0) { rowStep = 1; } if (rowStep > outHeight) { rowStep = outHeight; } int stepCount = (int)(Math.Ceiling((double)outHeight / rowStep)); int percent = 0; int progress = 0; int progressCount = outBandCount * stepCount + stepCount * 2; for (int oRow = 0; oRow < outHeight; oRow += rowStep) { if (progressCallback != null) { percent++; progress = percent * 100 / progressCount; progressCallback(progress, string.Format("投影完成{0}%", progress)); } if (oRow + rowStep > outHeight) { rowStep = outHeight - oRow; } Size outStepSize = new Size(outWidth, rowStep); double[] xs = new double[outWidth * rowStep]; double[] ys = new double[outWidth * rowStep]; double oY = oRow * outResolutionY; Parallel.For(0, rowStep, j => { double x; double y; int index; y = outLtPointY - j * outResolutionY - oY; for (int i = 0; i < outWidth; i++) { x = outLtPointX + i * outResolutionX; index = i + j * outWidth; xs[index] = x; ys[index] = y; } }); _projectionTransform.InverTransform(xs, ys); PrjEnvelope tEnvelope = PrjEnvelope.GetEnvelope(xs, ys, null); tEnvelope.Extend(srcResolutionX, srcResolutionY * 4); tEnvelope = PrjEnvelope.Intersect(tEnvelope, srcEnvelope); if (tEnvelope == null || tEnvelope.IsEmpty) { continue; } Size tSize = tEnvelope.GetSize(srcResolutionX, srcResolutionY); int tBeginRow = -1, tEndRow = -1, tBeginCol = -1, tEndCol = -1; int oBeginRow = -1, oEndRow = -1, oBeginCol = -1, oEndCol = -1; PrjBlockHelper.ComputeBeginEndRowCol(srcEnvelope, srcSize, tEnvelope, tSize, ref oBeginRow, ref oBeginCol, ref oEndRow, ref oEndCol, ref tBeginRow, ref tBeginCol, ref tEndRow, ref tEndCol); int srcStepWidth = oEndCol - oBeginCol; int srcStepHeight = oEndRow - oBeginRow; Size srcStepSize = new Size(srcStepWidth, srcStepHeight); T[] srcBandData = new T[srcStepWidth * srcStepHeight]; T[] dstBandData = new T[outWidth * rowStep]; double srcStepLeftTopX = tEnvelope.MinX; double srcStepLeftTopY = tEnvelope.MaxY; double srcStepRightBottomX = tEnvelope.MaxX; double srcStepRightBottomY = tEnvelope.MinY; UInt16[] rows = new UInt16[outWidth * rowStep]; //正向查找表 UInt16[] cols = new UInt16[outWidth * rowStep]; //正向查找表 if (progressCallback != null) { percent++; progress = percent * 100 / progressCount; progressCallback(progress, string.Format("投影完成{0}%", progress)); } Parallel.For(0, rowStep, j => { double x; double y; int index; for (int i = 0; i < outWidth; i++) { index = i + j * outWidth; x = xs[index]; y = ys[index]; if (x >= srcStepLeftTopX && x <= srcStepRightBottomX && y <= srcStepLeftTopY && y >= srcStepRightBottomY) { cols[index] = (UInt16)((x - srcStepLeftTopX) / srcResolutionX + 0.5); rows[index] = (UInt16)((srcStepLeftTopY - y) / srcResolutionY + 0.5); } } }); xs = null; ys = null; for (int b = 0; b < outBandCount; b++) { if (progressCallback != null) { percent++; progress = percent * 100 / progressCount; progressCallback(progress, string.Format("投影完成{0}%", progress)); } ReadBandData <T>(srcBandData, b, oBeginCol, oBeginRow, srcStepWidth, srcStepHeight, dataType); //用于测试全图输出结果,用于查看插值的效果: #if DebugEaseGrid GCHandle hTe = GCHandle.Alloc(srcBandData, GCHandleType.Pinned); try { Random random = new Random(12); IntPtr bufferPtr = hTe.AddrOfPinnedObject(); Int16[] tmp = new Int16[srcBandData.Length]; for (int i = 0; i < srcBandData.Length; i++) { tmp[i] = (Int16)random.Next(200, 255); } Marshal.Copy(tmp, 0, bufferPtr, tmp.Length); } finally { hTe.Free(); } #endif _rasterProjector.Project <T>(srcBandData, srcStepSize, rows, cols, outStepSize, dstBandData, fillValue, 0, null); if (dataWeight == 1) { WriteDataToLDF <T>(prdWriter, dataType, outWidth, rowStep, oRow, dstBandData, b); } else { WriteDataToLDF <T>(prdWriter, dataType, outWidth, rowStep, oRow, dstBandData, b, dataWeight, zoom); } } rows = null; rows = null; srcBandData = null; dstBandData = null; } }
private void ProjectRaster <T>(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, Action <int, string> progressCallback, IRasterDataProvider prdWriter, T fillValue) { ProjectRaster <T>(srcRaster, prjSettings, progressCallback, prdWriter, fillValue, 1, 1); }
private static FY3_MERSI_PrjSettings ArgsCheck(IRasterDataProvider srcRaster, FilePrjSettings prjSettings) { if (srcRaster == null) { throw new ArgumentNullException("srcRaster"); } if (prjSettings == null) { throw new ArgumentNullException("prjSettings"); } FY3_MERSI_PrjSettings fy3prjSettings = prjSettings as FY3_MERSI_PrjSettings; return(fy3prjSettings); }
private void ReadyArgs(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, ISpatialReference dstSpatialRef, Action <int, string> progressCallback) { float resolutionScale = 1f; _readyProgress = 0; if (progressCallback != null) { progressCallback(_readyProgress++, "准备相关参数"); } if (dstSpatialRef == null) { dstSpatialRef = SpatialReference.GetDefault(); } _dstSpatialRef = dstSpatialRef; _prjSettings = ArgsCheck(srcRaster, prjSettings, progressCallback); //_fileType = CheckFile(srcRaster); _locationRaster = (prjSettings as FY3L2L3FilePrjSettings).LocationFile; ReadExtArgs(prjSettings); TryCreateDefaultArg(srcRaster, _prjSettings, ref _dstSpatialRef); _left = 0; _right = 0; TrySetLeftRightInvalidPixel(_prjSettings.ExtArgs); DoSession(srcRaster, _dstSpatialRef, _prjSettings, progressCallback); if (_prjSettings.OutEnvelope == null || _prjSettings.OutEnvelope == PrjEnvelope.Empty) { _prjSettings.OutEnvelope = _maxPrjEnvelope; _orbitBlock = new Block { xOffset = 0, yBegin = 0, xEnd = srcRaster.Width - 1, yEnd = srcRaster.Height - 1 }; } else { GetEnvelope(_xs, _ys, _srcLocationSize.Width, _srcLocationSize.Height, _prjSettings.OutEnvelope, out _orbitBlock); if (_orbitBlock == null || _orbitBlock.Width <= 0 || _orbitBlock.Height <= 0) { throw new Exception("数据不在目标区间内"); } float invalidPresent = (_orbitBlock.Width * _orbitBlock.Height * resolutionScale) / (srcRaster.Width * srcRaster.Height); if (invalidPresent < 0.0001f) { throw new Exception("数据占轨道数据比例太小,有效率" + invalidPresent * 100 + "%"); } if (invalidPresent > 0.60f) { _orbitBlock = new Block { xOffset = 0, yBegin = 0, xEnd = srcRaster.Width - 1, yEnd = srcRaster.Height - 1 } } ; } _dstEnvelope = _prjSettings.OutEnvelope; if (!_dstEnvelope.IntersectsWith(_maxPrjEnvelope)) { throw new Exception("数据不在目标区间内"); } _outResolutionX = _prjSettings.OutResolutionX; _outResolutionY = _prjSettings.OutResolutionY; _outFormat = _prjSettings.OutFormat; _outfilename = _prjSettings.OutPathAndFileName; _dstProj4 = _dstSpatialRef.ToProj4String(); //_dstBandCount = _prjBands.Length; _dstBandCount = _rasterDataBands.Length; _dstSize = _prjSettings.OutSize; //_isRadiation = _prjSettings.IsRadiation; //_isSolarZenith = _prjSettings.IsSolarZenith; //_isSensorZenith = _prjSettings.IsSensorZenith; }
public override IRasterDataProvider Project(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, IRasterDataProvider dstRaster, int beginBandIndex, Action <int, string> progressCallback) { if (dstRaster == null) { return(null); } try { ReadyArgs(srcRaster, prjSettings, dstRaster.SpatialRef, progressCallback); _prjSettings.OutPathAndFileName = dstRaster.fileName; _outfilename = dstRaster.fileName; _outResolutionX = dstRaster.ResolutionX; _outResolutionY = dstRaster.ResolutionY; _dstEnvelope = _prjSettings.OutEnvelope = new PrjEnvelope( dstRaster.CoordEnvelope.MinX, dstRaster.CoordEnvelope.MaxX, dstRaster.CoordEnvelope.MinY, dstRaster.CoordEnvelope.MaxY); try { Size outSize = new Size(dstRaster.Width, dstRaster.Height); //角度输出,其中的BANDNAME需要在ReadyAngleFiles()方法中获取 string[] angleOptions = new string[] { "INTERLEAVE=BSQ", "VERSION=LDF", "WITHHDR=TRUE", "SPATIALREF=" + _dstSpatialRef.ToProj4String(), "MAPINFO={" + 1 + "," + 1 + "}:{" + _prjSettings.OutEnvelope.MinX + "," + _prjSettings.OutEnvelope.MaxY + "}:{" + _outResolutionX + "," + _outResolutionY + "}" }; ReadyAngleFiles(_angleDataProvider, _outfilename, _prjSettings, outSize, angleOptions); ProjectToLDF(srcRaster, dstRaster, beginBandIndex, progressCallback); return(dstRaster); } catch (IOException ex) { if (ex.Message == "磁盘空间不足。\r\n" && File.Exists(_outfilename)) { File.Delete(_outfilename); } throw ex; } finally { if (dstRaster != null) { dstRaster.Dispose(); dstRaster = null; } } } catch { EndSession(); TryDeleteCurCatch(); throw; } finally { if (_curSession == null) { EndSession(); if (prjSettings.IsClearPrjCache) { TryDeleteCurCatch(); } } } }
/// <summary> /// /// 修改记录 /// -------------------------------------------- /// 修改日期:2013-80-29 /// 修改人:罗战克 /// 修改内容: /// 计算最大输出范围,原先为计算原始数据所有点的坐标, /// 现修改为使用采样读取原数据地理坐标的方式(高度和宽度最多采样1000个点),以提高速度 /// -------------------------------------------- /// /// </summary> /// <param name="srcRaster"></param> /// <param name="prjSettings"></param> /// <param name="dstSpatialRef"></param> /// <param name="progressCallback"></param> /// public override void Project(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, ISpatialReference dstSpatialRef, Action <int, string> progressCallback) { Project(srcRaster, prjSettings, dstSpatialRef, progressCallback, 1, 1); }
private void ReadyArgs(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, ISpatialReference dstSpatialRef, Action <int, string> progressCallback) { if (srcRaster.DataIdentify != null) { string satellite = srcRaster.DataIdentify.Satellite; //if (satellite == "FY3A")//FY3A MERSI250米数据已经经过处理,不需要再执行去条带操作 //{ // _sacnLineWidth = 0; //} } float resolutionScale = 1f; _readyProgress = 0; if (progressCallback != null) { progressCallback(_readyProgress++, "准备相关参数"); } _prjSettings = ArgsCheck(srcRaster, prjSettings); CheckIs0250(srcRaster); _dstSpatialRef = dstSpatialRef; switch (_dataType) { case "1KM": //整轨投影时候去除左右锯齿,分块投影不需要 _left = 10; _right = 10; if (_prjSettings.OutEnvelope == null || _prjSettings.OutEnvelope == PrjEnvelope.Empty) //整轨投影 { MemoryHelper.MemoryNeed(500, 1536); } else { MemoryHelper.MemoryNeed(400, 1536); //剩余900MB,已使用1.2GB } TryCreateDefaultArgs(srcRaster, _prjSettings, ref _dstSpatialRef); DoSession(srcRaster, srcRaster, _dstSpatialRef, _prjSettings, progressCallback); _angleDataProvider = srcRaster; break; case "QKM": resolutionScale = 4f; _left = 20; _right = 20; if (_prjSettings.OutEnvelope == null || _prjSettings.OutEnvelope == PrjEnvelope.Empty) { MemoryHelper.MemoryNeed(800, 1280); //整幅投影对内存做限制,系统剩余内存不低于1.5GB,应用程序已使用内存不超过600MB } else { MemoryHelper.MemoryNeed(600, 1280); //剩余900MB,已使用1.2GB } TryCreate0250DefaultArgs(srcRaster, _prjSettings, ref _dstSpatialRef); DoSession(srcRaster, _prjSettings.SecondaryOrbitRaster, _dstSpatialRef, _prjSettings, progressCallback); _angleDataProvider = _prjSettings.SecondaryOrbitRaster; break; default: break; } TrySetLeftRightInvalidPixel(_prjSettings.ExtArgs); if (_prjSettings.OutEnvelope == null || _prjSettings.OutEnvelope == PrjEnvelope.Empty) { _prjSettings.OutEnvelope = _maxPrjEnvelope; _orbitBlock = new Block { xOffset = 0, yBegin = 0, xEnd = _srcLocationSize.Width - 1, yEnd = _srcLocationSize.Height - 1 }; } else { GetEnvelope(_xs, _ys, _srcLocationSize.Width, _srcLocationSize.Height, _prjSettings.OutEnvelope, out _orbitBlock); if (_orbitBlock == null || _orbitBlock.Width <= 0 || _orbitBlock.Height <= 0) { throw new Exception("数据不在目标区间内"); } float invalidPresent = (_orbitBlock.Width * _orbitBlock.Height * resolutionScale) / (_srcLocationSize.Width * _srcLocationSize.Height); if (invalidPresent < 0.0001f) { throw new Exception("数据占轨道数据比例太小,有效率" + invalidPresent * 100 + "%"); } if (invalidPresent > 0.60) { _orbitBlock = new Block { xOffset = 0, yBegin = 0, xEnd = _srcLocationSize.Width - 1, yEnd = _srcLocationSize.Height - 1 } } ; } //地理坐标投影,下面简单的对地理坐标投影的范围作了限制,不大严谨,仅适合目前的状况。 if (_dstSpatialRef.ProjectionCoordSystem == null && (prjSettings.OutEnvelope.MaxY > 80 || prjSettings.OutEnvelope.MaxY < -80)) { throw new Exception(string.Format("高纬度数据,不适合投影为等经纬度数据[{0}]", _maxPrjEnvelope)); } //以下参数用于投影 _dstEnvelope = _prjSettings.OutEnvelope; if (!_dstEnvelope.IntersectsWith(_maxPrjEnvelope)) { throw new Exception("数据不在目标区间内"); } _outResolutionX = _prjSettings.OutResolutionX; _outResolutionY = _prjSettings.OutResolutionY; _outFormat = _prjSettings.OutFormat; _outfilename = _prjSettings.OutPathAndFileName; _dstProj4 = _dstSpatialRef.ToProj4String(); _dstBandCount = _prjBands.Length; _dstSize = _prjSettings.OutSize; _isRadiation = _prjSettings.IsRadiation; _isSolarZenith = _prjSettings.IsSolarZenith; _isSensorZenith = _prjSettings.IsSensorZenith; }
public override IRasterDataProvider Project(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, IRasterDataProvider dstRaster, int beginBandIndex, Action <int, string> progressCallback) { if (srcRaster == null) { throw new ArgumentNullException("srcRaster"); } if (prjSettings == null) { throw new ArgumentNullException("prjSettings"); } if (dstRaster == null && prjSettings.OutPathAndFileName == null) { throw new ArgumentNullException("dstRaster"); } try { FY3_VIRR_PrjSettings fy3prjSettings = prjSettings as FY3_VIRR_PrjSettings; ISpatialReference dstSpatialRef = dstRaster.SpatialRef; TryCreateDefaultArgs(srcRaster, fy3prjSettings, ref dstSpatialRef); DoSession(srcRaster, _geoDataProvider, dstSpatialRef, fy3prjSettings, progressCallback); if (prjSettings.OutEnvelope == null || prjSettings.OutEnvelope == PrjEnvelope.Empty) { prjSettings.OutEnvelope = _maxPrjEnvelope; } if (dstSpatialRef.ProjectionCoordSystem == null && (prjSettings.OutEnvelope.MaxY > 80 || prjSettings.OutEnvelope.MaxY < -80)) { throw new Exception(string.Format("高纬度数据[>80],不适合投影为等经纬度数据[{0}]", _maxPrjEnvelope)); } if (dstRaster == null) { PrjEnvelope dstEnvelope = prjSettings.OutEnvelope; string outFormat = prjSettings.OutFormat; string outfilename = prjSettings.OutPathAndFileName; string dstProj4 = dstSpatialRef.ToProj4String(); int dstBandCount = _prjBands.Length; Size srcSize = new Size(srcRaster.Width, srcRaster.Height); Size dstSize = prjSettings.OutSize; IRasterDataDriver drv = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver; string[] options = new string[] { "INTERLEAVE=BSQ", "VERSION=LDF", "WITHHDR=TRUE", "SPATIALREF=" + dstProj4, "MAPINFO={" + 1 + "," + 1 + "}:{" + dstEnvelope.MinX + "," + dstEnvelope.MaxY + "}:{" + prjSettings.OutResolutionX + "," + prjSettings.OutResolutionY + "}" }; dstRaster = drv.Create(outfilename, dstSize.Width, dstSize.Height, dstBandCount, enumDataType.UInt16, options) as IRasterDataProvider; } ProjectToLDF(srcRaster, dstRaster, 0, progressCallback); return(dstRaster); } catch { EndSession(); TryDeleteCurCatch(); throw; } finally { EndSession(); if (prjSettings.IsClearPrjCache) { TryDeleteCurCatch(); } } }
public override void Project(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, ISpatialReference dstSpatialRef, Action <int, string> progressCallback) { try { ReadyArgs(srcRaster, prjSettings, dstSpatialRef, progressCallback); IRasterDataProvider outwriter = null; try { //string[] options = new string[]{ // "INTERLEAVE=BSQ", // "VERSION=LDF", // "WITHHDR=TRUE", // "SPATIALREF=" + _dstSpatialRef.ToProj4String(), // "MAPINFO={" + 1 + "," + 1 + "}:{" + _prjSettings.OutEnvelope.MinX + "," + _prjSettings.OutEnvelope.MaxY + "}:{" + _outResolutionX + "," + _outResolutionY + "}" // ,"BANDNAMES="+ BandNameString(_prjSettings.OutBandNos) //}; List <string> options = new List <string>(); options.Add("INTERLEAVE=BSQ"); options.Add("VERSION=LDF"); options.Add("WITHHDR=TRUE"); options.Add("SPATIALREF=" + _dstSpatialRef.ToProj4String()); options.Add("MAPINFO={" + 1 + "," + 1 + "}:{" + _prjSettings.OutEnvelope.MinX + "," + _prjSettings.OutEnvelope.MaxY + "}:{" + _outResolutionX + "," + _outResolutionY + "}"); options.Add("SENSOR=MERSI"); if (srcRaster.DataIdentify != null) { string satellite = srcRaster.DataIdentify.Satellite; DateTime dt = srcRaster.DataIdentify.OrbitDateTime; bool asc = srcRaster.DataIdentify.IsAscOrbitDirection; if (!string.IsNullOrWhiteSpace(satellite)) { options.Add("SATELLITE=" + satellite); } if (dt != DateTime.MinValue && dt != DateTime.MaxValue) { options.Add("DATETIME=" + dt.ToString("yyyy/MM/dd HH:mm")); } options.Add("ORBITDIRECTION=" + (asc ? "ASC" : "DESC")); } List <string> op1 = new List <string>(options); op1.Add("BANDNAMES=" + BandNameString(_prjSettings.OutBandNos)); outwriter = CreateOutFile(_outfilename, _dstBandCount, _dstSize, op1.ToArray()); ReadyAngleFiles(_angleDataProvider, _outfilename, _prjSettings, _dstSize, options.ToArray()); ProjectToLDF(srcRaster, outwriter, 0, progressCallback); } catch (IOException ex) { if (ex.Message == "磁盘空间不足。\r\n" && File.Exists(_outfilename)) { File.Delete(_outfilename); } throw ex; } finally { if (outwriter != null) { outwriter.Dispose(); outwriter = null; } } } catch { EndSession(); TryDeleteCurCatch(); throw; } finally { if (_curSession == null) { EndSession(); if (prjSettings.IsClearPrjCache) { TryDeleteCurCatch(); } } } }
private void ProjectToLDF(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, ISpatialReference dstSpatialRef, Action <int, string> progressCallback, double weight, float zoom) { //...此处计算分块大小。 string outFilename = prjSettings.OutPathAndFileName; CheckAndCreateDir(Path.GetDirectoryName(outFilename)); using (IRasterDataProvider prdWriter = CreateOutFile(srcRaster, prjSettings, dstSpatialRef, srcRaster.DataType)) { switch (srcRaster.DataType) { case enumDataType.Atypism: throw new Exception("不支持混合类型数据"); break; case enumDataType.Bits: ProjectRaster <sbyte>(srcRaster, prjSettings, progressCallback, prdWriter, 0, weight, zoom); break; case enumDataType.Byte: ProjectRaster <byte>(srcRaster, prjSettings, progressCallback, prdWriter, 0, weight, zoom); break; case enumDataType.Double: ProjectRaster <Double>(srcRaster, prjSettings, progressCallback, prdWriter, 0, weight, zoom); break; case enumDataType.Float: ProjectRaster <float>(srcRaster, prjSettings, progressCallback, prdWriter, 0, weight, zoom); break; case enumDataType.Int16: ProjectRaster <Int16>(srcRaster, prjSettings, progressCallback, prdWriter, 0, weight, zoom); break; case enumDataType.Int32: ProjectRaster <Int32>(srcRaster, prjSettings, progressCallback, prdWriter, 0, weight, zoom); break; case enumDataType.Int64: ProjectRaster <Int64>(srcRaster, prjSettings, progressCallback, prdWriter, 0, weight, zoom); break; case enumDataType.UInt16: ProjectRaster <UInt16>(srcRaster, prjSettings, progressCallback, prdWriter, 0, weight, zoom); break; case enumDataType.UInt32: ProjectRaster <UInt32>(srcRaster, prjSettings, progressCallback, prdWriter, 0, weight, zoom); break; case enumDataType.UInt64: ProjectRaster <UInt64>(srcRaster, prjSettings, progressCallback, prdWriter, 0, weight, zoom); break; case enumDataType.Unknow: default: throw new Exception("未知数据类型"); break; } } GC.Collect(); }