# Add style

| **Description** | Adds a raster style.          |
| --------------- | ----------------------------- |
| **Endpoint**    | `/path/{pathId}/raster/style` |
| **Method**      | POST                          |

### Access Level Rules

| **Minimum Access Level** | edit+ |
| ------------------------ | ----- |

### Processing Units

| **Minimum processing units** | 2 |
| ---------------------------- | - |

### Parameters

<table><thead><tr><th>Name</th><th width="385">Description</th><th>Required</th><th>Default</th></tr></thead><tbody><tr><td><code>pathId</code></td><td>The id of the raster layer.</td><td>true</td><td></td></tr><tr><td><code>name</code></td><td>The name of the style to add.</td><td>true</td><td></td></tr><tr><td><code>parameters</code></td><td>The parameters for the style. See details below.</td><td>true</td><td></td></tr><tr><td><code>default</code></td><td>Boolean whether the style should be used as the default styling of the timestamp.</td><td>true</td><td></td></tr><tr><td><code>method</code></td><td>The method of the style, should be 'v2' to use the most recent styling framework.</td><td>true</td><td></td></tr><tr><td><code>description</code></td><td>A description of the style as string.</td><td>false</td><td>Default null.</td></tr><tr><td><code>dryRun</code></td><td>Boolean whether to to only check the validity of the style without instead of creating it.</td><td>false</td><td>Default null.</td></tr></tbody></table>

#### Sample requests for different methods

{% tabs %}
{% tab title="channelMap" %}

```json
//Define the values of the three color channels using free expressions
{
    "fill": {
        "type": "channelMap", //must be channelMap
        "channelMap": [
            {
                "expression": "band3", //An expression giving the value of the particular color channel
                "channel": "red", //The color channel to place the expression outcome in
            },
            {
                "expression": "band2", //An expression giving the value of the particular color channel
                "channel": "green", //The color channel to place the expression outcome in
            },
            {
                "expression": "band1", //An expression giving the value of the particular color channel
                "channel": "blue", //The color channel to place the expression outcome in
            }
        ],
    },
    "alphaMultiplier": 1,//A float between 0 and 1 to fade the image
    "alpha": null, //An alpha object documented below
    "noData":null, //A noData object documented below
    "shade":null //A shade object documented below
}
```

{% endtab %}

{% tab title="caseMap" %}

```json
//Define conditions and assign colors based on those conditions 
{
    "fill": {
        "type": "caseMap", //must be caseMap
        "defaultTarget":{"color":"#FFE733"}, //Color to assign if all conditions evaluate false
        "caseMap": [
            {
                "expression": "band1>0", //An expression to evaluate
                "target": {"color":"#2A5C84"}, //The color to assign if the expression evaluates true
                "label":"label" //An optional label to use in the legend
            },
            {
                "expression": "band1>1", //An expression to evaluate
                "target": {"color":"#74AE56"}, //The color to assign if the exxpression evaluates true
                "label":"label" //An optional label to use in the legend
            },
            {
                "expression": "and(band1>2, band2<0 )", //An expression to evaluate
                "target": {"color":"#ED2938"}, //The color to assign if the expression evaluates true
                "label":"label" //An optional label to use in the legend
            }
        ],
    },
    "alphaMultiplier": 1,//A float between 0 and 1 to fade the image
    "alpha": null, //An alpha object documented below
    "noData":null, //A noData object documented below
    "shade":null //A shade object documented below
}
```

{% endtab %}

{% tab title="rangeMap" %}

