Difference between revisions of "Integrating Google Earth Engine with QGIS"
| (12 intermediate revisions by the same user not shown) | |||
| Line 3: | Line 3: | ||
==Connecting Google Earth Engine to QGIS== |
==Connecting Google Earth Engine to QGIS== |
||
| + | === Installing Plugins=== |
||
To connect Google Earth Engine to QGIS you will need to download the plugin. Open QGIS navigate to Plugins > Manage and Install plugins and then scroll down or search for Google Earth Engine and Google Earth Engine Data Catalog. |
To connect Google Earth Engine to QGIS you will need to download the plugin. Open QGIS navigate to Plugins > Manage and Install plugins and then scroll down or search for Google Earth Engine and Google Earth Engine Data Catalog. |
||
| Line 12: | Line 13: | ||
| + | === Connecting your Google Earth Engine Account=== |
||
Once the plugins are installed you can connect your Google Earth Engine account to your QGIS project. Navigate to the GEE button at the top of the screen, and select sign in, this will take you to a web page that asks you so sign in to your google account and link your project. |
Once the plugins are installed you can connect your Google Earth Engine account to your QGIS project. Navigate to the GEE button at the top of the screen, and select sign in, this will take you to a web page that asks you so sign in to your google account and link your project. |
||
Once you approve the connection you’ll need to connect the Earth Engine project you wish to work from. If you haven’t set up an Earth Engine project you can learn how to do so here(LINK). |
Once you approve the connection you’ll need to connect the Earth Engine project you wish to work from. If you haven’t set up an Earth Engine project you can learn how to do so here(LINK). |
||
| Line 19: | Line 21: | ||
| + | ===Connecting a Google Earth Engine Project=== |
||
Once you've authenticated you Google Earth Engine account you will be prompted to connect QGIS to an Earth engine project. |
Once you've authenticated you Google Earth Engine account you will be prompted to connect QGIS to an Earth engine project. |
||
[[File:Connect to gee project.png|500px|thumb|none|Project Connection Window]] |
[[File:Connect to gee project.png|500px|thumb|none|Project Connection Window]] |
||
| + | |||
==Using Google Earth Engine within QGIS== |
==Using Google Earth Engine within QGIS== |
||
| − | Now that your account and projects have been connected you can begin to use GEE. We’ll explore the data catalog first. |
+ | Now that your account and projects have been connected you can begin to use GEE. We’ll explore the data catalog first. |
| + | ===Google Earth Engine Data Catalog=== |
||
| + | Click the data catalog button at the top of the screen in QGIS |
||
| Line 41: | Line 47: | ||
Once you have an image in QGIS you can manipulate it as you would if you had downloaded the image from any other data provider. |
Once you have an image in QGIS you can manipulate it as you would if you had downloaded the image from any other data provider. |
||
| + | ===Google Earth Engine=== |
||
| − | While the data catalog is incredibly useful Google Earth Engine much more powerful than just a data provider. If you have used GEE before and have scripts that you have run in another environment such as Jupyter notebooks or google colab you can also run them in QGIS through the python console / code editor. |
||
| + | While the data catalog is incredibly useful you are limited in that you can only import images and not whole image collections or feature datasets. To import image collections or feature collections, click on the Earth Engine Plugin and navigate to Add Layer. |
||
| + | |||
| + | [[File:Add Layer from GEE.png|500px|thumb|none|Add a layer from Google Earth Engine]] |
||
| + | |||
| + | |||
| + | Google Earth Engine much more powerful than just a data provider, if you have used GEE before and have scripts that you have run in another environment such as Jupyter notebooks or google colab you can run them in a similar way within QGIS through the python console / code editor. |
||
| + | |||
==Use Case Examples== |
==Use Case Examples== |
||
| + | ===Running Climate Models=== |
||
The following code can be used to run a climate prediction model and map the mean air temperature across the globe in the year 2030. All the computing is done with GEE servers and the result is displayed within QGIS. |
The following code can be used to run a climate prediction model and map the mean air temperature across the globe in the year 2030. All the computing is done with GEE servers and the result is displayed within QGIS. |
||
| − | (Imbed Code File) |
||
| + | <syntaxhighlight lang="python"> |
||
| − | (IMAGE) |
||
| + | |||
| + | 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) |
||
| + | </syntaxhighlight> |
||
| + | |||
| + | |||
| + | |||
| + | [[File:Climate model code results.png|500px|thumb|none|Climate model code results]] |
||
| + | |||
| + | |||
| + | |||
| + | ===Classifications=== |
||
| + | Large scale classifications is one advantage of using a cloud computing service such as Google Earth Engine. The datasets and area that the classification is applied to can be very large and will run very quickly. |
||
| + | |||
| + | ====Unsupervised Classification==== |
||
| + | The following code will run an unsupervised classification centered on Europe but will continue to classifiy as you zoom out or scroll around the map (with reduced accuracy as the classification was trained on data with the extent shown below). |
||
| + | |||
| + | <syntaxhighlight lang="python"> |
||
| + | import ee |
||
| + | from ee_plugin import Map |
||
| + | |||
| + | # Load a pre-computed Landsat composite for input. |
||
| + | input = ee.Image('LANDSAT/LE7_TOA_1YEAR/2001') |
||
| + | |||
| + | # Define a region in which to generate a sample of the input. |
||
| + | region = ee.Geometry.Rectangle(29.7, 30, 32.5, 31.7) |
||
| + | |||
| + | # Display the sample region. |
||
| + | Map.setCenter(31.5, 31.0, 8) |
||
| + | Map.addLayer(ee.Image().paint(region, 0, 2), {}, 'region') |
||
| + | |||
| + | # Make the training dataset. |
||
| + | training = input.sample(**{ |
||
| + | 'region': region, |
||
| + | 'scale': 30, |
||
| + | 'numPixels': 5000 |
||
| + | }) |
||
| + | |||
| + | # Instantiate the clusterer and train it. |
||
| + | clusterer = ee.Clusterer.wekaKMeans(15).train(training) |
||
| + | |||
| + | # Cluster the input using the trained clusterer. |
||
| + | result = input.cluster(clusterer) |
||
| + | |||
| + | # Display the clusters with random colors. |
||
| + | Map.addLayer(result.randomVisualizer(), {}, 'clusters') |
||
| + | </syntaxhighlight> |
||
| + | |||
| + | |||
| + | [[File:Unsupervised Classification Results.png|500px|thumb|none|Unsupervised Classification Results]] |
||
| + | |||
| + | ==Conclusions & Resources== |
||
| + | Google Earth Engine is an extremely powerful tool that can be used to work with large datasets and spatial extents. By integrating it with QGIS we have a friendly graphical user interface that can be used by beginner or advanced users. |
||
Latest revision as of 12:44, 2 December 2025
Contents
Introduction
This tutorial will walk you through how to integrate Google Earth Engine with QGIS. QGIS is a more traditional GIS with a graphical user interface, to learn more about QGIS and how to install it go here (LINK). Google Earth Engine is a cloud computing platform that houses large datasets of satellite imagery and where large scale processes run. A free account is needed to use Google Earth Engine, to learn more about GEE and how to set up your account go (HERE).
Connecting Google Earth Engine to QGIS
Installing Plugins
To connect Google Earth Engine to QGIS you will need to download the plugin. Open QGIS navigate to Plugins > Manage and Install plugins and then scroll down or search for Google Earth Engine and Google Earth Engine Data Catalog.
Connecting your Google Earth Engine Account
Once the plugins are installed you can connect your Google Earth Engine account to your QGIS project. Navigate to the GEE button at the top of the screen, and select sign in, this will take you to a web page that asks you so sign in to your google account and link your project. Once you approve the connection you’ll need to connect the Earth Engine project you wish to work from. If you haven’t set up an Earth Engine project you can learn how to do so here(LINK).
Connecting a Google Earth Engine Project
Once you've authenticated you Google Earth Engine account you will be prompted to connect QGIS to an Earth engine project.
Using Google Earth Engine within QGIS
Now that your account and projects have been connected you can begin to use GEE. We’ll explore the data catalog first.
Google Earth Engine Data Catalog
Click the data catalog button at the top of the screen in QGIS
This opens the data catalog window. You can now choose the imagery dataset you wish to use (sentinel2, Landsat, ect.) you can also choose which bands you want to use including true colour, false colour, NDVI, EVI, and many others. You can also set the date range, maximum cloud coverage, and the number of images you want (the max is 20). The default extent it the viewing window within QGIS.
Once you have an image in QGIS you can manipulate it as you would if you had downloaded the image from any other data provider.
Google Earth Engine
While the data catalog is incredibly useful you are limited in that you can only import images and not whole image collections or feature datasets. To import image collections or feature collections, click on the Earth Engine Plugin and navigate to Add Layer.
Google Earth Engine much more powerful than just a data provider, if you have used GEE before and have scripts that you have run in another environment such as Jupyter notebooks or google colab you can run them in a similar way within QGIS through the python console / code editor.
Use Case Examples
Running Climate Models
The following code can be used to run a climate prediction model and map the mean air temperature across the globe in the year 2030. All the computing is done with GEE servers and the result is displayed within QGIS.
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)
Classifications
Large scale classifications is one advantage of using a cloud computing service such as Google Earth Engine. The datasets and area that the classification is applied to can be very large and will run very quickly.
Unsupervised Classification
The following code will run an unsupervised classification centered on Europe but will continue to classifiy as you zoom out or scroll around the map (with reduced accuracy as the classification was trained on data with the extent shown below).
import ee
from ee_plugin import Map
# Load a pre-computed Landsat composite for input.
input = ee.Image('LANDSAT/LE7_TOA_1YEAR/2001')
# Define a region in which to generate a sample of the input.
region = ee.Geometry.Rectangle(29.7, 30, 32.5, 31.7)
# Display the sample region.
Map.setCenter(31.5, 31.0, 8)
Map.addLayer(ee.Image().paint(region, 0, 2), {}, 'region')
# Make the training dataset.
training = input.sample(**{
'region': region,
'scale': 30,
'numPixels': 5000
})
# Instantiate the clusterer and train it.
clusterer = ee.Clusterer.wekaKMeans(15).train(training)
# Cluster the input using the trained clusterer.
result = input.cluster(clusterer)
# Display the clusters with random colors.
Map.addLayer(result.randomVisualizer(), {}, 'clusters')
Conclusions & Resources
Google Earth Engine is an extremely powerful tool that can be used to work with large datasets and spatial extents. By integrating it with QGIS we have a friendly graphical user interface that can be used by beginner or advanced users.
