public HdrFile ToHdrFile() { HdrFile hdrContent = _header.ToHdrFile(); hdrContent.HdrProjectionInfo = GetHdrProjectionInfo(); hdrContent.MapInfo = GetHdrMapInfo(); return(hdrContent); }
public override IRasterDataProvider Create(string fileName, int xSize, int ySize, int bandCount, enumDataType dataType, params object[] options) { ISpatialReference spatialRef; CoordEnvelope coordEnvelope; bool isWithHdr; int extHeaderSize = 0; HdrMapInfo mapInfo; ParseOptions(xSize, ySize, options, out spatialRef, out coordEnvelope, out mapInfo, out isWithHdr, out extHeaderSize); MemoryRasterHeader h = GetHeader(spatialRef, coordEnvelope); h.BandCount = bandCount; h.DataType = (int)dataType; h.Width = xSize; h.Height = ySize; h.ExtendHeaderLength = extHeaderSize; byte[] headerBytes = new byte[1024]; using (FileStream fs = new FileStream(fileName, FileMode.Create)) { int headerSize = Marshal.SizeOf(typeof(MemoryRasterHeader)); byte[] buffer = new byte[headerSize]; GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); Marshal.StructureToPtr((object)h, handle.AddrOfPinnedObject(), true); handle.Free(); fs.SetLength(headerSize + extHeaderSize + (long)xSize * (long)ySize * (long)bandCount * (long)DataTypeHelper.SizeOf(dataType)); fs.Write(buffer, 0, buffer.Length); fs.Seek(0, SeekOrigin.Begin); fs.Read(headerBytes, 0, (int)Math.Min(headerBytes.Length, fs.Length)); } HdrFile hdrFile = h.ToHdrFile(); if (spatialRef != null) { hdrFile.HdrProjectionInfo = GetHdrProjectionInfo(spatialRef); } if (mapInfo != null) { hdrFile.MapInfo = mapInfo; } hdrFile.SaveTo(HdrFile.GetHdrFileName(fileName)); IGeoDataProvider provider = BuildDataProvider(fileName, headerBytes, enumDataProviderAccess.Update, options); return(provider as IRasterDataProvider); }