KML was originally designed for vector data (points/lines/polygons), and many software tools will only export vector data as KML, which is why you don't always see the option in QGIS. In this case, it sounds like you want to get a raster dataset into KML for viewing in Google Earth. This can be done using a feature called Image Overlay (or in KML terms: GroundOverlay), which takes an image file and defines where on the globe it should be positioned. You should be able to create this by exporting a GeoTiff (image file with embedded coordinate data) from QGIS, and importing it into Google Earth Pro, which will convert to KML (or KMZ) for you.
- Import your DTM data as a raster layer and style it as you wish.
- Right-click on the layer and select Export > Save As to bring up the dialog titled "Save Raster Layer as...".
- Select Output mode: Rendered Image. (IMPORTANT - this creates the 3-band RGB image needed by Earth)
- Format: GeoTiff
- File name: Choose a name and location to save to.
- CRS: "EPSG:4326 - WGS 84". See note on projections below.
- Extent: use the default extent of layer, unless you want to set it differently.
- Resolution: usually use the defaults. Select Columns if you want to set the exact pixel height and width of the image if desired. See note on sizes below.
- No data values: you may need to set these if you have areas of no data that you wish to keep as transparent in the image. This can be tricky, but try it if needed.
- Save the GeoTiff to your computer.
In Google Earth Pro...
- Import the GeoTiff into Earth Pro. Use File > Open or File > Import, and select the filetype "GeoTIFF". If you use drag & drop to import (usually faster), then make sure that the import dialog that comes up is for a "New Image Overlay" and not for a "New Photo Overlay". If it tries to create a Photo Overlay, then your GeoTiff file does not contain correct georeferencing info.
- If your image is bigger than a certain size, then Earth will provide options to import just a part of it, or to create a "KML SuperOverlay". See note on image sizes below.
- In the "New Image Overlay" dialog, edit the name, transparency, description, and any other settings you wish to change.
- Click OK to create your image overlay, which will appear as a new item in your Places list.
If you wish to save & share the KML/KMZ file...
- If you created a single image overlay, and not a SuperOverlay, then right-click on the item in your Places list and select "Save Place As..."
- In the save dialog, select file type KMZ, give it a file name & location, and save to your computer. A KMZ is a compressed zip archive that bundles together the necessary KML as well as the image file, making it easy to share and open in Earth.
- If you created a SuperOverlay, it's harder to share, as you'll need to find where it saved it on your hard drive, and copy/share the entire folder.
Note on projections - It shouldn't matter what projection your QGIS Project and data layer use, so long as you export to "EPSG:4326 - WGS 84". But if you see any projection or positioning issues in Earth, then it's best to do all this with both the dataset and project coordinate reference systems set to WGS84 (EPSG:4326). I almost always set my project and re-project my data to EPSG:4326 to avoid unexpected projection issues.
Notes on image sizes, superoverlays, etc. - Google Earth can only overlay images up to a certain size, depending on the graphics capacity of your computer. To see the max size in Earth Pro, go to Help menu > About Google Earth, and look for "Maximum Texture Size". Most machines will support around 4096x4096 or 8192x8192 pixels max, though some will support higher. Older/weaker machines may only support upto 2048x2048 pixel images. So if you want to make sure that anyone can view your KML/KMZ, then you'll want to limit the image size to 2048 max dimension, though for most modern machines, 4096 should be fine. You can control the image size when exporting from QGIS, though be aware that reducing from the defaults may make your image in Earth lower resolution than the original data. Now, when you import, Earth will detect the image size, and if it's too big, it will offer some options:
- Crop: this will let you import just a part of the image, but at full resolution. This is good for testing what the full res looks like. It creates a standard, single-image Image Overlay KML.
- Scale: this will import the full image but will scale it down to a reasonable size, so you will loose resolution. This creates a standard, single-image Image Overlay KML.
- Create Super Overlay... - This will take your large image and chop it up into tiles, with one low res tile to display when zoomed out, four tiles at the next zoom/resolution level, and continuing in a pyramid of tiles down to the full resolution tiles at the bottom. Viewing it in Earth, everything works automatically to load just the correct tiles (necessary location and zoom/resolution) for the place & zoom you're looking at. It does this with a folder of folders containing pairs of KML files and images for each tile. This is a powerful tool, but is harder to share or incorporate into other Earth/KML projects.
Hope that helps. Good luck!