Imaging geophysical data in QGIS2threejs

The QGIS2threejs plugin is an excellent, lightweight utility for the visualisation of surface data such as DEM. But what if your workflow requires the interpretation and visualisation of geophysical data? Fortunately there are a few simple tricks you can perform in QGIS and with this plugin to easily visualise other gridded data types. You can also add legends to create publication-quality 3D images.

Imaging geophysical data

First you’ll need to load your geophysical data by adding them as rasters. Spend a bit of time imaging your data in the Layer Styling panel. One really good way to visualise your geophysical data is by making a colourdrape image:

  1. Duplicate your geophysics raster
  2. Apply a hillshade to the lowest in the layer menu (if this doesn’t shade very well it is because your data is dissimilar from typical elevation – just fiddle the Z-scale until you are happy)
  3. Apply a singleband pseudocolour stretch to the top layer in the Layer Styling panel
  4. Then scroll down in the Layer Styling panel to the Layer Rendering menu and change it from “normal” to something you are happy with (overlay and burn work quite well but you will usually need to make adjustments to the contrast and brightness)

Depending on the size of your data and the area you want to focus on you may need to clip extent to canvas on your top layer so that there is a good stretch through your colourtable. This is important for close-ups of your data.

BA_clippedBA_minmax
When you “clip extent to canvas” the full colourtable is stretched across the area of interest providing a better contrast between features and anomalies. Use the slider to compare.

When you are happy with the layer styling of your geophysical data and ready to export the 3D model try the following:

  1. Install the QGIS2threejs plugin
  2. Ensure that the geophysical image  you wish to have in your model is displayed in the map window with the appropriate styling
  3. Start the plugin from the menu Web>QGIS2threejs>QGIS2threejs or by clicking the icon
  4. Adjust the vertical exaggeration beneath Scale and Shift in the World tab. As the QGIS2threejs plugin assumes the model space is always built with respect to a DEM (elevation model in metres) any raster with values significantly different from typical Earth surface values will cause the 3D model to be non-useful. The amount of vertical exaggeration will depend on your data and could range from 0.1 to 200 for a useful model. DOn’t expect to get it right the first time and if you need a second crack the plugin thankfully saves the last-used parameters
  5. Within the DEM menu select the geophysical raster that you wish to view in 3D and make sure that under Display Type you select Map Canvas Image so that all your hard work creating a decent image will be exported to the 3D model
  6. Choose your HTML output path (where all the model and javascript files are exported to)
  7. Press Run!

There are a number of other things the QGIS2threejs plugin can do, but that’s really all there is to making a quick 3D visualisation. If you want to know how to create a custom legend that can be viewed in the 3D model read on…

QGISthreejs_Export Fig

QGIS2threejs plugin pop-up window to control the parameters of your 3D model export

Creating a legend image in QGIS Print Composer

Legends are very important as they quantify your model. The QGIS2threejs plugin doesn’t have this functionality built in yet. But if you want to add a legend to your 3D model try the following workaround:

  1. Open the QGIS print composer
  2. Add the map you wish to model to the print composer by clickingAdd Map to composer iconMap composer and legend
    The Print Composer window showing the map area with imaged geophysical data and a default legend for the raster image
  3. Add a Legend to the print composer by clicking  Legend icon. If you are happy with the discrete intervals and formatting of the defined by default then just check the legend title and units. These can be changed by selecting the Legend item in the Item Properties panel and clicking Edit Histogram icon.  If you are going to be changing any legend properties ensure that auto-update is switched off.

Alternatively you can create your own continuous legend using a rectangle with a gradient fill:

  1. Add a shapeAdd shape to composer icon to the composer  and select “Add Rectangle”.
  2. Decide on the size and ratio of your shape
  3. Select the rectangle to change its properties in the Item Properties panel
  4. Change fill style to Gradient Fill
  5. Choose the colour ramp for your legend that matches the ramp you have used to image your geophysical data. If you have used a predefined colour ramp for your geophysical imaging within the map window then choose the same colour ramp for your gradient fill. If not then you will need to customise your own ramp by clicking on the Edit button
  6. Add stops to your gradient colour ramp using the excellent range of colour palettes

Edit gradient fill Fig

Object style properties window (left) and gradient colour ramp editing window (right)

To make your colours accurate go back to the QGIS map window and select Properties for your raster layer. In the style menu you will be able to copy the HTML values (e.g. #31007e) for each colour then use these as stops in your gradient fill. Alternatively you can use the colour picker Colourpicker iconjust make sure that the layers legend is visible when you open the gradient ramp editor.

Final Gradient Colourmap

Gradient colour ramp editing window showing a number of stops, each correponding to the discrete colours in the default legend selected using the colour picker tool

FInal Colour Gradient legend

Final colour gradient legend with title, units and simplified scale

When you are happy with your legend you will need to export it as an image to be incorporated into the 3D model:

  1. Export the image by going to Composer>Export as image
  2. Choose your desired resolution and select your file path, filename and file type
  3.  Before clicking Save make sure you select the Crop to content box as this will save the hassle of cropping your legend later
  4. Click Save

Image export

Options for exporting your legend as an image from the Print Composer

Add the legend to the QGIS2threejs model

This is the tricky part and will require a bit of testing before you get it how you want the first time:

  1. Track down the folder with all the files that were exported from QGIS2threejs (Or alternatively just export it your model again making sure you check the HTML file path at the bottom of the Plugin pop-up window
  2. Copy your legend image file into the 3D model folder that you defined when exporting from QGIS2threejs
    QGISthreejs_Export Fig_VerticalExagg
    QGIS2threejs plugin pop-up window again – showing the HTML file output path
  3. Open the .html file in text editing software (something like Wordpad works well)
  4. Within the <HEAD> add the position, size and source for your legend. What is shown below works quite well. But make sure that you copy the legend image into the same directory as the other QGIS2threejs files!
    html additions for legend
    The head of the HTML file exported by QGIS2threejs for your model. Highlighted text shows simple format for adding your legend to the 3D model space
  5. Save your file from within the text editor (you may need to save it as a .txt but you can manually change the file extension back to .html after)
  6. Open the html file for your model and be amazed (or disappointed). If the latter then go back into the .html file and adjust the image size and position

To make this look really good try matching the background of the legend with the 3D viewer background. You can do this in by matching the Hex code in both the .html file and in the Print Composer background

Leave a Reply

Your email address will not be published.