GEE Tutorials

Google Earth Engine Tutorial: Create Random Sample Points

Credit: Youtube Channel “Terra Spatial, Learn how to generate random sample points within any study area for statistical analysis and validation.”

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

Introduction

Google Earth Engine (GEE) provides a powerful platform for processing and analyzing geospatial data. One common task in geospatial analysis is generating random sample points within a defined area for validation or sampling purposes. This guide will walk you through the steps to create random sample points using Google Earth Engine.

Step-by-Step Tutorial

To create random sample points, you first need to initialize the Earth Engine API and load a dataset. Below is a sample script that uses a global dataset (e.g., MODIS Land Cover) and generates random points within a defined region of interest (ROI).


// Initialize the Earth Engine API
// Make sure you have authenticated and enabled the API in your Earth Engine account
// Load a dataset, e.g., MODIS Land Cover (MCD12Q1)
var dataset = ee.ImageCollection('MODIS/006/MCD12Q1');
var image = dataset.first();
// Define a region of interest (e.g., a square)
var roi = ee.Geometry.Rectangle([10, 20, 30, 40]);
// Generate 100 random points within the ROI
var randomPoints = image.randomPoints(100, 12345, roi);
// Visualize the points
Map.addLayer(randomPoints, {color: 'red'}, 'Random Sample Points');
// Export the points as a GeoJSON file
Export.table.toDrive({
collection: randomPoints,
description: 'Random_Sample_Points',
folder: 'GEE_Exports',
fileNamePrefix: 'random_points',
fileFormat: 'GeoJSON'
});

Key Concepts

  • ee.ImageCollection: A collection of images for analysis.
  • randomPoints: Method to generate random points within a region.
  • ee.Geometry.Rectangle: Defines the geographic area for sampling.
  • Export.table.toDrive: Exports the points to a Google Drive folder.

Frequently Asked Questions (FAQ)

  • How can I adjust the number of random points?
    Modify the first parameter in the randomPoints() method (e.g., 100 for 100 points).
  • Can I use a different region of interest?
    Yes, replace ee.Geometry.Rectangle with a custom geometry, such as a shapefile or polygon.
  • Is it possible to add an attribute field to the point features?
    Yes, use the .set() method on individual features in the collection.
  • How do I export the points in a different format?
    Change the fileFormat parameter in Export.table.toDrive to ‘CSV’, ‘KML’, or other supported formats.
  • What if I want reproducible results?
    Set the seed parameter in randomPoints() to ensure the same set of points is generated each time.

Similar Posts

Leave a Reply

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