Attempt to merge:

Better support for writing RATs #4903 (4903.7.diff):
 * 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
Fixes for #4903
Merge branch 'trunk-kx' of github.com:koordinates/gdal into trunk-kx

Conflicts:
	gdal/frmts/hfa/hfadataset.cpp
	gdal/frmts/hfa/hfaentry.cpp