James,<br><br>You can use the GDALDriver::CreateCopy() method to translate a dataset if you don't plan to perform any reprojection during translation.<br>If you don't need the intermediate geotiff file, you can look at the ogr2ogr.py [0] script to perform the reprojection and translation in one go.<br>
<br>[0] <a href="http://trac.osgeo.org/gdal/browser/trunk/gdal/swig/python/samples/ogr2ogr.py">http://trac.osgeo.org/gdal/browser/trunk/gdal/swig/python/samples/ogr2ogr.py</a><br><br><div class="gmail_quote">On Wed, Jan 19, 2011 at 6:56 AM, manzione <span dir="ltr"><<a href="mailto:james.j.manzione@usace.army.mil">james.j.manzione@usace.army.mil</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><br>
Greetings and thank you for looking at my post,<br>
<br>
I am converting a Grib2 file into a geo tiff file and then reprojecting it<br>
in python. When I reproject the tiff file it states it is "unable to<br>
compute a transformation between pixel/line and georeferenced coordinates"<br>
for my converted tiff file because "there is no affine transformation and no<br>
GCPs."<br>
<br>
I ran some tests and am under the assumption that my script is not embedding<br>
any georefferencing information into the tiff file. Any suggestions on how<br>
to do this? I am new to gdal and could use the help. Below is my code for<br>
the conversion.<br>
<br>
Thank you in advance for your advice,<br>
-James<br>
<br>
Script:<br>
<br>
dataset = gdal.Open( Rpath, GA_ReadOnly )<br>
<br>
xsize = dataset.RasterXSize<br>
ysize = dataset.RasterYSize<br>
pixels = xsize * ysize<br>
<br>
num_bands = dataset.RasterCount<br>
for band_num in range(1, num_bands + 1):<br>
band = dataset.GetRasterBand(band_num)<br>
meta = band.GetMetadata()<br>
bandName = str(meta['GRIB_COMMENT'].split()[0])<br>
tiffImagePath = str(pngPath + bandName + '.tiff')<br>
<br>
ct = color_table(str(table))<br>
<br>
buf = dataset.ReadRaster( 0, 0, xsize, ysize, None, None, None, [<br>
band_num ] )<br>
outBand = tiff.Create( tiffImagePath, xsize, ysize, 1, GDT_Byte)<br>
if outBand is None:<br>
sys.exit(1)<br>
<br>
outBand.GetRasterBand(1).SetRasterColorTable(ct)<br>
outbuf = []<br>
<br>
for offset in range(0, pixels):<br>
val = int(struct.unpack_from('d', buf, offset * 8)[0])<br>
if val > 255: val = 255<br>
if val < 0: val = 0<br>
outbuf.append('%c' % val)<br>
buffo = ''.join(outbuf)<br>
outBand.WriteRaster( 0, 0, xsize, ysize, buffo, xsize, ysize,<br>
GDT_Byte )<br>
<font color="#888888"><br>
--<br>
View this message in context: <a href="http://osgeo-org.1803224.n2.nabble.com/Grib2-band-to-Geo-Tiff-tp5937919p5937919.html" target="_blank">http://osgeo-org.1803224.n2.nabble.com/Grib2-band-to-Geo-Tiff-tp5937919p5937919.html</a><br>
Sent from the GDAL - Dev mailing list archive at Nabble.com.<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>
</font></blockquote></div><br><br clear="all"><br>-- <br>Best regards,<br>Chaitanya kumar CH.<br>/tʃaɪθənjə/ /kʊmɑr/ <br>+91-9494447584<br>17.2416N 80.1426E<br>