private void BuildInternalBuffer(string fileName) { IRasterDataDriver drv = GeoDataDriver.GetDriverByName("MEM") as IRasterDataDriver; _dataProvider = drv.Create(fileName, vData.Width, vData.Height, 1, vData.DataType, GetOptions()); _rasterBand = _dataProvider.GetRasterBand(1); }
public static IRasterDataProvider CreateVirtureData(VirtualRasterHeader vHeader, string filename, enumDataType enumDataType) { IRasterDataDriver dr = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver; return(dr.Create(filename, vHeader.Width, vHeader.Height, 1, enumDataType, vHeader.CoordEnvelope.ToMapInfoString(new Size(vHeader.Width, vHeader.Height)))); }
/// <summary> /// 创建目标tif文件读取驱动 /// </summary> /// <returns></returns> private IRasterDataProvider GetOutFileProvider(IRasterDataProvider srcRaster, Size outimg, string outfilename) { string[] options = null; string driver = string.Empty; string dstwktstr = string.Empty; dstwktstr = "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137,298.257223563]],PRIMEM['Greenwich',0],UNIT['Degree',0.0174532925199433]]"; dstwktstr = dstwktstr.Replace('\'', '"'); double minx = srcRaster.CoordEnvelope.MinX; double maxy = srcRaster.CoordEnvelope.MaxY; double resolutionX = srcRaster.ResolutionX; double resolutionY = srcRaster.ResolutionY; driver = "GDAL"; options = new string[] { "DRIVERNAME=GTiff", "TFW=NO", "WKT=" + dstwktstr, "GEOTRANSFORM=" + string.Format("{0},{1},{2},{3},{4},{5}", minx, resolutionX, 0, maxy, 0, -resolutionY) }; int bandCount = srcRaster.BandCount == 1 ? 1 : 3; string outdir = Path.GetDirectoryName(outfilename); if (!Directory.Exists(outdir)) { Directory.CreateDirectory(outdir); } IRasterDataDriver outdrv = GeoDataDriver.GetDriverByName(driver) as IRasterDataDriver; return(outdrv.Create(outfilename, outimg.Width, outimg.Height, bandCount, enumDataType.Byte, options) as IRasterDataProvider); }
private IRasterDataProvider CreatOutputRaster(string outputFName, IRasterDataProvider inRaster, int bandCount, Action <int, string> progressCallback) { if (inRaster == null) { return(null); } if (progressCallback != null) { progressCallback(1, "开始创建目标文件..."); } IRasterDataDriver driver = GeoDataDriver.GetDriverByName("GDAL") as IRasterDataDriver; List <string> options = new List <string>(); options.AddRange(new string[] { "DRIVERNAME=GTiff", "TFW=YES", "TILED=YES" }); if (inRaster.SpatialRef != null) { options.Add("WKT=" + inRaster.SpatialRef.ToWKTString()); } if (inRaster.CoordEnvelope != null) { options.Add("GEOTRANSFORM=" + string.Format("{0},{1},{2},{3},{4},{5}", 0, inRaster.ResolutionX, 0, inRaster.CoordEnvelope.MaxY, 0, -inRaster.ResolutionY)); } IRasterDataProvider prdWrite = driver.Create(outputFName, inRaster.Width, inRaster.Height, bandCount, enumDataType.Byte, options.ToArray()) as IRasterDataProvider; if (progressCallback != null) { progressCallback(20, "目标文件创建完成."); } return(prdWrite); }
public static IRasterDataProvider CreateRaster(string outFileName, IRasterDataProvider referProvider, string fname) { int width = referProvider.Width; int height = referProvider.Height; Project.ISpatialReference spatialRef = referProvider.SpatialRef; enumDataType datatype = referProvider.DataType; List <string> options = new List <string>(); options.Add("INTERLEAVE=BSQ"); options.Add("VERSION=LDF"); options.Add("WITHHDR=TRUE"); options.Add("SPATIALREF=" + spatialRef.ToProj4String()); options.Add("MAPINFO={" + 1 + "," + 1 + "}:{" + referProvider.CoordEnvelope.MinX + "," + referProvider.CoordEnvelope.MaxY + "}:{" + referProvider.ResolutionX + "," + referProvider.ResolutionY + "}"); //=env.ToMapInfoString(new Size(width, height)); string hdrfile = HdrFile.GetHdrFileName(Path.ChangeExtension(fname, ".hdr")); if (!string.IsNullOrWhiteSpace(hdrfile) && File.Exists(hdrfile)) { HdrFile hdr = HdrFile.LoadFrom(hdrfile); if (hdr != null && hdr.BandNames != null) { options.Add("BANDNAMES=" + string.Join(",", hdr.BandNames)); } } if (!Directory.Exists(Path.GetDirectoryName(outFileName))) { Directory.CreateDirectory(Path.GetDirectoryName(outFileName)); } IRasterDataDriver raster = RasterDataDriver.GetDriverByName("LDF") as IRasterDataDriver; RasterDataProvider outRaster = raster.Create(outFileName, width, height, 1, datatype, options.ToArray()) as RasterDataProvider; return(outRaster); }
public unsafe void CopyBlockToEmptyFile() { int xSize = 512; int ySize = 512; int bandCount = 20; string fname = "d:\\Ldf_Write_GeoDo.ldf"; IRasterDataDriver drv = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver; IRasterDataProvider dstPrd = CreateEmptyFile(fname, drv, xSize, ySize, bandCount); IRasterDataProvider srcPrd = OpenLdfFile(_originalFname); UInt16[] buffer = new UInt16[xSize * ySize]; long lostTime = 0; fixed(UInt16 *ptr = buffer) { IntPtr butterPtr = new IntPtr(ptr); for (int b = 1; b <= bandCount; b++) { srcPrd.GetRasterBand(b).Read(200, 200, xSize, ySize, butterPtr, enumDataType.UInt16, xSize, ySize); Stopwatch sw = new Stopwatch(); sw.Start(); dstPrd.GetRasterBand(b).Write(0, 0, xSize, ySize, butterPtr, enumDataType.UInt16, xSize, ySize); sw.Stop(); lostTime += sw.ElapsedMilliseconds; } } srcPrd.Dispose(); dstPrd.Dispose(); Console.WriteLine("Time Only Write:" + lostTime.ToString()); }
public unsafe void WriteWithSample() { int xSize = 512; int ySize = 512; int bandCount = 20; int dstWith = 2000; int dstHeight = 2000; string fname = "d:\\Ldf_Write_GeoDo_Sample.ldf"; IRasterDataDriver drv = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver; IRasterDataProvider dstPrd = CreateEmptyFile(fname, drv, dstWith, dstHeight, bandCount); IRasterDataProvider srcPrd = OpenLdfFile(_originalFname); UInt16[] buffer = new UInt16[xSize * ySize]; fixed(UInt16 *ptr = buffer) { IntPtr butterPtr = new IntPtr(ptr); for (int b = 1; b <= bandCount; b++) { srcPrd.GetRasterBand(b).Read(200, 200, xSize, ySize, butterPtr, enumDataType.UInt16, xSize, ySize); dstPrd.GetRasterBand(b).Write(0, 0, dstWith, dstHeight, butterPtr, enumDataType.UInt16, xSize, ySize); } } srcPrd.Dispose(); dstPrd.Dispose(); }
//以下为一些辅助帮助类 public static IRasterDataProvider CreateRaster(string outFileName, CoordEnvelope env, float resolutionX, float resolutionY, int bandCount, IRasterDataProvider referProvider) { //int bandCount = referProvider.BandCount; //CoordEnvelope outEnv = referProvider.CoordEnvelope; //float resX = referProvider.ResolutionX; //float resY = referProvider.ResolutionY; int width = (int)(Math.Round(env.Width / resolutionX)); int height = (int)(Math.Round(env.Height / resolutionY)); Project.ISpatialReference spatialRef = referProvider.SpatialRef; enumDataType datatype = referProvider.DataType; List <string> options = new List <string>(); options.Add("INTERLEAVE=BSQ"); options.Add("VERSION=LDF"); options.Add("WITHHDR=TRUE"); options.Add("SPATIALREF=" + spatialRef.ToProj4String()); options.Add("MAPINFO={" + 1 + "," + 1 + "}:{" + env.MinX + "," + env.MaxY + "}:{" + resolutionX + "," + resolutionY + "}"); //=env.ToMapInfoString(new Size(width, height)); string hdrfile = HdrFile.GetHdrFileName(referProvider.fileName); if (!string.IsNullOrWhiteSpace(hdrfile) && File.Exists(hdrfile)) { HdrFile hdr = HdrFile.LoadFrom(hdrfile); if (hdr != null && hdr.BandNames != null) { options.Add("BANDNAMES=" + string.Join(",", hdr.BandNames)); } } CheckAndCreateDir(Path.GetDirectoryName(outFileName)); IRasterDataDriver raster = RasterDataDriver.GetDriverByName("LDF") as IRasterDataDriver; RasterDataProvider outRaster = raster.Create(outFileName, width, height, bandCount, datatype, options.ToArray()) as RasterDataProvider; return(outRaster); }
private IRasterDataProvider CreateOutRaster(string outdir, IRasterDataProvider raster, ISpatialReference dstSpatial, PrjEnvelope envelope, double resolutionX, double resolutionY, string bandNames) { IRasterDataProvider outRaster = null; if (raster.Driver.Name == "MEM") //smart 产品数据,输出也用MEM驱动,目前数据纠正这里不存在。 { string[] options = new string[] { "INTERLEAVE=BSQ", "VERSION=MEM", "SPATIALREF=" + dstSpatial.ToProj4String(), "MAPINFO={" + 1 + "," + 1 + "}:{" + envelope.MinX + "," + envelope.MaxY + "}:{" + resolutionX + "," + resolutionY + "}", string.IsNullOrWhiteSpace(bandNames)?"": "BANDNAMES=" + bandNames }; string outfilename = Path.Combine(outdir, Path.GetFileNameWithoutExtension(raster.fileName) + ".DAT"); outRaster = (raster.Driver as IRasterDataDriver).Create(outfilename, raster.Width, raster.Height, 1, enumDataType.Int16, options); } else//ldf { string[] options = new string[] { "INTERLEAVE=BSQ", "VERSION=LDF", "SPATIALREF=" + dstSpatial.ToProj4String(), "MAPINFO={" + 1 + "," + 1 + "}:{" + envelope.MinX + "," + envelope.MaxY + "}:{" + resolutionX + "," + resolutionY + "}", "DATETIME=" + raster.DataIdentify.OrbitDateTime, string.IsNullOrWhiteSpace(bandNames)?"": "BANDNAMES=" + bandNames }; string outfilename = Path.Combine(outdir, Path.GetFileNameWithoutExtension(raster.fileName) + ".LDF"); IRasterDataDriver driver = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver; outRaster = driver.Create(outfilename, raster.Width, raster.Height, 1, enumDataType.Int16, options); } return(outRaster); }
private void BuildInternalBuffer(string _fileName) { IRasterDataDriver drv = GeoDataDriver.GetDriverByName("MEM") as IRasterDataDriver; _dataProvider = drv.Create(_fileName, _size.Width, _size.Height, 1, GetDataType(), GetOptions()); _rasterValues = _dataProvider.GetRasterBand(1); }
internal IRasterDataProvider CreateOutFile(string driver, string outfilename, int dstBandCount, Size outSize, enumDataType dataType, string[] options) { CheckAndCreateDir(Path.GetDirectoryName(outfilename)); IRasterDataDriver outdrv = GeoDataDriver.GetDriverByName(driver) as IRasterDataDriver; return(outdrv.Create(outfilename, outSize.Width, outSize.Height, dstBandCount, dataType, options) as IRasterDataProvider); }
protected IRasterDataProvider CreateOutM_BandRaster(string outFileName, RasterMaper[] inrasterMaper, int bandcount) { IRasterDataDriver raster = RasterDataDriver.GetDriverByName("LDF") as IRasterDataDriver; CoordEnvelope outEnv = null; foreach (RasterMaper inRaster in inrasterMaper) { if (outEnv == null) { outEnv = inRaster.Raster.CoordEnvelope; } else { outEnv.Union(inRaster.Raster.CoordEnvelope); } } float resX = inrasterMaper[0].Raster.ResolutionX; float resY = inrasterMaper[0].Raster.ResolutionY; int width = (int)(Math.Round(outEnv.Width / resX)); int height = (int)(Math.Round(outEnv.Height / resY)); string mapInfo = outEnv.ToMapInfoString(new Size(width, height)); string[] optionString = new string[] { "INTERLEAVE=BSQ", "VERSION=LDF", "WITHHDR=TRUE", "SPATIALREF=" + inrasterMaper[0].Raster.SpatialRef == null?"":("SPATIALREF=" + inrasterMaper[0].Raster.SpatialRef.ToProj4String()), "MAPINFO={" + 1 + "," + 1 + "}:{" + outEnv.MinX + "," + outEnv.MaxY + "}:{" + resX + "," + resY + "}" }; RasterDataProvider outRaster = raster.Create(outFileName, width, height, bandcount, enumDataType.UInt16, optionString) as RasterDataProvider; return(outRaster); }
public void GetBandData() { string fname = "d:\\NOAA18_AVHRR_CHINA_L1_20090806_N3_1000M.dat"; IRasterDataDriver drv = GeoDataDriver.GetDriverByName("GDAL") as IRasterDataDriver; IRasterDataProvider prd = drv.Open(fname, enumDataProviderAccess.ReadOnly) as IRasterDataProvider;// GeoDataDriver.Open(fname) as IRasterDataProvider; IRasterBand rb = prd.GetRasterBand(3); UInt16[] buffer = new UInt16[prd.Width * prd.Height]; unsafe { fixed(UInt16 *ptr = buffer) { IntPtr bufferPtr = new IntPtr(ptr); //prd.Read(0, 0, prd.Width, prd.Height, bufferPtr, enumDataType.UInt16, prd.Width, prd.Height, 1, new int[] { 1 }, enumInterleave.BSQ); rb.Read(0, 0, prd.Width, prd.Height, bufferPtr, enumDataType.UInt16, prd.Width, prd.Height); } } string filename = "d:\\d.dat"; FileStream fs = new FileStream(filename, FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); for (int i = 0; i < buffer.Length; i++) { bw.Write(buffer[i]); } fs.Close(); }
public IRasterBand[] Clip(IRasterBand srcBand, BlockDef[] blockDefs, int samplePercent, string driver, Action <int, string> progressCallback, params object[] options) { if (blockDefs.Length == 0 || blockDefs == null || srcBand == null) { return(null); } IRasterBand[] targetBands = new IRasterBand[blockDefs.Length]; int blockNums = 0; foreach (BlockDef it in blockDefs) { int tBeginRow = -1, tEndRow = -1, tBeginCol = -1, tEndCol = -1; int oBeginRow = -1, oEndRow = -1, oBeginCol = -1, oEndCol = -1; CoordEnvelope oEnvelope = srcBand.CoordEnvelope; CoordEnvelope tEnvelope = it.ToEnvelope(); Size oSize = new Size(srcBand.Width, srcBand.Height); Size tSize = ClipCutHelper.GetTargetSize(it, srcBand.ResolutionX, srcBand.ResolutionY); bool isInternal = new RasterMoasicClipHelper().ComputeBeginEndRowCol(oEnvelope, oSize, tEnvelope, tSize, ref oBeginRow, ref oBeginCol, ref oEndRow, ref oEndCol, ref tBeginRow, ref tBeginCol, ref tEndRow, ref tEndCol); IRasterDataDriver rasterDriver = GeoDataDriver.GetDriverByName(driver) as IRasterDataDriver; //targetBands[blockNums] = ; blockNums++; } return(targetBands); }
private void TryCreateLDFFile(string bandfname, int bandNO, int xSize, int ySize, float[] buffer, string[] options, enumDataType dataType) { string dstDir = Path.GetDirectoryName(bandfname); if (!Directory.Exists(dstDir)) { Directory.CreateDirectory(dstDir); } if (File.Exists(bandfname)) { File.Delete(bandfname); } IRasterDataDriver driver = RasterDataDriver.GetDriverByName("LDF") as IRasterDataDriver; using (IRasterDataProvider bandRaster = driver.Create(bandfname, xSize, ySize, 1, dataType, options) as IRasterDataProvider) { GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); try { bandRaster.GetRasterBand(1).Write(0, 0, xSize, ySize, handle.AddrOfPinnedObject(), enumDataType.Float, xSize, ySize); } finally { handle.Free(); } } }
private IRasterDataProvider CreateOutRaster(string outFileName, RasterMaper[] inrasterMaper, int extHeaderLength) { IRasterDataDriver raster = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver; CoordEnvelope outEnv = null; float resX = inrasterMaper[0].Raster.ResolutionX; float resY = inrasterMaper[0].Raster.ResolutionY; foreach (RasterMaper inRaster in inrasterMaper) { if (outEnv == null) { outEnv = inRaster.Raster.CoordEnvelope; } else { outEnv = outEnv.Union(inRaster.Raster.CoordEnvelope); } if (resX < inRaster.Raster.ResolutionX) { resX = inRaster.Raster.ResolutionX; } if (resY < inRaster.Raster.ResolutionY) { resY = inRaster.Raster.ResolutionY; } } int width = (int)(Math.Round(outEnv.Width / resX)); int height = (int)(Math.Round(outEnv.Height / resY)); string mapInfo = outEnv.ToMapInfoString(new Size(width, height)); RasterDataProvider outRaster = raster.Create(outFileName, width, height, 1, enumDataType.UInt16, mapInfo, "EXTHEADERSIZE=" + extHeaderLength) as RasterDataProvider; return(outRaster); }
protected IRasterDataProvider CreateOutRaster(string outFileName, RasterMaper[] inrasterMaper) { IRasterDataDriver raster = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver; CoordEnvelope outEnv = null; foreach (RasterMaper inRaster in inrasterMaper) { if (outEnv == null) { outEnv = inRaster.Raster.CoordEnvelope; } else { outEnv.Union(inRaster.Raster.CoordEnvelope); } } float resX = inrasterMaper[0].Raster.ResolutionX; float resY = inrasterMaper[0].Raster.ResolutionY; int width = (int)(Math.Round(outEnv.Width / resX)); int height = (int)(Math.Round(outEnv.Height / resY)); string mapInfo = outEnv.ToMapInfoString(new Size(width, height)); RasterDataProvider outRaster = raster.Create(outFileName, width, height, 1, enumDataType.Int16, mapInfo) as RasterDataProvider; return(outRaster); }
private void BuildCalcBuffer(string fileName) { IRasterDataDriver drv = GeoDataDriver.GetDriverByName("MEM") as IRasterDataDriver; _outputCalcDataProvider = drv.Create(fileName, vData.Width, vData.Height, 1, CalcType, GetOptions()); _outputCalcRasterBand = _outputCalcDataProvider.GetRasterBand(1); }
private void WriteData(float[] data, string fileName, int width, int height) { string[] options = new string[] { "INTERLEAVE=BSQ", "VERSION=LDF", "WITHHDR=TRUE", }; if (_outLdfDriver == null) { _outLdfDriver = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver; } IRasterDataProvider cacheWriter = _outLdfDriver.Create(fileName, width, height, 1, enumDataType.Float, options) as IRasterDataProvider; { using (IRasterBand band = cacheWriter.GetRasterBand(1)) { unsafe { fixed(float *ptr = data) { IntPtr bufferPtr = new IntPtr(ptr); band.Write(0, 0, width, height, bufferPtr, enumDataType.Float, width, height); } } } } _solarZenithCacheRaster = cacheWriter; }
public void OpenFile() { string fname = "d:\\1110910.1a5"; fname = @"H:\测试\测试数据\1a5\1110908.1a5"; IRasterDataDriver driver = GeoDataDriver.GetDriverByName("NOAA_1A5") as IRasterDataDriver; Assert.NotNull(driver); //IRasterDataProvider prd = driver.Open(fname, enumDataProviderAccess.ReadOnly) as IRasterDataProvider; IRasterDataProvider prd = GeoDataDriver.Open(fname) as IRasterDataProvider; Assert.NotNull(prd); Console.WriteLine(prd.BandCount.ToString()); Console.WriteLine(prd); //PrintHeaderInfo(prd); ID1A5DataProvider noaaPrd = prd as ID1A5DataProvider; Assert.NotNull(noaaPrd); D1A5Header header = noaaPrd.Header as D1A5Header; Assert.NotNull(header); Console.WriteLine(header.SatelliteIdentify); Console.WriteLine(header.BitErrorRatio); Console.WriteLine(header.DataBeginDayNums); Console.WriteLine(header.DataBeginMilliSecond); }
private IRasterBand WriteCacheFile(double[] data, string fileName, int width, int height, out IRasterDataProvider cacheWriter) { string[] options = new string[] { "INTERLEAVE=BSQ", "VERSION=LDF", "WITHHDR=TRUE", }; if (_outLdfDriver == null) { _outLdfDriver = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver; } cacheWriter = _outLdfDriver.Create(fileName, width, height, 1, enumDataType.Double, options) as IRasterDataProvider; IRasterBand band = cacheWriter.GetRasterBand(1); { unsafe { fixed(double *ptr = data) { IntPtr bufferPtr = new IntPtr(ptr); band.Write(0, 0, width, height, bufferPtr, enumDataType.Double, width, height); } } } return(band); }
public void ProcessArrayToRaster(string dstFileName, int[,] arrayValue) { CoordEnvelope envelope = new CoordEnvelope(-180, 180, -90, 90); IRasterDataProvider dataPrd = null; enumDataType dataType = enumDataType.Int16; try { if (Path.GetExtension(dstFileName).ToUpper() == ".DAT") { IRasterDataDriver driver = GeoDataDriver.GetDriverByName("MEM") as IRasterDataDriver; string mapInfo = envelope.ToMapInfoString(new Size(_datwidth, _datheight)); dataPrd = driver.Create(dstFileName, _datwidth, _datheight, 1, dataType, mapInfo); } else { return; } if (arrayValue == null) { return; } ProcessArrayToRaster(arrayValue, dataPrd); } finally { if (dataPrd != null) { dataPrd.Dispose(); } } }
private IRasterDataProvider CreateDstDataProvider(IRasterDataDriver driver, string outFile, IRasterDataProvider dataProvider) { ISpatialReference spatialRef = dataProvider.SpatialRef ?? new SpatialReference(new GeographicCoordSystem()); string spRef = "SPATIALREF=" + spatialRef.ToProj4String(); string mapInf = dataProvider.CoordEnvelope.ToMapInfoString(new Size(dataProvider.Width, dataProvider.Height)); return(driver.Create(outFile, dataProvider.Width, dataProvider.Height, 1, enumDataType.Float, spRef, mapInf, "WITHHDR=TRUE")); }
public void DeleteFile() { IRasterDataDriver drv = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver; string dstfname = "d:\\CreateCopy.ldf"; drv.Delete(dstfname); Assert.True(!File.Exists(dstfname)); }
/// <summary> /// 0、先生成目标文件,以防止目标空间不足。 /// 1、计算查找表 /// 2、对所有波段执行投影 /// </summary> private void ProjectToLDF(IRasterDataProvider srcRaster, FY3_VIRR_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 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) { //计算查找表 //ISpatialReference srcSpatialRef = srcRaster.SpatialRef; UInt16[] dstRowLookUpTable = new UInt16[dstSize.Width * dstSize.Height]; UInt16[] dstColLookUpTable = new UInt16[dstSize.Width * dstSize.Height]; _rasterProjector.ComputeIndexMapTable(_xs, _ys, srcSize, dstSize, dstEnvelope, _maxPrjEnvelope, out dstRowLookUpTable, out dstColLookUpTable, progressCallback); //执行投影 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}共{1}通道", i + 1, dstBandCount)); } BandMap bandMap = bandMaps[i]; ReadBandData(srcBandData, bandMap.File, bandMap.DatasetName, bandMap.BandIndex, srcSize); if (prjSettings.IsRadiation) { DoRadiation(srcBandData, srcSize, bandMap.DatasetName, bandMap.BandIndex, prjSettings.IsSolarZenith); } _rasterProjector.Project <UInt16>(srcBandData, srcSize, dstRowLookUpTable, dstColLookUpTable, dstSize, dstBandData, 0, progressCallback); 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); } } } } } } }
public void ReadAngleInfo() { string fname = "d:\\0111d2.n16.1bd"; IRasterDataDriver driver = GeoDataDriver.GetDriverByName("NOAA_1BD") as IRasterDataDriver; Assert.NotNull(driver); IRasterDataProvider prd = driver.Open(fname, enumDataProviderAccess.ReadOnly) as IRasterDataProvider; D1BDDataProvider dp = prd as D1BDDataProvider; }
public void OpenBSQFile_GDAL_FullSize() { IRasterDataDriver drv = GeoDataDriver.GetDriverByName("GDAL") as IRasterDataDriver; IRasterDataProvider prd = drv.Open(_fnameBSQ, enumDataProviderAccess.ReadOnly) as IRasterDataProvider;// OpenLdfFile(_fnameBSQ); Assert.Greater(prd.BandCount, 0); ReadOneBandByFullSize(prd, 1, "D:\\GDAL_LDF"); prd.Dispose(); }
private IRasterDataProvider CreateRaster(string outFileName, IRasterDataProvider inRaster) { IRasterDataDriver raster = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver; CoordEnvelope outEnv = inRaster.CoordEnvelope.Clone(); string mapInfo = outEnv.ToMapInfoString(new Size(inRaster.Width, inRaster.Height)); RasterDataProvider outRaster = raster.Create(outFileName, inRaster.Width, inRaster.Height, 1, enumDataType.Int16, mapInfo) as RasterDataProvider; return(outRaster); }
protected IRasterDataProvider CreateOutRaster(string outFileName, RasterMaper[] inrasterMaper, float resolution) { string dir = Path.GetDirectoryName(outFileName); if (!string.IsNullOrEmpty(dir)) { if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } } IRasterDataDriver raster = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver; CoordEnvelope outEnv = null; foreach (RasterMaper inRaster in inrasterMaper) { if (outEnv == null) { outEnv = inRaster.Raster.CoordEnvelope; } else { outEnv = outEnv.Union(inRaster.Raster.CoordEnvelope); } } float resX, resY; if (resolution != 0f) { resX = resolution; resY = resolution; } else { resX = inrasterMaper[0].Raster.ResolutionX; resY = inrasterMaper[0].Raster.ResolutionY; for (int i = 1; i < inrasterMaper.Length; i++) { if (resX > inrasterMaper[i].Raster.ResolutionX) { resX = inrasterMaper[i].Raster.ResolutionX; } if (resY > inrasterMaper[i].Raster.ResolutionY) { resY = inrasterMaper[i].Raster.ResolutionY; } } } int width = (int)(Math.Round(outEnv.Width / resX)); int height = (int)(Math.Round(outEnv.Height / resY)); string mapInfo = outEnv.ToMapInfoString(new Size(width, height)); RasterDataProvider outRaster = raster.Create(outFileName, width, height, 1, enumDataType.Int16, mapInfo) as RasterDataProvider; return(outRaster); }
public FY3_MERSIFileProjector() : base() { _name = "FY3_MERSI"; _fullname = "FY3_MERSI轨道数据投影"; _rasterProjector = new RasterProjector(); _srcSpatialRef = new SpatialReference(new GeographicCoordSystem()); _outLdfDriver = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver; _left = 10; _right = 10; }