Google Earth Engine Tutorial: Beginners Guide 1 Code Editor Introduction
Credit: Youtube Channel “Terra Spatial, Introduction to the Google Earth Engine Code Editor interface and basic navigation for new users.”
You can see all the tutorials from here: Techgeo Academy.
Google Earth Engine Tutorial: Beginners Guide 1 – Code Editor Introduction
Welcome to the first part of our Google Earth Engine tutorial series! In this comprehensive guide, we’ll walk you through the basics of the Google Earth Engine Code Editor, your gateway to exploring and analyzing Earth’s geospatial data.
What is Google Earth Engine?
Google Earth Engine (GEE) is a cloud-based platform that allows scientists, researchers, and developers to detect changes, map trends, and quantify differences on the Earth’s surface using Google’s massive catalog of satellite imagery and geospatial datasets. With petabytes of data and powerful computational capabilities, GEE enables users to perform planetary-scale geospatial analysis without needing high-performance computing infrastructure.
Getting Started with the Code Editor
The Google Earth Engine Code Editor is a web-based integrated development environment (IDE) that provides all the tools needed to write and execute JavaScript code for geospatial analysis. It features a code writing area, console output, interactive map, and various panels for exploring datasets and managing scripts.
Accessing the Code Editor
To access the Google Earth Engine Code Editor, visit code.earthengine.google.com. You’ll need a Google account to sign in. Once logged in, you’ll encounter the main interface consisting of several key components:
- Scripting Panel: Where you write your JavaScript code
- Console: Displays output, errors, and print statements
- Map: Interactive visualization of your results
- Inspector: Tool for querying map features and pixel values
- Tasks: Panel for managing export operations
- API Documentation: Comprehensive reference for GEE functions
Your First GEE Script
Let’s start with a simple example to familiarize ourselves with the Code Editor. We’ll load a basic satellite image and display it on the map.
// Load a Landsat 8 image
var image = ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_044034_20140318');
// Center the map on the image
Map.centerObject(image, 8);
// Add the image to the map
Map.addLayer(image, {bands: ['SR_B4', 'SR_B3', 'SR_B2'], min: 0, max: 30000}, 'Landsat Image');
This script demonstrates several fundamental GEE concepts:
- Loading data using the
ee.Image()
function - Centering the map with
Map.centerObject()
- Adding layers to the map with
Map.addLayer()
Understanding the JavaScript Environment
Google Earth Engine uses a flavor of JavaScript adapted for server-side geospatial processing. While standard JavaScript runs in your browser, GEE JavaScript runs on Google’s servers. Here are some key differences and concepts:
Server vs. Client Objects
In GEE, there are two types of objects:
- Server objects: Earth Engine objects like Images, FeatureCollections, and geometries that exist on Google’s servers
- Client objects: Standard JavaScript objects like strings, numbers, and arrays that exist in your browser
Understanding this distinction is crucial for effective GEE programming.
Lazy Evaluation
GEE uses lazy evaluation, meaning that operations are not executed immediately when you write them. Instead, Earth Engine builds a computation graph that is executed only when you explicitly request results, such as displaying an image or exporting data.
Working with the Interface
The Script Panel
The scripting panel is where you compose your JavaScript code. It supports syntax highlighting and auto-completion. You can save scripts to your personal repository for later use.
The Console
The console displays the output of print()
statements in your code, as well as any errors or warnings. It’s an essential tool for debugging your scripts.
var cityName = 'San Francisco';
print('The city is: ' + cityName);
var image = ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_044034_20140318');
print(image);
The Map Panel
The map panel displays geospatial results. You can zoom, pan, and change base maps. Layers added to the map appear in the layer manager on the right, where you can adjust their visibility and styling.
The Inspector Tool
The inspector tool allows you to click on map features to view their properties. For images, it shows pixel values at the clicked location, which is invaluable for understanding your data.
Basic Syntax and Functions
Declaring Variables
In GEE JavaScript, variables are declared using the var
keyword:
var geometry = ee.Geometry.Point([-122.085, 37.422]);
var imageCollection = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2');
Function Calls
Functions are called using dot notation on Earth Engine objects:
var filteredCollection = imageCollection
.filterDate('2020-01-01', '2020-12-31')
.filterBounds(geometry);
Debugging in the Code Editor
The Code Editor provides several debugging tools:
- Print statements: Use them liberally to check intermediate results
- Error messages: Clear indication of syntax and runtime errors
- Inspector tool: Probe pixel values and feature properties
- Playground: Test small code snippets without affecting your main script
Running Your First Analysis
Let’s try a more comprehensive example that calculates NDVI (Normalized Difference Vegetation Index) from a Landsat image:
// Load a Landsat 8 image
var image = ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_044034_20140318')
.select(['SR_B5', 'SR_B4']);
// Calculate NDVI
var ndvi = image.normalizedDifference(['SR_B5', 'SR_B4']);
// Center the map
Map.centerObject(image, 9);
// Add NDVI layer to the map with appropriate visualization
Map.addLayer(ndvi, {min: -1, max: 1, palette: ['blue', 'white', 'green']}, 'NDVI');
Frequently Asked Questions
Next Steps
This introduction to the Google Earth Engine Code Editor provides a foundation for more advanced geospatial analysis. In the next tutorial, we’ll explore loading and filtering image collections, which will enable you to work with time-series satellite data.
Remember to explore the built-in documentation, experiment with different datasets, and join the GEE community forums for additional support and inspiration.