<div>Hello list:</div>
<div> </div>
<div>I developed a python script to create an excel, which collects some data from images with .tif, gtif, tiff, etc. When I run the module, it throws warnings related to the type of .tiff images, I think it is because the script doesn't make a difference between raster images and normal pictures. Does anyone have ain idea how to make a difference of tii images?</div>
<div>The python module:</div>
<div>import sys, os, time, socket, codecs<br>from xlwt import Workbook<br>from osgeo import gdal<br>from osgeo.gdalconst import *<br>from PIL import Image</div>
<div><br>#Register GDAL drivers<br>gdal.AllRegister()<br>file_list = []<br>folders = None<br>for root, folders, files in os.walk( "C:\\" ):<br> file_list.extend(os.path.join(root,fi) for fi in files if fi.endswith(".tif") or fi.endswith(".tiff") or fi.endswith(".gtif") or fi.endswith(".ecw") or fi.endswith(".bil"))<br>
wrkbk = Workbook()<br>wksht = wrkbk.add_sheet('raster') <br>wksht.row(0).write(0,'ruta')<br>wksht.row(0).write(1,'nombre')<br>wksht.row(0).write(2,'x_min')<br>wksht.row(0).write(3,'x_max')<br>
wksht.row(0).write(4,'y_min')<br>wksht.row(0).write(5,'y_max')<br>wksht.row(0).write(6,'ancho_pixel')<br>wksht.row(0).write(7,'alto_pixel')<br>wksht.row(0).write(8,'num_filas')<br>wksht.row(0).write(9,'num_columnas')<br>
wksht.row(0).write(10,'num_bandas')<br>wksht.row(0).write(11,'proyeccion')<br>wksht.row(0).write(12,'fecha_modificacion')<br>wksht.row(0).write(13,'maquina_host')<br>wksht.row(0).write(14,'usuario')<br>
for row, filepath in enumerate(file_list, start=1): <br> wksht.row(row).write(0, unicode(filepath,errors='ignore'))<br> (ruta, filename) = os.path.split(filepath) <br> wksht.row(row).write(1, unicode(filename,errors='ignore'))</div>
<div> dataset = gdal.Open(filepath, GA_ReadOnly)<br> if dataset is None:<br> print 'Could not open...' +filename<br> else:<br> xOrigin, yOrigin, pixelWidth, pixelHeight, a, b = dataset.GetGeoTransform()<br> geotransform = dataset.GetGeoTransform()<br>
x_min = geotransform[0]<br> wksht.row(row).write(2,x_min)<br> y_max = geotransform[3]<br> wksht.row(row).write(5,y_max)<br> pixel_width = geotransform[1]<br> wksht.row(row).write(6,pixel_width)<br> pixel_height = geotransform[5]<br>
wksht.row(row).write(7,pixel_height<br> rows = dataset.RasterYSize<br> cols = dataset.RasterXSize<br> bands = dataset.RasterCount<br> wksht.row(row).write(8,rows)<br> wksht.row(row).write(9,cols)<br> wksht.row(row).write(10,bands)<br>
y_min = y_max + cols*geotransform[4] + rows*pixel_height <br> x_max = x_min + cols*pixel_width + rows*geotransform[2]<br> wksht.row(row).write(3,x_max)<br> wksht.row(row).write(4,y_min)<br> n = os.path.splitext(filepath)<br>
tif = n[0]+'.tif'<br> tiff = n[0]+'.tiff'<br> gtif = n[0]+'.gtif'<br> ecw = n[0]+'.ecw'<br> bil = n[0]+'.bil'<br> if os.path.lexists(tif) or os.path.lexists(tiff) or os.path.lexists(gtif) or os.path.lexists(ecw) or os.path.lexists(bil):<br>
wksht.row(row).write(11, dataset.GetProjection()<br> else:<br> wksht.row(row).write(11, "No tiene proyeccion"<br> wksht.row(row).write(13, socket.gethostname())<br> wksht.row(row).write(14,os.environ.get("USERNAME"))<br>
<br> if os.path.lexists(filepath):<br> t = time.strftime("%m/%d/%Y %I:%M:%S %p",time.localtime(os.path.getmtime(filepath)))<br> wksht.row(row).write(12, t)<br> else:<br> wksht.row(row).write(12, 'No se encontro el archivo')</div>
<div>wrkbk.save('rasters.xls')</div>
<div> </div>
<div>The error that I got is:</div>
<div>Warning 1: TIFFReadDirectory:Unknown field with tag 2457 (0x999) encountered<br>Warning 1: TIFFReadDirectoryCheckOrder:Invalid TIFF directory; tags are not sorted in ascending order<br>Warning 1: TIFFReadDirectory:Unknown field with tag 2457 (0x999) encountered<br>
Warning 1: TIFFReadDirectoryCheckOrder:Invalid TIFF directory; tags are not sorted in ascending order<br>More than 1000 errors or warnings have been reported. No more will be reported from now.</div>
<div> </div>