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