python - GDAL Raster Output -



python - GDAL Raster Output -

i'm trying create .tif file using gdal in python. it's creating file, saying "no preview available" whenever browse it. right now, i'm trying create re-create of input file. here's code:

gdal.allregister() inds = gdal.open("c:\\documents , settings\\patrick\\desktop\\tiff elevation\\ebk1km\\color_a2.tif") if inds none: print 'could not open image file' sys.exit(1) else: print "successfully opened input file" rows = inds.rasterysize cols = inds.rasterxsize myband = inds.getrasterband(1) elev_data = myband.readasarray(0,0,cols,rows) driver = inds.getdriver() outds = driver.create('c:\\documents , settings\\patrick\\desktop\\tiff elevation\\ebk1km\\new.tif', cols, rows, 1, gdt_int32) if outds none: print "couldn't open output file" sys.exit(1) outband = outds.getrasterband(1) outdata = numpy.zeros((rows,cols),numpy.int16) outband.writearray(elev_data) outband.flushcache() outband.setnodatavalue(-99) outds.setgeotransform(inds.getgeotransform()) outds.setprojection(inds.getprojection()) del outdata

============================update========================================= made discoveries... i've studied ways of converting 1 number format using statistical normalization. processed input info , transformed uint8 using next algorithm:

std = elev_data.std() #standard dev avg = elev_data.mean() arr = numpy.zeros((rows,cols),numpy.uint8) _i_ in _range_(_rows_): _j_ in _range_(_cols_): arr[i,j] = (((out_elev[i,j]-avg)/std)*127)+128 #normalization formula #this puts vals in range 1 255 (uint8) dr = gdal.getdriverbyname("gtiff") outds = dr.create("name",cols,rows,3,gdt_byte) #creates , rgb file, accepts uint8 input outds.getrasterband(1).writearray(arr) #write output shades of reddish #this writes out format viewable microsoft products

the main reason wanted re-create prove read in, write out updated info based on calculations.

what might way write out output info using color ramp, instead of shades of 1 color?

do mean you're getting "no preview available" windows image , fax viewer application when trying preview tiff file image? (see below screenshot.)

bear in mind there many different flavors of tiff, , not same. in particular, windows image , fax viewer not back upwards kinds of tiffs.

there microsoft knowledge base of operations article you cannot view tiff images using windows image , fax viewer says in part:

windows image , fax viewer in windows xp uses windows graphics device interface (gdi+). gdi+ supports many standard compression algorithms faxes. however, may incompatible of encoding schemes not used frequently.

if you're looking tool viewing raster info (including geotiff rasters), i'd recommend freely available openev, can part of fwtools package.

python io arcgis raster gdal

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -