The process module¶
The process module provides a constructor for Process objects. A process is essentially a runnable function with additional metadata about the functions’ arguments (referred to as process inputs), return value (or process outputs), title, and description.
The following constructs a process that performs some simple arithmetic.
>> var Process = require("geoscript/process").Process;
>> var add = Process({
.. title: "Add",
.. description: "Adds two numbers",
.. inputs: {
.. a: {
.. type: "Number",
.. title: "First",
.. description: "The first number"
.. },
.. b: {
.. type: "Number",
.. title: "Second",
.. description: "The second number"
.. }
.. },
.. outputs: {
.. result: {
.. type: "Number",
.. title: "Sum",
.. description: "The sum of the two input numbers"
.. }
.. },
.. run: function(inputs) {
.. return {result: inputs.a + inputs.b};
.. }
.. });
Now that this process is created and well described, it can be run with the following:
>> var outputs = add.run({a: 2, b: 3});
>> outputs.result
5
process.Process()
¶
-
class
process.
Process
(config)¶ - Arguments
config – Object Process configuration.
Config Properties¶
-
description
String
Full description of the process, including all input and output fields.
-
inputs
Object
Proces inputs. Property names correspond to named inputs. Property values are objects withtype
(required),title
,description
,minOccurs
, andmaxOccurs
properties (optional unless noted).Below is an example
inputs
object with three named inputs:{ start: { type: "Date", title: "Start Time" }, end: { type: "Date", title: "End Time", description: "Optional end time", minOccurs: 0 }, geom: { type: "Polygon", title: "Area of Interest" } }
For a description and list of supported
type
values, see the Type Mapping section. If you need to reference a type for which there is not a mapping, you can supply the class directly instead of providing a string (e.g.Packages.com.example.SomeClass
).
-
outputs
Object
Proces outputs. Property names correspond to named outputs. Property values are objects withtype
(required),title
,description
,minOccurs
, andmaxOccurs
properties (optional unless noted).Below is an example
outputs
object with one named output:{ result: { type: "FeatureCollection", title: "Resulting features" } }
For a description and list of supported
type
values, see the Type Mapping section. If you need to reference a type for which there is not a mapping, you can supply the class directly instead of providing a string (e.g.Packages.com.example.SomeClass
).
-
run
Function
The function to be executed when running the process. This function is expected to take a singleinputs
argument with a property for each of the named inputs. The function should return an object with a property for each of the named outputs.
-
title
String
Title for the process.
Properties¶
-
Process.
description
¶ String
Full description of the process, including all input and output fields.
-
Process.
inputs
¶ Object
Proces inputs.
-
Process.
outputs
¶ Object
Proces outputs.
-
Process.
title
¶ String
Title for the process.
Methods¶
-
Process.
run
()¶ - Arguments
inputs –
Object
Inputs object
- Returns
Object
Outputs object
Execute the process with the given inputs.
Static Methods¶
-
Process.
get
(id)¶ - Arguments
id –
String
Process identifier (e.g. “geo:buffer”)
- Returns
Process
Get a registered process. Returns
null
if no process was found from the provided identifier.The example below uses the static
Process.get()
method to access and run thegeo:buffer
process. (Note this is a contrived example as all geometries already have aGeometry.buffer()
method that accomplishes the same.)>> var Process = require("geoscript/process").Process >> var Point = require("geoscript/geom").Point; >> var buffer = Process.get("geo:buffer"); >> Object.keys(buffer.inputs); geom,distance,quadrantSegments,capStyle >> Object.keys(buffer.outputs); result >> var point = Point([-110, 45]); >> var outputs = buffer.run({geom: point, distance: 10}); >> outputs.result; <Polygon [[[-100, 45], [-100.19214719596769, 43.04909677983872], [-10...>
-
Process.
getNames
()¶ - Returns
Array
A list of identifiers for all registered processes.
Get a list of all processes that are registered as part of the underlying libraries (does not include dynamically generated processes).