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(); } } } }
private void ReadyArgs(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, ISpatialReference dstSpatialRef, Action <int, string> progressCallback) { float resolutionScale = 1f; _readyProgress = 0; if (progressCallback != null) { progressCallback(_readyProgress++, "准备相关参数"); } _prjSettings = ArgsCheck(srcRaster, prjSettings); _geoDataProvider = _prjSettings.GeoFile; 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 } //_angleDataProvider = srcRaster; TryCreateDefaultArgs(srcRaster, _prjSettings, ref _dstSpatialRef); TrySetLeftRightInvalidPixel(_prjSettings.ExtArgs); DoSession(srcRaster, _geoDataProvider, _dstSpatialRef, _prjSettings, progressCallback); break; case "QKM": resolutionScale = 4f; _left = 20; _right = 20; if (_prjSettings.OutEnvelope == null || _prjSettings.OutEnvelope == PrjEnvelope.Empty) { MemoryHelper.MemoryNeed(800, 1280); //整幅投影对内存做限制,系统剩余内存不低于A参数MB,应用程序已使用内存不超过B参数MB } else { MemoryHelper.MemoryNeed(600, 1280); //剩余900MB,最大已使用1.2GB } //_angleDataProvider = _prjSettings.SecondaryOrbitRaster; TryCreate0250DefaultArgs(srcRaster, _prjSettings, ref _dstSpatialRef); TrySetLeftRightInvalidPixel(_prjSettings.ExtArgs); DoSession(srcRaster, _geoDataProvider, _dstSpatialRef, _prjSettings, progressCallback); break; default: break; } 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 { if (_xs != null && _ys != null) { GetEnvelope(_xs, _ys, _srcLocationSize.Width, _srcLocationSize.Height, _prjSettings.OutEnvelope, out _orbitBlock); } else { int bC = 8; int tmpWidth = 0; int tmpHeight = 0; double[] tmpxs = null; double[] tmpys = null; //8024,8000 tmpWidth = _srcLocationSize.Width / bC; tmpHeight = _srcLocationSize.Height / bC; tmpxs = ReadSampleDatas(_longitudeBand, 0, 0, tmpWidth, tmpHeight); tmpys = ReadSampleDatas(_latitudeBand, 0, 0, tmpWidth, tmpHeight); _rasterProjector.Transform(SpatialReference.GetDefault(), tmpxs, tmpys, _dstSpatialRef); //计算偏移 GetEnvelope(tmpxs, tmpys, tmpWidth, tmpHeight, _prjSettings.OutEnvelope, out _orbitBlock); _orbitBlock = _orbitBlock.Zoom(bC, bC); } 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; }
private void ReadyArgs(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, ISpatialReference dstSpatialRef, Action <int, string> progressCallback) { if (srcRaster == null) { throw new ArgumentNullException("srcRaster"); } if (prjSettings == null) { throw new ArgumentNullException("prjSettings"); } _readyProgress = 0; _prjSettings = prjSettings as FY3_VIRR_PrjSettings; _dstSpatialRef = dstSpatialRef; MemoryHelper.MemoryNeed(200, 1536);//剩余200MB,已使用1.2GB if (progressCallback != null) { progressCallback(_readyProgress++, "准备相关参数"); } TryCreateDefaultArgs(srcRaster, _prjSettings, ref dstSpatialRef); //这里去除的是读取轨道数据时候的左右像元个数。 _left = 4; _right = 4; 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, 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.0001f) { throw new Exception("数据占轨道数据比例太小,有效率" + invalidPresent * 100 + "%"); } if (invalidPresent > 0.60) { _orbitBlock = new Block { xOffset = 0, yBegin = 0, xEnd = srcRaster.Width - 1, yEnd = srcRaster.Height - 1 } } ; } if (dstSpatialRef.ProjectionCoordSystem == null && (prjSettings.OutEnvelope.MaxY > 80 || prjSettings.OutEnvelope.MaxY < -80)) { throw new Exception(string.Format("高纬度数据,不适合投影为等经纬度数据[{0}]", _maxPrjEnvelope)); } _dstSpatialRef = dstSpatialRef; _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 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(200, 1536); } else { MemoryHelper.MemoryNeed(200, 1536); //剩余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.0001f) { throw new Exception("数据占轨道数据比例太小,有效率" + invalidPresent * 100 + "%"); } 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("读取FY1X 1a5经纬度不在合理范围内[" + _maxPrjEnvelope.ToString() + "]"); } //if (dstSpatialRef.ProjectionCoordSystem == null && (prjSettings.OutEnvelope.MaxY > 80 || prjSettings.OutEnvelope.MaxY < -80)) // throw new Exception(string.Format("高纬度数据[>80],不适合投影为等经纬度数据[{0}]", _maxPrjEnvelope)); PrjEnvelope envelops = prjSettings.OutEnvelope; if (!envelops.IntersectsWith(_maxPrjEnvelope)) { throw new Exception("数据不在目标区间内"); } float outResolutionX = prjSettings.OutResolutionX; float outResolutionY = prjSettings.OutResolutionY; int dstBandCount = prjSettings.OutBandNos.Length; Size outSize = prjSettings.OutSize; string[] angleOptions = new string[] { "INTERLEAVE=BSQ", "VERSION=LDF", "WITHHDR=TRUE", "SPATIALREF=" + dstSpatialRef.ToProj4String(), "MAPINFO={" + 1 + "," + 1 + "}:{" + prjSettings.OutEnvelope.MinX + "," + prjSettings.OutEnvelope.MaxY + "}:{" + outResolutionX + "," + outResolutionY + "}" }; string outfilename = prjSettings.OutPathAndFileName; ReadyAngleFiles(srcRaster, outfilename, prjSettings, outSize, angleOptions); Project(srcRaster, noaaPrjSettings, dstSpatialRef, progressCallback); } catch { EndSession(); TryDeleteCurCatch(); throw; } finally { if (_curSession == null) { EndSession(); if (prjSettings.IsClearPrjCache) { TryDeleteCurCatch(); } } } }