Add a processing operation#

Objectives

By the end of this tutorial, you will be able to add or modify data processing commands for JupyterGIS.

Prerequisites

  • Knowledge of geospatial processing operations, for example using GDAL/OGR.

  • Ability to edit JSON and JSONSchema.

Overview#

  • packages/schema/src/schema/processing/: In this directory, we need to create a file which defines the UI form structure for each processing operation.

  • packages/schema/src/processing/config/: In this directory, we need to create a file which defines the processing behavior for each processing operation.

Creating a schema#

What information is required to execute the processing step?

Most processing operations need an input layer and some other parameters. Here, under the properties key, we define a schema which requires an input layer and a buffer distance. The required parameters are listed under the required key.

There’s also an optional parameter to determine whether the output layer should be embedded in the project file.

Prerequisites

Always include a description for each property!

{
  "type": "object",
  "description": "Buffer",
  "title": "IBuffer",
  "required": ["inputLayer", "bufferDistance"],
  "additionalProperties": false,
  "properties": {
    "inputLayer": {
      "type": "string",
      "description": "The input layer for buffering."
    },
    "bufferDistance": {
      "type": "number",
      "default": 10,
      "description": "The distance used for buffering the geometry (in projection units)."
    },
    "embedOutputLayer": {
      "type": "boolean",
      "title": "Embed output buffered layer in file",
      "default": true
    }
  }
}

Configuring processing behavior#

This information is used to generate the code, including a JupyterLab command, which will do the command and enable display in the UI.

No need to edit the UI code!

The operation key contains templates for generating the underlying processing operation (often using GDAL/OGR). Template parameters are set off with braces {}.

The operationParams key contains the attributes (from the schema defined above) that will be injected into the processing operation templates.

type is a special string that determines how the processing operation is constructed. See the next section for more details!

{
  "name": "buffer",
  "label": "Buffer",
  "operationParams": ["bufferDistance"],
  "operation": {
    "gdalFunction": "ogr2ogr",
    "sql": "SELECT ST_Union(ST_Buffer(geometry, {bufferDistance})) AS geometry, * FROM \"{layerName}\""
  },
  "type": "vector"
}

Processing type#

The processing type attribute from the config shown above determines which logic will be used to generate commands.

Prerequisites

The processing type you use must be defined in packages/schema/src/processing/ProcessingMerge.ts and used in packages/base/src/processing/processingCommands.ts.

If no existing types satisfy your needs, then you’ll need to add a new case.