GEE Tutorials

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


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:

  1. Loading data using the ee.Image() function
  2. Centering the map with Map.centerObject()
  3. 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

Do I need programming experience to use Google Earth Engine?
While prior programming experience is helpful, especially with JavaScript, beginners can start with basic examples and gradually build their skills. GEE’s extensive documentation and community resources make it accessible for newcomers to remote sensing.
Is Google Earth Engine free to use?
Yes, Google Earth Engine is free for research, education, and non-commercial use. Commercial users should check Google’s licensing terms. The platform provides substantial computing resources at no cost.
What kind of data is available in Earth Engine?
GEE hosts petabytes of satellite imagery including Landsat, Sentinel, MODIS, and aerial imagery. It also includes climate datasets, population data, elevation models, and much more. The public data catalog contains hundreds of datasets.
How do I save and share my work in GEE?
You can save scripts to your personal repository within the Code Editor. Scripts can be shared with specific users or made public. The platform also supports version control for your scripts.
Can I export data from Google Earth Engine?
Yes, GEE allows you to export images, maps, tables, and video. Exports are processed in the background and can be saved to your Google Drive, Google Cloud Storage, or as new Earth Engine assets.
What’s the difference between ee.Image and ee.ImageCollection?
An ee.Image represents a single raster dataset at a specific time, while ee.ImageCollection is a stack of images, usually over time. You can filter, sort, and process ImageCollections to create time series analysis.
How can I handle errors in my GEE scripts?
Use console.print() statements to debug your script step by step. Check the console for error messages. Common errors include incorrect dataset paths, invalid geometries, and exceeding memory limits. The API documentation is invaluable for correct syntax.
Is there a limit to how much processing I can do?
GEE provides substantial computational resources but has usage quotas to ensure fair access. Complex computations might time out or exceed memory limits. For large-scale processing, consider breaking tasks into smaller pieces or using export operations.
Can I use Python with Google Earth Engine?
Yes, GEE supports Python through the earthengine-api package. You can write Python scripts that interact with Earth Engine and process data similarly to the JavaScript API. The Python API is particularly useful for integration with other scientific computing tools.
How often is satellite data updated in Earth Engine?
Dataset updates depend on the data provider and satellite mission. Some datasets are updated daily (like MODIS), while others might be updated monthly or yearly. You can check specific dataset documentation for update frequencies.

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.


Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *