Class: Builder

Builder(processes, parentnullable, id)

A class to construct processes easily.

An example (con is a object of type Connection):

var builder = await con.buildProcess();

var datacube = builder.load_collection(
  new Parameter("collection-id", "string", "The ID of the collection to load"), // collection-id is then a process parameter that can be specified by users.
  { "west": 16.1, "east": 16.6, "north": 48.6, "south": 47.2 },
  ["2018-01-01", "2018-02-01"],
  ["B02", "B04", "B08"]
);

// Alternative 1 - using the Formula class
var eviAlgorithm = new Formula('2.5 * (($B08 - $B04) / (1 + $B08 + 6 * $B04 + -7.5 * $B02))');
// Alternative 2 - "by hand"
var eviAlgorithm = function(data) {
  var nir = data["B08"]; // Array access by label, accessing label "B08" here
  var red = data["B04"];
  var blue = data["B02"];
  return this.multiply(
    2.5,
    this.divide(
      this.subtract(nir, red),
      this.sum([
        1,
        nir,
        this.multiply(6, red),
        this.multiply(-7.5, blue)
      ])
    )
  );
};
datacube = builder.reduce_dimension(datacube, eviAlgorithm, "bands")
                  .description("Compute the EVI. Formula: 2.5 * (NIR - RED) / (1 + NIR + 6*RED + -7.5*BLUE)");
                  
var min = function(data) { return this.min(data); };
datacube = builder.reduce_dimension(datacube, min, "t");

datacube = builder.save_result(datacube, "PNG");

var storedProcess = await con.setUserProcess("evi", datacube);

As you can see above, the builder in callback functions is available as this. Arrow functions do not support rebinding this and therefore the builder is passed as the last argument.

So a normal function can be defined as follows:

let callback = function(data) {
  return this.mean(data);
}

An arrow function on the other hand has to use the builder that is passed as the last parameter:

let callback = (data, c, builder) => builder.mean(data);

Using arrow functions is available only since JS client version 1.3.0. Beforehand it was not possible to use arrow functions in this context.

Constructor

new Builder(processes, parentnullable, id)

Creates a Builder instance.

Each process passed to the constructor is made available as object method.

Parameters:
Name Type Attributes Default Description
processes Array.<Process> | Processes | ProcessRegistry

Either an array containing processes or an object compatible with GET /processes of the API.

parent Builder <nullable>
null

The parent builder, usually only used by the Builder itself.

id string

A unique identifier for the process.

Source:

Members

id :string

A unique identifier for the process.

Type:
  • string
Source:

(nullable) parent :Builder

The parent builder.

Type:
Source:

(nullable) parentNode :BuilderNode

The parent node.

Type:
Source:

(nullable) parentParameter :string

The parent parameter name.

Type:
  • string
Source:

processes :ProcessRegistry

List of all non-namespaced process specifications.

Type:
  • ProcessRegistry
Source:

Methods

(async, static) fromURL(url) → {Promise.<Builder>}

Creates a Builder instance that can be used without connecting to a back-end.

It requests the processes for the version specified from the given URL. CORS needs to be implemented on the server-side for the URL given.

Parameters:
Name Type Description
url string | null
Source:
Throws:
Error
Returns:
Type
Promise.<Builder>

(async, static) fromVersion(versionopt, nullable) → {Promise.<Builder>}

Creates a Builder instance that can be used without connecting to a back-end.

It requests the processes for the version specified from processes.openeo.org. Requests the latest version if no version number is passed.

Parameters:
Name Type Attributes Default Description
version string <optional>
<nullable>
null
Source:
Throws:
Error
Returns:
Type
Promise.<Builder>

[undefined](…args) → {BuilderNode}

Implicitly calls the process with the given name on the back-end by adding it to the process.

This is a shortcut for Builder#process.

Parameters:
Name Type Attributes Description
args * <repeatable>

The arguments for the process.

Source:
See:
Returns:
Type
BuilderNode

addParameter(parameter, rootopt)

Adds a parameter to the list of process parameters.

Doesn't add the parameter if it has the same name as a callback parameter.

Parameters:
Name Type Attributes Default Description
parameter object.<string, *>

The parameter spec to add, must comply to the API.

root boolean <optional>
true

Adds the parameter to the root process if set to true, otherwise to the process constructed by this builder. Usually you want to add it to the root.

Source:

addProcessSpec(process, namespaceopt, nullable)

Adds a process specification to the builder so that it can be used to create a process graph.

Parameters:
Name Type Attributes Default Description
process Process

Process specification compliant to openEO API

namespace string <optional>
<nullable>
null

Namespace of the process (default to null, i.e. pre-defined processes). EXPERIMENTAL!

Source:
Throws:
Error

(protected) createCallbackParameter(parameterName) → {Proxy.<Parameter>}

Creates a callback parameter with the given name.

Parameters:
Name Type Description
parameterName string
Source:
Returns:
Type
Proxy.<Parameter>

createFunction(process)

Creates a callable function on the builder object for a process.

Parameters:
Name Type Description
process Process
Source:
Throws:
Error

generateId(prefixopt) → {string}

Generates a unique identifier for the process nodes.

A prefix can be given to make the identifiers more human-readable. If the given name is empty, the id is simply an incrementing number.

Parameters:
Name Type Attributes Default Description
prefix string <optional>
""
Source:
Returns:
Type
string

getParentCallbackParameters() → {Array}

Gets the callback parameter specifics from the parent process.

Source:
To Do:
  • Should this also pass callback parameters from parents until root is reached?
Returns:
Type
Array

math(formula) → {BuilderNode}

Adds a mathematical formula to the process.

See the Formula class for more information.

Parameters:
Name Type Description
formula string
Source:
See:
Throws:
Error
Returns:
Type
BuilderNode

process(processId, argsopt, descriptionopt, nullable) → {BuilderNode}

Adds another process call to the process chain.

Parameters:
Name Type Attributes Default Description
processId string

The id of the process to call. To access a namespaced process, use the process@namespace notation.

args object.<string, *> | Array <optional>
{}

The arguments as key-value pairs or as array. For objects, they keys must be the parameter names and the values must be the arguments. For arrays, arguments must be specified in the same order as in the corresponding process.

description string <optional>
<nullable>
null

An optional description for the process call.

Source:
Returns:
Type
BuilderNode

setParent(node, parameterName)

Sets the parent for this Builder.

Parameters:
Name Type Description
node BuilderNode
parameterName string
Source:

spec(id, namespaceopt, nullable) → {Process|null}

Returns the process specification for the given process identifier and namespace (or null).

Parameters:
Name Type Attributes Default Description
id string

Process identifier

namespace string <optional>
<nullable>
null

Namespace of the process (default to null, i.e. user or backend namespace). EXPERIMENTAL!

Source:
Returns:
Type
Process | null

supports(processId, namespaceopt, nullable) → {boolean}

Checks whether a process with the given id and namespace is supported by the back-end.

Parameters:
Name Type Attributes Default Description
processId string

The id of the process.

namespace string <optional>
<nullable>
null

Namespace of the process (default to null, i.e. pre-defined processes). EXPERIMENTAL!

Source:
Returns:
Type
boolean

toJSON() → {Process}

Returns a JSON serializable representation of the data that is API compliant.

Source:
Returns:
Type
Process