private void TryCreateDefaultArgsHKM(IRasterDataProvider srcRaster, EOS_MODIS_PrjSettings prjSettings, ref ISpatialReference dstSpatialRef) { if (dstSpatialRef == null) { dstSpatialRef = _srcSpatialRef; } if (string.IsNullOrWhiteSpace(prjSettings.OutFormat)) { prjSettings.OutFormat = "LDF"; } if (prjSettings.OutResolutionX == 0 || prjSettings.OutResolutionY == 0) { if (dstSpatialRef.ProjectionCoordSystem == null) { prjSettings.OutResolutionX = 0.005F; prjSettings.OutResolutionY = 0.005F; } else { prjSettings.OutResolutionX = 500F; prjSettings.OutResolutionY = 500F; } } if (prjSettings.BandMapTable == null || prjSettings.BandMapTable.Count == 0) { List <BandMap> bandmapList = new List <BandMap>(); bandmapList.Add(new BandMap() { DatasetName = "EV_250_Aggr500_RefSB", File = srcRaster, BandIndex = 0 }); //1 bandmapList.Add(new BandMap() { DatasetName = "EV_250_Aggr500_RefSB", File = srcRaster, BandIndex = 1 }); //2 bandmapList.Add(new BandMap() { DatasetName = "EV_500_RefSB", File = srcRaster, BandIndex = 0 }); //3 bandmapList.Add(new BandMap() { DatasetName = "EV_500_RefSB", File = srcRaster, BandIndex = 1 }); bandmapList.Add(new BandMap() { DatasetName = "EV_500_RefSB", File = srcRaster, BandIndex = 2 }); bandmapList.Add(new BandMap() { DatasetName = "EV_500_RefSB", File = srcRaster, BandIndex = 3 }); bandmapList.Add(new BandMap() { DatasetName = "EV_500_RefSB", File = srcRaster, BandIndex = 4 }); //7 prjSettings.BandMapTable = bandmapList; } }
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 Project(IRasterDataProvider srcRaster, EOS_MODIS_PrjSettings prjSettings, ISpatialReference dstSpatialRef, Action <int, string> progressCallback) { PrjEnvelope envelops = prjSettings.OutEnvelope; if (envelops.IntersectsWith(_maxPrjEnvelope)) { switch (prjSettings.OutFormat) { case "LDF": ProjectToLDF(srcRaster, prjSettings, dstSpatialRef, progressCallback); break; case "MEMORY": default: throw new NotSupportedException(string.Format("暂不支持的输出格式", prjSettings.OutFormat)); } } else { throw new Exception("数据不在目标区间内"); } }
private string PrjMODIS_1KM_L1(IRasterDataProvider fileName, ISpatialReference projRef) {// IRasterDataProvider srcRaster = fileName; IRasterDataProvider locationRaster = null; try { List <BandMap> bandmapList = new List <BandMap>(); bandmapList.Add(new BandMap() { DatasetName = "EV_250_Aggr1km_RefSB", File = srcRaster, BandIndex = 0 }); //1 bandmapList.Add(new BandMap() { DatasetName = "EV_250_Aggr1km_RefSB", File = srcRaster, BandIndex = 1 }); //2 bandmapList.Add(new BandMap() { DatasetName = "EV_500_Aggr1km_RefSB", File = srcRaster, BandIndex = 0 }); //3 locationRaster = TryFindMODIS_1KM_L103File(fileName); IFileProjector projTor = FileProjector.GetFileProjectByName("EOS"); EOS_MODIS_PrjSettings prjSetting = new EOS_MODIS_PrjSettings(); prjSetting.BandMapTable = bandmapList; prjSetting.LocationFile = locationRaster; prjSetting.OutPathAndFileName = GetOutPutFile(fileName.fileName, projRef); ISpatialReference dstSpatialRef = projRef; projTor.Project(srcRaster, prjSetting, dstSpatialRef, _progress); return(prjSetting.OutPathAndFileName); } finally { if (locationRaster != null) { locationRaster.Dispose(); } } }
private void ProjectToLDF0500(IRasterDataProvider srcRaster, Size srcLocationSize, EOS_MODIS_PrjSettings prjSettings, ISpatialReference dstSpatialRef, Action <int, string> progressCallback) { if (srcRaster == null || srcRaster.Width == 0 || srcRaster.Height == 0) { throw new Exception("投影250米MERSI数据失败:无法读取源数据,或者源数据高或宽为0。"); } Size srcDataSize = new Size(srcRaster.Width, srcRaster.Height); string outFormat = prjSettings.OutFormat; string outfilename = prjSettings.OutPathAndFileName; string dstProj4 = dstSpatialRef.ToProj4String(); List <BandMap> bandMaps = prjSettings.BandMapTable; int dstBandCount = bandMaps.Count; Size dstSize = prjSettings.OutSize; using (IRasterDataDriver drv = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver) { PrjEnvelope dstEnvelope = prjSettings.OutEnvelope; string mapInfo = "MAPINFO={" + 1 + "," + 1 + "}:{" + dstEnvelope.MinX + "," + dstEnvelope.MaxY + "}:{" + prjSettings.OutResolutionX + "," + prjSettings.OutResolutionY + "}"; using (IRasterDataProvider prdWriter = drv.Create(outfilename, dstSize.Width, dstSize.Height, dstBandCount, enumDataType.UInt16, "INTERLEAVE=BSQ", "VERSION=LDF", "SPATIALREF=" + dstProj4, mapInfo, "WITHHDR=TRUE") as IRasterDataProvider) { //考虑分块 float outResolutionX = prjSettings.OutResolutionX; float outResolutionY = prjSettings.OutResolutionY; Size outSize = dstEnvelope.GetSize(outResolutionX, outResolutionY); #region 计算分块个数、分块高宽 int blockXNum; int blockYNum; int blockWidth; int blockHeight; GetBlockNumber(outSize, out blockXNum, out blockYNum, out blockWidth, out blockHeight); #endregion Size blockSize = new Size(blockWidth, blockHeight); for (int blockYIndex = 0; blockYIndex < blockYNum; blockYIndex++) { for (int blockXIndex = 0; blockXIndex < blockXNum; blockXIndex++) { //当前块的四角范围 double blockMinX = dstEnvelope.MinX + blockWidth * outResolutionX * blockXIndex; double blockMaxX = blockMinX + blockWidth * outResolutionX; double blockMaxY = dstEnvelope.MaxY - blockHeight * outResolutionY * blockYIndex; double blockMinY = blockMaxY - blockHeight * outResolutionY; PrjEnvelope blockEnvelope = new PrjEnvelope(blockMinX, blockMaxX, blockMinY, blockMaxY); UInt16[] dstRowLookUpTable = new UInt16[blockWidth * blockHeight]; UInt16[] dstColLookUpTable = new UInt16[blockWidth * blockHeight]; _rasterProjector.ComputeIndexMapTable(_xs, _ys, srcLocationSize, srcDataSize, blockSize, blockEnvelope, out dstRowLookUpTable, out dstColLookUpTable, progressCallback); //执行投影 UInt16[] srcBandData = null; UInt16[] dstBandData = new UInt16[blockWidth * blockHeight]; for (int i = 0; i < dstBandCount; i++) //读取原始通道值,投影到目标区域 { BandMap bandMap = bandMaps[i]; ReadBandData(out srcBandData, bandMap.File, bandMap.DatasetName, bandMap.BandIndex, srcDataSize); if (prjSettings.IsRadiation) //亮温转换,这里处理的不好,如果是做了一个小块的分幅,这里花的代价太高, { DoRadiation(srcBandData, srcDataSize, srcLocationSize, bandMap.DatasetName, bandMap.BandIndex, srcRaster, prjSettings.IsRadiation, prjSettings.IsSolarZenith); } _rasterProjector.Project <UInt16>(srcBandData, srcDataSize, dstRowLookUpTable, dstColLookUpTable, blockSize, dstBandData, 0, progressCallback); using (IRasterBand band = prdWriter.GetRasterBand(i + 1)) { unsafe { fixed(UInt16 *ptr = dstBandData) { IntPtr bufferPtr = new IntPtr(ptr); int blockOffsetY = blockYIndex * blockSize.Height; int blockOffsetX = blockWidth * blockXIndex; band.Write(blockOffsetX, blockOffsetY, blockWidth, blockHeight, bufferPtr, enumDataType.UInt16, blockWidth, blockHeight); } } } } } } } } }
private void TryCreateDefaultArgsKM(IRasterDataProvider srcRaster, EOS_MODIS_PrjSettings prjSettings, ref ISpatialReference dstSpatialRef) { if (dstSpatialRef == null) { dstSpatialRef = _srcSpatialRef; } if (string.IsNullOrWhiteSpace(prjSettings.OutFormat)) { prjSettings.OutFormat = "LDF"; } 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; } } if (prjSettings.BandMapTable == null || prjSettings.BandMapTable.Count == 0) { List <BandMap> bandmapList = new List <BandMap>(); bandmapList.Add(new BandMap() { DatasetName = "EV_250_Aggr1km_RefSB", File = srcRaster, BandIndex = 0 }); //1 bandmapList.Add(new BandMap() { DatasetName = "EV_250_Aggr1km_RefSB", File = srcRaster, BandIndex = 1 }); //2 bandmapList.Add(new BandMap() { DatasetName = "EV_500_Aggr1km_RefSB", File = srcRaster, BandIndex = 0 }); //3 bandmapList.Add(new BandMap() { DatasetName = "EV_500_Aggr1km_RefSB", File = srcRaster, BandIndex = 1 }); bandmapList.Add(new BandMap() { DatasetName = "EV_500_Aggr1km_RefSB", File = srcRaster, BandIndex = 2 }); bandmapList.Add(new BandMap() { DatasetName = "EV_500_Aggr1km_RefSB", File = srcRaster, BandIndex = 3 }); bandmapList.Add(new BandMap() { DatasetName = "EV_500_Aggr1km_RefSB", File = srcRaster, BandIndex = 4 }); //7 bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_RefSB", File = srcRaster, BandIndex = 0 }); //8 bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_RefSB", File = srcRaster, BandIndex = 1 }); bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_RefSB", File = srcRaster, BandIndex = 2 }); bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_RefSB", File = srcRaster, BandIndex = 3 }); bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_RefSB", File = srcRaster, BandIndex = 4 }); bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_RefSB", File = srcRaster, BandIndex = 5 }); //13lo bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_RefSB", File = srcRaster, BandIndex = 6 }); //13hi bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_RefSB", File = srcRaster, BandIndex = 7 }); //14lo bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_RefSB", File = srcRaster, BandIndex = 8 }); //14hi bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_RefSB", File = srcRaster, BandIndex = 9 }); //15 bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_RefSB", File = srcRaster, BandIndex = 10 }); bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_RefSB", File = srcRaster, BandIndex = 11 }); bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_RefSB", File = srcRaster, BandIndex = 12 }); bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_RefSB", File = srcRaster, BandIndex = 13 }); //19 bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_Emissive", File = srcRaster, BandIndex = 0 }); //20 bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_Emissive", File = srcRaster, BandIndex = 1 }); bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_Emissive", File = srcRaster, BandIndex = 2 }); bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_Emissive", File = srcRaster, BandIndex = 3 }); bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_Emissive", File = srcRaster, BandIndex = 4 }); bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_Emissive", File = srcRaster, BandIndex = 5 }); //25 bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_RefSB", File = srcRaster, BandIndex = 14 }); //26 bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_Emissive", File = srcRaster, BandIndex = 6 }); //27 bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_Emissive", File = srcRaster, BandIndex = 7 }); //28 bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_Emissive", File = srcRaster, BandIndex = 8 }); bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_Emissive", File = srcRaster, BandIndex = 9 }); bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_Emissive", File = srcRaster, BandIndex = 10 }); bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_Emissive", File = srcRaster, BandIndex = 11 }); bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_Emissive", File = srcRaster, BandIndex = 12 }); bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_Emissive", File = srcRaster, BandIndex = 13 }); bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_Emissive", File = srcRaster, BandIndex = 14 }); bandmapList.Add(new BandMap() { DatasetName = "EV_1KM_Emissive", File = srcRaster, BandIndex = 15 }); //36 prjSettings.BandMapTable = bandmapList; } }
/// <summary> /// 0、先生成目标文件,以防止目标空间不足。 /// 1、计算查找表 /// 2、对所有波段执行投影 /// </summary> private void ProjectToLDF(IRasterDataProvider srcRaster, EOS_MODIS_PrjSettings prjSettings, ISpatialReference dstSpatialRef, Action <int, string> progressCallback) { string outFormat = prjSettings.OutFormat; string outfilename = prjSettings.OutPathAndFileName; string dstProj4 = dstSpatialRef.ToProj4String(); List <BandMap> bandMaps = prjSettings.BandMapTable; int dstBandCount = bandMaps.Count; Size srcSize = new Size(srcRaster.Width, srcRaster.Height); Size dstSize = prjSettings.OutSize; using (IRasterDataDriver drv = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver) { PrjEnvelope dstEnvelope = prjSettings.OutEnvelope; string[] options = new string[] { "INTERLEAVE=BSQ", "VERSION=LDF", "WITHHDR=TRUE", "SPATIALREF=" + dstSpatialRef.ToProj4String(), "MAPINFO={" + 1 + "," + 1 + "}:{" + dstEnvelope.MinX + "," + dstEnvelope.MaxY + "}:{" + prjSettings.OutResolutionX + "," + prjSettings.OutResolutionY + "}" }; if (progressCallback != null) { progressCallback(4, "生成输出文件"); } using (IRasterDataProvider prdWriter = drv.Create(outfilename, dstSize.Width, dstSize.Height, dstBandCount, enumDataType.UInt16, options) as IRasterDataProvider) { UInt16[] dstRowLookUpTable = new UInt16[dstSize.Width * dstSize.Height]; UInt16[] dstColLookUpTable = new UInt16[dstSize.Width * dstSize.Height]; _rasterProjector.ComputeIndexMapTable(_xs, _ys, _locationSize, dstSize, dstEnvelope, _maxPrjEnvelope, out dstRowLookUpTable, out dstColLookUpTable, null); //执行投影 UInt16[] srcBandData = new UInt16[srcSize.Width * srcSize.Height]; UInt16[] dstBandData = new UInt16[dstSize.Width * dstSize.Height]; int progress = 0; for (int i = 0; i < dstBandCount; i++) //读取原始通道值,投影到目标区域 { if (progressCallback != null) { progress = (int)((i + 1) * 100 / dstBandCount); progressCallback(progress, string.Format("投影第{0}通道", i + 1)); } BandMap bandMap = bandMaps[i]; ReadBandData(srcBandData, bandMap.File, bandMap.DatasetName, bandMap.BandIndex, srcSize); DoRadiation(srcBandData, srcSize, bandMap.DatasetName, bandMap.BandIndex, srcRaster, prjSettings.IsRadiation, prjSettings.IsSolarZenith); _rasterProjector.Project <UInt16>(srcBandData, srcSize, dstRowLookUpTable, dstColLookUpTable, dstSize, dstBandData, 0, null); using (IRasterBand band = prdWriter.GetRasterBand(i + 1)) { unsafe { fixed(UInt16 *ptr = dstBandData) { IntPtr bufferPtr = new IntPtr(ptr); band.Write(0, 0, band.Width, band.Height, bufferPtr, enumDataType.UInt16, band.Width, band.Height); } } } } } } }
private void DoSession(IRasterDataProvider srcRaster, ISpatialReference dstSpatialRef, EOS_MODIS_PrjSettings fy3prjSettings, Action <int, string> progressCallback) { if (_curSession != null && _curSession != srcRaster) { EndSession(); } if (_curSession == null) { IRasterDataProvider locationFile = fy3prjSettings.LocationFile; ReadyLocations(locationFile, dstSpatialRef, out _xs, out _ys, out _maxPrjEnvelope, out _locationSize, progressCallback); if (progressCallback != null) { progressCallback(3, "准备其他参数"); } if (fy3prjSettings.IsRadiation && fy3prjSettings.IsSolarZenith) { ReadySolarZenithArgs(locationFile); } } }