[gdal-dev] Error in OSGeo.GDAL.Gdal.Open for .tif format
Zhenyu Lu
luzhenyu1981 at gmail.com
Wed Aug 1 20:33:10 PDT 2012
Hi Group,
I just encountered an error in writting data to image in GTiff format using
the OSGeo.GDAL.Gdal.Open command. The error message showing is "****.tif
not recognised as a supported file format". The gdal librarary I am using
is gdal19dev.dll. The weird thing is the Gdal.Open command worked if the
image is in the format of HFA. The C# code I used to implement the writting
process is attached below (the sentence where error happened was
highlighted in red):
/// <summary>
/// Function of WriteData2File
/// </summary>
/// <param name="LCx">the column index of left corner</param>
/// <param name="LCy">the row index of left corner</param>
/// <param name="width">the width of the rectangle</param>
/// <param name="height">the length of the rectangle</param>
/// <param name="fileName">the fileName where the data will be
saved</param>
/// <returns>true, if the data is added correctly, false
otherwise.</returns>
public bool WriteData2File(int LCx, int LCy, int width, int height,
int band, byte[] Data, string fileName)
{
OSGeo.GDAL.Driver imgDriver =
OSGeo.GDAL.Gdal.GetDriverByName("GTiff");
string extension = System.IO.Path.GetExtension(fileName);
if (extension == ".img")
imgDriver = OSGeo.GDAL.Gdal.GetDriverByName("HFA");
if (imgDriver == null)
throw new Exception("The file type is not supported!");
// OSGeo.GDAL.Gdal.AllRegister();
OSGeo.GDAL.Dataset ds = OSGeo.GDAL.Gdal.Open(fileName,
OSGeo.GDAL.Access.GA_Update);
int[] bandMap = new int[] { 1, 1, 1, 1 };
try
{
ds.WriteRaster(LCx, LCy, width, height, Data, width,
height, 1, bandMap, 0, 0, 0);
//ds.WriteRaster(LCx, LCy, width, height, Data, width,
height, band, 0, 0, 0);
ds.Dispose();
return true;
}
catch
{
return false;
}
}
Can anyone point out where the problem is? Thank you so much,
--
Zhenyu Lu
SUNY-ESF
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20120801/80e34603/attachment.html>
More information about the gdal-dev
mailing list