GDAL raster output

I am trying to create a .tif file using GDAL in python. It creates a file, but saying "no preview" whenever I view it. Right now, I'm just trying to get him to make a copy of the input file. Here is my code:



 gdal.AllRegister() inDs = gdal.Open("C:\\Documents and Settings\\patrick\\Desktop\\tiff elevation\\EBK1KM\\color_a2.tif") if inDs is 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 and Settings\\patrick\\Desktop\\tiff elevation\\EBK1KM\\new.tif', cols, rows, 1, GDT_Int32) if outDs is 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 

code> ============================= update =================== == ===================== made some discoveries ... I learned how to convert from one format of numbers to another using statistical normalization. I processed the input and converted it to uint8 using the following algorithm:
 std = elev_data.std() #standard dev avg = elev_data.mean() arr = numpy.zeros((rows,cols),numpy.uint8) for _i_ in _range_(_rows_): for _j_ in _range_(_cols_): arr[i,j] = (((out_elev[i,j]-avg)/std)*127)+128 #normalization formula #this puts all vals in range 1 to 255 (uint8) dr = gdal.GetDriverByName("GTiff") outDs = dr.Create("name",cols,rows,3,GDT_Byte) #creates and RGB file, accepts uint8 for input outDs.GetRasterBand(1).WriteArray(arr) #write the output as shades of red #this writes out a format viewable by microsoft products 

The main reason I wanted to copy was to prove that I could read and then write the updated data based on the calculations.

What could be a way to output the output using a color ramp instead of shades of the same color?

+6
source share
2 answers

Do you mean that you get β€œNo Preview” from the Windows Picture and Fax Viewer when you try to view a TIFF file as an image? (See screenshot below.)

No preview available screenshot

Keep in mind that there are many different tastes of TIFF , and not all are the same. In particular, Windows Image and Fax Viewer does not support all TIFF types.

There is a Microsoft Knowledge Base article. You cannot view TIFF images using the Windows Image and Fax Viewer in particular:

The Windows Image and Fax Viewer in Windows XP uses the Windows GUI (GDI +). GDI + supports many standard compression algorithms for faxes. However, this may not be compatible with some coding schemes that are often not used.

If you are looking for a tool for viewing raster data (including GeoTIFF bitmaps), I would recommend the freely available OpenEV , which you can get as part of the FWTools package.

+2
source

A few things I notice:

  • You copy only one range of the original dataset. If it is a color image, it can have 3 stripes or a color map. If he has a color card, you also need to copy it. If it is 3 or 4 groups, you have to copy all the data.
  • CreateCopy() is an easier way to do what you are looking for.
+1
source

Source: https://habr.com/ru/post/892849/


All Articles