public string TestDstExtendWGS84() { try { PrjEnvelope dstEnvelope; dstSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("WGS 1984.prj"); srcFilename = @"D:\mas数据\Mersi\FY3A_MERSI_GBAL_L1_20110501_0250_1000M_MS.HDF"; srcRaster = GeoDataDriver.Open(srcFilename) as IRasterDataProvider; IFileProjector proj = FileProjector.GetFileProjectByName("FY3_MERSI"); proj.ComputeDstEnvelope(srcRaster, dstSpatialRef, out dstEnvelope, _progressCallback); Console.WriteLine(dstEnvelope.ToString()); return(dstEnvelope.ToString()); } finally { if (srcRaster != null) { if (srcRaster.BandProvider != null) { srcRaster.BandProvider.Dispose(); } srcRaster.Dispose(); } } }
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"); } if (progressCallback != null) { progressCallback(0, "准备相关参数"); } _dstSpatialRef = dstSpatialRef; if (prjSettings.OutEnvelope == null || prjSettings.OutEnvelope == PrjEnvelope.Empty) { MemoryHelper.MemoryNeed(800, 1280); } else { MemoryHelper.MemoryNeed(600, 1280); //剩余900MB,已使用1.2GB } try { NOAA_PrjSettings noaaPrjSettings = prjSettings as NOAA_PrjSettings; TryCreateDefaultArgs(srcRaster, noaaPrjSettings, ref dstSpatialRef); _isSensorZenith = noaaPrjSettings.IsSensorZenith; DoSession(srcRaster, dstSpatialRef, noaaPrjSettings, 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, srcRaster.Width, srcRaster.Height, prjSettings.OutEnvelope, out _orbitBlock); if (_orbitBlock == null || _orbitBlock.Width <= 0 || _orbitBlock.Height <= 0) { throw new Exception("数据不在目标区间内"); } float invalidPresent = (_orbitBlock.Width * _orbitBlock.Height * 1.0F) / (srcRaster.Width * srcRaster.Height); if (invalidPresent < 0.001) { throw new Exception("数据不在目标区间内,有效率" + invalidPresent + "。"); } if (invalidPresent > 0.60) { _orbitBlock = new Block { xOffset = 0, yBegin = 0, xEnd = srcRaster.Width - 1, yEnd = srcRaster.Height - 1 } } ; } if (dstSpatialRef.ProjectionCoordSystem == null && _maxPrjEnvelope.MaxX > 180 && _maxPrjEnvelope.MinX < -180 && _maxPrjEnvelope.MaxY > 90 && _maxPrjEnvelope.MinY < -90) { throw new Exception("读取NOAA 1a5经纬度不在合理范围内[" + _maxPrjEnvelope.ToString() + "]"); } if (dstSpatialRef.ProjectionCoordSystem == null && (prjSettings.OutEnvelope.MaxY > 80 || prjSettings.OutEnvelope.MaxY < -80)) { throw new Exception(string.Format("高纬度数据[>80],不适合投影为等经纬度数据[{0}]", _maxPrjEnvelope)); } Project(srcRaster, noaaPrjSettings, dstSpatialRef, progressCallback); } catch { EndSession(); TryDeleteCurCatch(); throw; } finally { if (_curSession == null) { EndSession(); if (prjSettings.IsClearPrjCache) { TryDeleteCurCatch(); } } } }