Zhenyu Lu,<div><br></div><div>Gdal.Open() with GA_Update mode cannot be used to create new files. Instead</div><div>you will need to use the Create method on the driver object, and specify the</div><div>size, band count and other creation options. GA_Update in Gdal.Open()</div>
<div>is intended for use with existing files that you want to update (replace</div><div>imagery, or metadata). </div><div><br></div><div>Best regards,</div><div>Frank</div><div><br><div class="gmail_quote">On Wed, Aug 1, 2012 at 8:33 PM, Zhenyu Lu <span dir="ltr"><<a href="mailto:luzhenyu1981@gmail.com" target="_blank">luzhenyu1981@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><br clear="all">Hi Group,</div><div> </div><div>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):</div>
<div> /// <summary><br> /// Function of WriteData2File<br> /// </summary><br> /// <param name="LCx">the column index of left corner</param><br> /// <param name="LCy">the row index of left corner</param><br>
/// <param name="width">the width of the rectangle</param><br> /// <param name="height">the length of the rectangle</param><br> /// <param name="fileName">the fileName where the data will be saved</param><br>
/// <returns>true, if the data is added correctly, false otherwise.</returns></div><div> public bool WriteData2File(int LCx, int LCy, int width, int height, int band, byte[] Data, string fileName)<br>
{<br> OSGeo.GDAL.Driver imgDriver = OSGeo.GDAL.Gdal.GetDriverByName("GTiff");<br> string extension = System.IO.Path.GetExtension(fileName);<br> if (extension == ".img")<br>
imgDriver = OSGeo.GDAL.Gdal.GetDriverByName("HFA");<br> if (imgDriver == null)<br> throw new Exception("The file type is not supported!");<br> // OSGeo.GDAL.Gdal.AllRegister();<br>
<font color="#ff0000">OSGeo.GDAL.Dataset ds = OSGeo.GDAL.Gdal.Open(fileName, OSGeo.GDAL.Access.GA_Update);</font><br> int[] bandMap = new int[] { 1, 1, 1, 1 };<br> try<br> {<br>
ds.WriteRaster(LCx, LCy, width, height, Data, width, height, 1, bandMap, 0, 0, 0);<br> //ds.WriteRaster(LCx, LCy, width, height, Data, width, height, band, 0, 0, 0);<br> ds.Dispose();<br>
return true;<br> }<br> catch<br> {<br> return false;<br> }<br> }</div><div> </div><div>Can anyone point out where the problem is? Thank you so much,</div>
<span class="HOEnZb"><font color="#888888">
<div> </div><div><br>-- <br></div><div>Zhenyu Lu</div>
<div>SUNY-ESF</div><br>
</font></span><br>_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br>---------------------------------------+--------------------------------------<br>
I set the clouds in motion - turn up | Frank Warmerdam, <a href="mailto:warmerdam@pobox.com" target="_blank">warmerdam@pobox.com</a><br>light and sound - activate the windows | <a href="http://pobox.com/~warmerdam" target="_blank">http://pobox.com/~warmerdam</a><br>
and watch the world go round - Rush | Geospatial Software Developer<br><br>
</div>