GEE Tutorials

Google Earth Engine Tutorial: Beginners Guide 11 Feature Collection Overview

Credit: Youtube Channel “Terra Spatial, Introduction to creating and working with feature collections including points, lines and polygones in GEE”

You can see all the tutorials from here: Techgeo Academy.

Feature Collection Overview

Google Earth Engine (GEE) provides powerful tools for handling geospatial data, and Feature Collections are a fundamental part of this ecosystem. A Feature Collection is a collection of geospatial features, where each feature contains both geometry (points, lines, polygons) and associated attributes (properties). These collections are essential for tasks like analyzing specific regions, managing administrative boundaries, or working with vector data sets.

Understanding Feature Collections is critical for beginners, as they form the basis of many advanced analyses. This tutorial covers their definition, creation, manipulation, and practical applications.

What is a Feature Collection?

A Feature Collection in GEE is similar to a shapefile or a GeoJSON dataset in traditional GIS tools. It consists of multiple Features, which are individual geographic entities. Each Feature has:

  • Geometry: Defines the spatial location (e.g., a point, line, or polygon).
  • Properties: Attributes or metadata associated with the geometry.

For example, a Feature Collection might represent a set of cities, with each city having a position (geometry) and details like population, area, or name (properties).

Creating a Feature Collection

You can create a Feature Collection manually or load it from external data sources. Here’s a simple way to create one from scratch:


// Create a point feature
var point = ee.Feature(ee.Geometry.Point([-122.082, 37.422]));

// Set properties for the point
var pointWithProperties = point.set('name', 'San Francisco', 'population', 883305);

// Create a Feature Collection with the point
var collection = ee.FeatureCollection([pointWithProperties]);

// Print the collection to the console
print(collection);

This code creates a Feature Collection containing a single point feature with custom properties.

Loading Built-in Feature Collections

GEE includes several built-in Feature Collections that are useful for quick analysis. For instance, the FAO Gridded Population of the World (GPW) dataset or the Global Administrative Areas (GADM) data. To load a built-in Feature Collection:


// Load a built-in Feature Collection
var gadm = ee.FeatureCollection("FAO/GAUL/2015/level0");

// Display the collection on the map
Map.addLayer(gadm, {}, 'GADM Features');

This example loads the GADM dataset and visualizes it on the map.

Filtering and Manipulating Feature Collections

Feature Collections can be filtered using conditions or joined with other datasets. For example:


// Filter the collection by a property
var filtered = collection.filter(ee.Filter.eq('name', 'San Francisco'));

// Get the first feature in the collection
var firstFeature = collection.first();

You can also perform operations like geometry aggregation to combine features or attribute joins to merge data with other tables.

Visualizing Feature Collections

To visualize a Feature Collection, assign a color or style to its features. For example:


// Define a style for the features
var style = {
color: 'red',
fillColor: '00FF0088'
};

// Add the collection to the map with the defined style
Map.addLayer(collection, style, 'Custom Features');

This code adds the Feature Collection to the map with red outlines and green fill colors.

Exporting a Feature Collection

Once you have a Feature Collection, you can export it as a GeoJSON or KML file. Here’s an example:


// Export the collection to Google Drive
Export.table.toDrive({
collection: collection,
description: 'FeatureCollectionExport',
fileFormat: 'GeoJSON'
});

This exports the collection to your Google Drive in GeoJSON format, making it easy to use outside of GEE.

FAQ

What is the difference between a Feature Collection and an Image Collection?

Feature Collections store vector data (points, lines, polygons) with attributes, while Image Collections store raster data (e.g., satellite imagery) with metadata. Feature Collections are best for discrete, attribute-rich data, whereas Image Collections handle time-series or multi-band raster data.

How do I create a Feature Collection from a CSV file?

To create a Feature Collection from a CSV file, you must first convert your data into a format that GEE understands. Use the ee.FeatureCollection constructor and ensure each row has geometry fields (latitude, longitude) to define the spatial component.

Can I join a Feature Collection with a raster dataset?

Yes, you can join a Feature Collection with a raster dataset using image reductions or zonal statistics. For example, you can calculate the average temperature within each feature’s geometry by reducing the raster data over the collection.

How do I visualize multiple features in a collection?

Use the Map.addLayer() function with a specified style. For unique styles based on properties, use Map.setLayer with a style function to differentiate between features dynamically.

What are common errors when working with Feature Collections?

Rarely, ensure your collection is not empty. If you encounter issues, verify that the data contains valid geometries and that properties are correctly assigned. Use collection.size() to check the number of features in a collection.

Similar Posts

Leave a Reply

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