Code Overview
This code provides a set of utility functions for working with satellite imagery using Google Earth Engine (GEE). It includes functions for manipulating image metadata, merging image collections, and applying various transformations and calculations to the images.
Dependencies
-
lodash/pick
: Used for picking specific properties from objects. -
../../services/earth-engine
: Custom service for interacting with Google Earth Engine. -
../../common/metadata
: Common metadata constants. -
../../common/indices
: Common indices for image processing.
Functions
addGridPosition(satellite)
Adds a grid position to an image based on the satellite's computed grid position.
-
Parameters:
-
satellite
: The satellite object used to compute the grid position.
-
- Returns: A function that takes an image element and returns the image with the grid position set.
getDate(image)
Retrieves the date from an image's metadata.
-
Parameters:
-
image
: The image from which to retrieve the date.
-
- Returns: The date of the image.
mergeFootprints(collection)
Merges the footprints of a collection of images into a single geometry.
-
Parameters:
-
collection
: The collection of images.
-
- Returns: The merged geometry of the collection.
retrieveExtremes(collection)
Retrieves the earliest and latest images in a collection based on their start time.
-
Parameters:
-
collection
: The collection of images.
-
- Returns: An object containing the earliest and latest dates.
mergeProperties(collection)
Merges properties of a collection of images, including the earliest date and footprint.
-
Parameters:
-
collection
: The collection of images.
-
- Returns: An object containing merged properties such as name, footprint, start time, and sensor ID.
combineReducers(...reducers)
Combines multiple reducers into a single reducer.
-
Parameters:
-
...reducers
: The reducers to combine.
-
- Returns: The combined reducer.
serializeList(subject)
Serializes a list into a string format.
-
Parameters:
-
subject
: The list to serialize.
-
- Returns: The serialized string.
generateVisualizationParams(mission)
Generates visualization parameters for a mission.
-
Parameters:
-
mission
: The mission object containing band information and visualization parameters.
-
- Returns: An object containing the visualization parameters.
evaluate(query)
Binds the evaluate method to a query.
-
Parameters:
-
query
: The query to evaluate.
-
- Returns: The bound evaluate method.
applyExpression(image, expressionOrLabel, bands)
Applies an expression to an image using specified bands.
-
Parameters:
-
image
: The image to which the expression is applied. -
expressionOrLabel
: The expression or label to apply. -
bands
: The bands to use in the expression.
-
- Returns: The image with the applied expression.
imageToKey(image)
Converts an image to a key by serializing its ID and version.
-
Parameters:
-
image
: The image to convert.
-
- Returns: The serialized key.
getSatelliteCollection(satellite)
Retrieves the image collection for a satellite.
-
Parameters:
-
satellite
: The satellite object containing the collection set.
-
- Returns: The image collection.
simplify(amount)
Simplifies a feature by a specified amount.
-
Parameters:
-
amount
: The amount by which to simplify the feature.
-
- Returns: A function that takes a feature and returns the simplified feature.
Usage Examples
Adding Grid Position
const satellite = { /* satellite object */ };
const image = ee.Image('some-image-id');
const addPosition = addGridPosition(satellite);
const imageWithPosition = addPosition(image);
Merging Footprints
const collection = ee.ImageCollection('some-collection-id');
const mergedFootprint = mergeFootprints(collection);
Applying Expression
const image = ee.Image('some-image-id');
const bands = { red: 'B4', green: 'B3', blue: 'B2', nir: 'B5', swir: 'B6' };
const resultImage = applyExpression(image, 'NDVI', bands);
Assumptions and Edge Cases
- Assumes that input data is in the correct format expected by Google Earth Engine.
- Handles edge cases such as empty collections by returning appropriate default values.
- If the code is based on external resources, references are provided within the comments.