Visualizing Data from Earth Engine¶
Overview¶
The Google Earth Engine plugin allows you to access Earth Engine datasets programmatically within QGIS using the Python Console. You can filter and pre-process the datasets using the Earth Engine Python API and then visualize the results as a WMS layer in QGIS. This enables you to quickly iterate and create visualizations without exporting large amounts of data from Earth Engine.
In this tutorial, we will use the NEX-GDDP-CMIP6: NASA Earth Exchange Global Daily Downscaled Climate Projections dataset and use the GEE Python API to create a Map layer of mean maximum daily temperature for a chosen year under a chosen model and scenario. We will then load and visualize this layer in QGIS on a globe.
Procedure¶
-
Open the QGIS Python Consolve from Plugins → Python Console.
-
The Python Console allows you to write, edit and run Python scripts in QGIS. Click the Show Editor button to open the Editor panel.
-
Once the Google Earth Engine plugin has been installed, you are able to access the EE Python API by importing the
ee
module in the Python Console. The plugin also adds functions from theMap
module to load EE data layers in QGIS canvas. Copy/paste the following block of code in the editor and click the Run Script button. If the script runs without any errors - it means the plugin has been installed and configured correctly. If you get any errors, follow the Installation Guide to install and configure the Google Earth Engine plugin.import ee from ee_plugin import Map
-
We can now write code to access the
NASA/GDDP-CMIP6
ImageCollection, apply a filter to select the images for the chosen band, year, model and scenario, convert the units from Kelvin to Celcius and calculate the mean annual values. All of this processing is done on the Earth Engine servers. Once we are ready to visualize the results, we use theMap.addLayer()
function to add the results to QGIS. Copy/paste the code below into your Python Console Code Editor and click Run Script. A new layertasmax_2030_ACCESS-CM2_ssp245
will be added to the Layers panel. This is a WMS layer that is streaming tiles from the Earth Engine servers.import ee from ee_plugin import Map # Use the CMIP6 Climate Projections Dataset cmip6 = ee.ImageCollection(`'NASA/GDDP-CMIP6'`) # Select a model and a scenario model = 'ACCESS-CM2' scenario = 'ssp245' # Select the band # Here we are using maximum air temperature band = 'tasmax' # Select the year year = 2030 startDate = ee.Date.fromYMD(year, 1, 1) endDate = startDate.advance(1, 'year') filtered = cmip6 \ .filter(ee.Filter.date(startDate, endDate)) \ .filter(ee.Filter.eq('model', model)) \ .filter(ee.Filter.eq('scenario', scenario)) \ .select(band) # Temperature values are in Kelvin # convert to Celcius def scaleValues(image): return image \ .subtract(273.15) \ .copyProperties(image, ['system:time_start', 'model', 'scenario']) scaled = filtered.map(scaleValues) # Calculate average daily maximum temperature mean = scaled.mean() tempVis = { 'min': 10, 'max': 40, 'palette': ['blue', 'purple', 'cyan', 'green', 'yellow', 'red'], } layer_name = f'{band}_{year}_{model}_{scenario}' Map.addLayer(mean, tempVis, layer_name)
-
A global layer like this is best visualized on a globe. We will use another QGIS plugin named Globe Builder to create a custom orthographic projection for rendering this layer. You can close the Python Console and go to Plugins → Manage and Install Plugins, switch to the All tab and search for the Globe Builder plugin. Click Install Plugin.
-
Once the plugin is installed, launch it from Plugins → Globe Builder → Build Globe view.
-
In the Globe Builder panel, you have an option to opverlay various global data layers and/or graticule layers. For this tutorial, we don't need them, so uncheck all the data sources. Select
Azimuthal Orthographic
as the Projection. -
Scroll down and in the Center the Globe based on: section, choose the Coordinates option. Enter coordinates
0, 30
. This will create a cutom orthographic projection centered at these coordinates. -
Lastly, under the Visualization section, choose
White
as the Background color. Once done, click the Add the Globe to a Map button. -
The plugin will set the Project CRS to a custom projection based on your configuration. The Earth Engine layer will request new tiles from the server in this projection and they will be rendered as a globe.