Better support for writing RATs, re #4903

Updated from 4903.7.diff to apply to latest trunk.
 * track thematic/athematic RAT type
 * Write RATs for Imagine/HFA output by default
 * Copy RATs during gdalwarp file-creation as well (if using nearest).
 * Copy RATs during gdal_translate VRT-path as well.
 * but, discard RATs if the operation makes them invalid