private void TryCreateDefaultArg(IRasterDataProvider srcRaster, FY3L2L3FilePrjSettings prjSettings, ref ISpatialReference dstSpatialRef) { if (dstSpatialRef == null) { dstSpatialRef = _srcSpatialRef; } if (string.IsNullOrWhiteSpace(prjSettings.OutFormat)) { prjSettings.OutFormat = "LDF"; } if (dstSpatialRef.ProjectionCoordSystem == null) { _srcImgResolution = 0.01f; } else { _srcImgResolution = 0.01f; } if (prjSettings.OutResolutionX == 0 || prjSettings.OutResolutionY == 0) { if (dstSpatialRef.ProjectionCoordSystem == null) { prjSettings.OutResolutionX = 0.01f; prjSettings.OutResolutionY = 0.01f; } else { prjSettings.OutResolutionX = 1000f; prjSettings.OutResolutionY = 1000f; } } }
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); }
private void btnOk_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(textBox1.Text) || string.IsNullOrWhiteSpace(textBox2.Text) || string.IsNullOrWhiteSpace(textBox3.Text)) { return; } string dss = GetSelectedDataSets(); if (dss == null || dss.Length == 0) { ShowMsgBox("需要选择要投影的数据集"); return; } float resolutionX; float resolutionY; if (!float.TryParse(cmbResolutionX.Text, out resolutionX) || resolutionX == 0f) { ShowMsgBox("经度分辨率没有正确设置"); return; } if (!float.TryParse(cmbResolutionY.Text, out resolutionY) || resolutionY == 0f) { ShowMsgBox("经度分辨率没有正确设置"); return; } string mainfilename = textBox1.Text; string locationFilename = textBox2.Text; string outFilename = textBox3.Text; string lonlatDs = GetLongLatDatasetNames(); IRasterDataProvider mainRaster = null; IRasterDataProvider locationRaster = null; Action <int, string> progress = new Action <int, string>(OnProgress); try { string[] openArgs = new string[] { "datasets=" + dss }; mainRaster = RasterDataDriver.Open(mainfilename, openArgs) as IRasterDataProvider; if (mainRaster == null) { ShowMsgBox("无法读取数据"); return; } if (mainRaster.DataType == enumDataType.Atypism) { ShowMsgBox("不支持混合类型的数据"); return; } string[] locationArgs = new string[] { "datasets=" + lonlatDs, "geodatasets=" + lonlatDs }; locationRaster = RasterDataDriver.Open(locationFilename, locationArgs) as IRasterDataProvider; if (locationRaster == null || locationRaster.BandCount == 0) { ShowMsgBox("经纬度HDF数据文件,不存在经纬度数据集[Longitude,Latitude]"); return; } FY3L2L3FilePrjSettings setting = new FY3L2L3FilePrjSettings(); setting.LocationFile = locationRaster; setting.OutFormat = "LDF"; setting.OutPathAndFileName = outFilename; setting.OutResolutionX = resolutionX; setting.OutResolutionY = resolutionY; //Dictionary<string, double> args = new Dictionary<string, double>(); //args.Add("xzoom", 0.000001d); //args.Add("yzoom", 0.000001d); //setting.ExtArgs = new object[] { args }; FY3L2L3FileProjector projector = new FY3L2L3FileProjector(); projector.Project(mainRaster, setting, SpatialReference.GetDefault(), progress); ShowMsgBox("投影结束"); } catch (Exception ex) { ShowMsgBox(ex.Message); } finally { if (mainRaster != null) { mainRaster.Dispose(); mainRaster = null; } if (locationRaster != null) { locationRaster.Dispose(); locationRaster = null; } } }
private IRasterBand[] TryCreateRasterDataBands(IRasterDataProvider srcRaster, FY3L2L3FilePrjSettings prjSettings, Action <int, string> progressCallback) { IBandProvider srcbandpro = srcRaster.BandProvider as IBandProvider; int count = srcRaster.BandCount; List <IRasterBand> rasterBands = new List <IRasterBand>(); for (int i = 0; i < count; i++) { if (progressCallback != null) { progressCallback(_readyProgress++, "准备第" + i + "个输入数据通道"); } IRasterBand band = srcRaster.GetRasterBand(i + 1); rasterBands.Add(band); } return(rasterBands.ToArray()); }
private void DoSession(IRasterDataProvider srcRaster, ISpatialReference dstSpatialRef, FY3L2L3FilePrjSettings prjSettings, Action <int, string> progressCallback) { if (_curSession == null || _curSession != srcRaster || _isBeginSession) { IRasterDataProvider locationRester = prjSettings.LocationFile; ReadyLocations(locationRester, dstSpatialRef, out _xs, out _ys, out _maxPrjEnvelope, out _srcLocationSize, progressCallback); if (progressCallback != null) { progressCallback(_readyProgress++, "准备其他参数"); } //if (prjSettings.IsSolarZenith && prjSettings.IsRadiation) //{ // _szDataFilename = GetSolarZenithCacheFilename(locationRester.fileName); // if (!File.Exists(_szDataFilename)) // ReadySolarZenithArgsToFile(locationRester); // else // _solarZenithCacheRaster = GeoDataDriver.Open(_szDataFilename) as IRasterDataProvider; // if (prjSettings.IsSensorZenith) // { // ReadySensorZenith(locationRester); // } //} _rasterDataBands = TryCreateRasterDataBands(srcRaster, prjSettings, progressCallback); _isBeginSession = false; } }
private void SetPrjBand(FY3L2L3FilePrjSettings prjSettings, PrjBand[] defaultPrjBands) { }
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; }