Google Earth Engin Docs
Google Earth Engin Docs
Google Earth Engin Docs
This Get Started guide is intended as a quick way to start programming with the Earth Engine
JavaScript API. For an introductory look at JavaScript and more in-depth exercises with the
Earth Engine API, see the tutorials. For suggestions on JavaScript coding style, see the
Google JavaScript Style Guide.
Google Earth Engine allows users to run algorithms on georeferenced imagery and vectors
stored on Google's infrastructure. The Google Earth Engine API provides a library of
functions which may be applied to data for display and analysis. Earth Engine's public data
catalog contains a large amount of publicly available imagery and vector datasets. Private
assets can also be created in users' personal folders.
The Docs tab of the Code Editor lists the methods of each API class. For example, the Image
class has an add() method:
This method adds the bands of image2 to the bands of image1. The ee.Algorithms category
contains a list of currently supported algorithms for specialized or domain specific processing.
For example, to create topographic layers from an input Digital Elevation Model (DEM):
Code Editor specific functions include the Map and Export methods, which control how
layers are added to the map panel or exported to Google Drive, respectively. Functions can
also be created in JavaScript using
As illustrated in the Mapping section, user defined functions are useful for creating custom
functionality or modifying the elements of a collection using:
The following sections illustrate these concepts for various simple use cases.
print('Hello world!');
Copy this line into the code editor of the Code Editor and click Run. Note that the output is
displayed in the Console tab, on the right of the Code Editor. For a more remote sensing
relevant example, the following prints the metadata of a Landsat 8 image:
print(ee.Image('LANDSAT/LC08/C01/T1/LC08_044034_20140318'));
Carefully inspect the output in the console to see metadata available for Landsat images.
// Load an image.
var image = ee.Image('LANDSAT/LC08/C01/T1/LC08_044034_20140318');
Observe that the visualization parameters are defined by an object literal, which includes a list
of bands to display, a minimum and maximum digital number and a gamma value. (Learn
more about Landsat bands here. Learn more about image visualization here).
Use Map.addLayer() to add features and feature collections to the map. For example,
Alternatively, copy the collection ID and paste it into your code. For example, choose the first
result of the ‘Landsat 8’ search and copy the ID as follows:
Since this is a collection of many images spanning the Earth land surface, finding an
individual image in the collection requires filtering in order to narrow down the search.
Alternatively, the collection of images can be reduced to a single image using compositing
and mosaicking techniques. More on filtering and compositing (see Reducing) in the next
sections.
Feature collections are also available through the Data Catalog. Their representation is smaller
than image collections, but you will find international, census, watershed, and protected areas
boundaries, to name a few. Learn more about importing your own vector datasets here.
Filter the Landsat 8 collection using the point and the dates, then sort using a metadata
property (discovered during inspection of the Landsat 8 scene metadata):
This collection can be safely printed and inspected. (If the collection has too many images,
printing it will either be very slow, time out, or return an error). Observe that the images in the
collection are a List stored in the ‘features’ property of the ImageCollection. The ID of any
image in the collection can be copied into the Image constructor as above. Alternatively, get
the first image (lowest cloud cover):
Access the complete Earth Engine filtering functionality using filter() with an ee.Filter
as the argument. (The filterBounds() and filterDate() methods used above are
shortcuts). For example, the following creates a Filter, uses it to filter a
FeatureCollection and displays the result:
Band math
Perform mathematical operations on images using Image methods. This may include band
recombinations (spectral indices), image differencing or mathematical operations such as
multiplication by a constant. For example, compute the difference between Normalized
Difference Vegetation Index (NDVI) images 20 years apart:
Notice the use of a user defined function in this example. More on functions in the next
section.
Another common task is adding a new property (or ‘attribute’ or ‘field’) to features in a
FeatureCollection. In the following example, the new property is a computation involving
two existing attributes:
// This function creates a new property that is the sum of two existing
properties.
var addField = function(feature) {
var sum =
ee.Number(feature.get('property1')).add(feature.get('property2'));
return feature.set({'sum': sum});
};
Note the added property (foo) for each feature created from the image centroid. In the final
line, the cast makes the resultant collection recognizable as a FeatureCollection.
Reducing
Reducing is the way to aggregate data over time, space, bands, arrays and other data
structures in Earth Engine. Various methods exist for this purpose in the API. For example, to
make a composite of an ImageCollection, use reduce() to reduce the images in the
collection to one Image. A simple example is creating the median composite of the five least
cloudy scenes in the Landsat 8 collection defined earlier:
// Compute the median of each pixel for each band of the 5 least cloudy
scenes.
var median = collection.limit(5).reduce(ee.Reducer.median());
Reducing is also the way to get statistics of an image in the regions defined by a Feature or
FeatureCollection. Suppose the task is to compute the mean pixel values within an area of
interest. Use reduceRegion() for this purpose. For example:
Masking
Every pixel in an ee.Image has both a value and a mask which ranges from 0 (no data) to 1.
Masked pixels (in which mask==0) are treated as no data. Pixels with 0 < mask ≤ 1 have a
value, but it is weighted by the mask for numerical computations.
You can make pixels transparent or exclude them from analysis using masks. Pixels are
masked when the mask value is zero. Continuing the image differencing example, use a mask
to display areas of increased and decreased NDVI over the difference interval:
In this example, note that the mask of the NDVI difference is updated by the land mask with
updateMask(). This sets the mask of the NDVI difference pixels to the land mask wherever
the NDVI difference mask is non-zero.
Masking is also useful for excluding data from the analysis. Consider the reduceRegion()
example from the Reducing section. Suppose the task is to compute a seasonal mean NDVI
for Santa Clara county, CA, excluding cloudy pixels. The following example demonstrates
multiple concepts: filtering, mapping, reducing and the use of a cloud mask:
// Load a Landsat collection, map the NDVI and cloud masking functions over
it.
var collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
.filterBounds(ee.Geometry.Point([-122.262, 37.8719]))
.filterDate('2014-03-01', '2014-05-31')
.map(addNDVI)
.map(cloudMask);