```json
//Define an expression and sent the result to a color using ranges. 
{
    "fill": {
        "type": "rangeMap", //must be rangeMap
        "expression":"2*band1+5", //An expression whose output to apply the rangeMap to
        "gradient":true, //A boolean indicating whether the color shoud fade from one range to the other
        "rangeMap": [
            {
                "value": 1, //Start of the range
                "target": {"color":"#2A5C84"}, //The color to assign if the output of the expression falls in this range
                "label":"label" //An optional label to use in the legend
            },
            {
                "value": 2, //Start of the range
                "target": {"color":"#74AE56"},  //The color to assign if the output of the expression falls in this range
                "label":"label" //An optional label to use in the legend
            },
            {
                "value": 3, //Start of the range
                "target": {"color":"#ED2938"}, //The color to assign if the output of the expression falls in this range
                "label":"label" //An optional label to use in the legend
            }
        ],
    },
    "alphaMultiplier": 1,//A float between 0 and 1 to fade the image
    "alpha": null, //An alpha object documented below
    "noData":null, //A noData object documented below
    "shade":null //A shade object documented below
}
```

{% endtab %}

{% tab title="valueMap" %}

```json
//Define an expression and sent the result to a color based on a value to color map
{
    "fill": {
        "type": "valueMap", //must be valueMap
        "expression":"2*band1+5", //An expression whose output to apply the valueMap to
        "defaultTarget":"#FFE733", //Color to assing if the output of the expression does not match any of the values in the valueMap
        "rangeMap": [
            {
                "value": 1, //Value to sent to the specific color. Must be integer
                "target": {"color":"#2A5C84"}, //The color to assign if the output equals the given value
                "label":"label" //An optional label to use in the legend
            },
            {
                "value": 2, //Value to sent to the specific color. Must be integer
                "target": {"color":"#74AE56"}, //The color to assign if the output equals the given value
                "label":"label" //An optional label to use in the legend
            },
            {
                "value": 3, //Value to sent to the specific color. Must be integer
                "target": {"color":"#ED2938"}, //The color to assign if the output equals the given value
                "label":"label" //An optional label to use in the legend
             }
        ],
    },
    "alphaMultiplier": 1,//A float between 0 and 1 to fade the image
    "alpha": null, //An alpha object documented below
    "noData":null, //A noData object documented below
    "shade":null //A shade object documented below
}
```

{% endtab %}
{% endtabs %}

#### Expressions

An expression is a string containing an expression outputting either a number or boolean.

In the expression you can use raster values by referencing the band:

```
band1, band2, band3, ...
```

The expression can also contain standard operators such as:

```
*,+,-,/, floor(_),),(
```

Lastly one can use these logical operators

```
&&, ||, !, ==,<=,<,>,>=,!=
```

An expression can simply be the value of the band

```
expression = "band1"
```

Or an expression can simply be a value

```
expression="1"
```

Or boolean

```
expression="true"
```

An example of an expression rendering a number:

```
expression = "(band1^2+band2^2)^(1/2)"
```

An example of an expression rendering a boolean

```
expression = "!( band1 > 0 && band2>0)"
```

####

#### Alpha object

The Alpha object can have two types. ***Expression Map*** and ***caseMap***

In case of type expression the result of the expression will be used as alpha value. Mind that the alpha value will be clipped to 0 and 1.

```
alpha={type:"expressionMap", expression: "5*band1/2"}
```

In case of type ***case***, all expressions in the conditions are evaluated and the given value is assigned if the condition evaluates true.

```
alpha={"type":"caseMap", "caseMap":[{"expression": "band1>0 && band1<1" , "target":{"number":0.2}}, {"expression":"band1>1 && band1<2", "target":{"number":0.4}}] }
```

#### NoData

NoData should be an expression outputting a boolean. True will make the output pixel transparent, false will make it non transparent.

```
noData="or(band1<0, band2==0)"
```

#### Shade

Shade should be an object describing a hill shade.

```
shade={bandNumber:1, exaggerate:1, azimuth:90, factor:0.5, angle:45 }
```

The bandNumber tells which band of the raster to interpret as altitude.

The factor should be between 0 and 1 and describes the weight with which to blend the shade into the output.

The exaggerate is used to multiply the band with.

The angle and azimuth describe the position of the sun in degrees.

#### RECOMMENDED READING

{% content-ref url="../../../../working-with-raster-data/raster-styling-methods" %}
[raster-styling-methods](https://docs.ellipsis-drive.com/working-with-raster-data/raster-styling-methods)
{% endcontent-ref %}
