RGB renderer

View inQMLC++
View on GitHub
Sample viewer app

Apply an RGB renderer to a raster layer to enhance feature visibility.

screenshot

Use case

An RGB renderer is used to adjust the color bands of a multispectral image. Remote sensing images acquired from satellites often contain values representing the reflection of multiple spectrums of light. Changing the RGB renderer of such rasters can be used to differentiate and highlight particular features that reflect light differently, such as different vegetation types, or turbidity in water.

How to use the sample

Tap on "Edit renderer" to change the settings for the rgb renderer. The sample allows you to change the stretch type and the parameters for each type. You can tap on the "Render" button to update the raster.

  1. Create a Raster from a from a multispectral raster file.
  2. Create a RasterLayer from the raster.
  3. Create a Basemap from the raster layer and set it to the map.
  4. Create an RGBRenderer, specifying the StretchParameters and other properties.
  5. Set the Renderer on the raster layer with rasterLayer::setRenderer(renderer).

Relevant API

  • Basemap
  • Raster
  • RasterLayer
  • RGBRenderer
  • StretchParameters

Offline Data

Read more about how to set up the sample's offline data here.

Link Local Location
Shasta.tif raster <userhome>/ArcGIS/Runtime/Data/raster/Shasta.tif

About the data

The raster used in this sample shows an area in the south of the Shasta-Trinity National Forest, California.

Tags

analysis, color, composite, imagery, multiband, multispectral, pan-sharpen, photograph, raster, spectrum, stretch, visualization

Sample Code

RasterRgbRenderer.qmlRasterRgbRenderer.cppRasterRgbRenderer.h
                                                                                                                                                                                                                                                                       
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
// [WriteFile Name=RasterRgbRenderer, Category=Layers]
// [Legal]
// Copyright 2017 Esri.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// [Legal]

import QtQuick 2.6
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.2
import Esri.Samples 1.0

RasterRgbRendererSample {
    id: rootRectangle
    clip: true
    width: 800
    height: 600

    readonly property string minMax: "Min Max"
    readonly property string percentClip: "Percent Clip"
    readonly property string stdDeviation: "Standard Deviation"
    readonly property var stretchTypes: [minMax, percentClip, stdDeviation]
    property bool editingRenderer: false
    property string selectedType: stretchTypeCombo.currentText

    states: [
        State {
            name: "orientHorizontal"
            when: width > height
            PropertyChanges {
                target: layout
                flow: GridLayout.LeftToRight
                labelAlignment: Qt.AlignRight
                columns: 4
            }
        },
        State {
            name: "orientVertical"
            when: width <= height
            PropertyChanges {
                target: layout
                flow: GridLayout.TopToBottom
                labelAlignment: Qt.AlignLeft
                rows: 4
            }
        }
    ]

    // add a mapView component
    MapView {
        anchors.fill: parent
        objectName: "mapView"
    }

    Rectangle {
        visible: editButton.visible
        anchors.centerIn: editButton
        radius: 8
        height: editButton.height + 16
        width: editButton.width + 16
        color: "lightgrey"
        border.color: "darkgrey"
        border.width: 2
        opacity: 0.75
    }

    Button {
        id: editButton
        anchors {
            bottom: parent.bottom
            horizontalCenter: parent.horizontalCenter
            margins: 32
        }
        visible: rendererBox.width === 0
        text: "Edit Renderer"
        onClicked: editingRenderer = true;
    }

    Rectangle {
        id: rendererBox
        clip: true
        anchors {
            right: parent.right
            top: parent.top
            bottom: parent.bottom
        }

        color: "white"
        opacity: 0.75
        width: editingRenderer ? parent.width : 0
        visible: width > 0

        ComboBox {
            id: stretchTypeCombo
            anchors {
                bottom: layout.top
                left: layout.left
                right: layout.right
                margins: 5
            }

            model: stretchTypes
            property int modelWidth: 0
            Layout.minimumWidth: modelWidth + leftPadding + rightPadding + indicator.width
            Component.onCompleted : {
                for (let i = 0; i < model.length; ++i) {
                    metrics.text = model[i];
                    modelWidth = Math.max(modelWidth, metrics.width);
                }
            }
            TextMetrics {
                id: metrics
                font: stretchTypeCombo.font
            }
        }

        GridLayout {
            id: layout
            property int labelAlignment
            anchors {
                centerIn: parent
                margins: 24
            }

            Text {
                text: "Min"
                Layout.alignment: layout.labelAlignment
                visible: selectedType === minMax
            }

            Repeater {
                id: minMaxMin
                model: 3
                SpinBox {
                    editable: true
                    visible: selectedType === minMax
                    from: 0
                    to: 255
                    value: from
                }
            }

            Text {
                text: "Max"
                Layout.alignment: layout.labelAlignment
                visible: selectedType === minMax
            }

            Repeater {
                id: minMaxMax
                model: 3
                SpinBox {
                    editable: true
                    visible: selectedType === minMax
                    from: 0
                    to: 255
                    value: to
                }
            }

            Text {
                text: "Min"
                Layout.alignment: layout.labelAlignment
                visible: selectedType === percentClip
            }

            SpinBox {
                id: percentClipMin
                editable: true
                visible: selectedType === percentClip
                Layout.columnSpan: 3
                from: 0
                to: 100
                value: from
            }

            Text {
                text: "Max"
                Layout.alignment: layout.labelAlignment
                visible: selectedType === percentClip
            }

            SpinBox {
                id: percentClipMax
                editable: true
                visible: selectedType === percentClip
                Layout.columnSpan: 3
                from: 0
                to: 100
                value: to
            }

            Text {
                text: "Factor"
                Layout.alignment: layout.labelAlignment
                visible: selectedType === stdDeviation
            }

            SpinBox {
                id: sdFactor
                editable: true
                visible: selectedType === stdDeviation
                Layout.columnSpan: 3
                property int decimals: 2
                property real realValue: value / 100
                from: 0
                to: 25 * 100
                value: 0

                validator: DoubleValidator {
                    bottom: Math.min(sdFactor.from, sdFactor.to)
                    top: Math.min(sdFactor.from, sdFactor.to)
                }

                textFromValue: function(value, locale) {
                    return Number(value / 100).toLocaleString(locale, 'f', sdFactor.decimals);
                }

                valueFromText: function(text, locale) {
                    return Number.fromLocaleString(locale, text) * 100;
                }
            }
        }

        Button {
            text: "Render"
            anchors {
                top: layout.bottom
                left: layout.left
                right: layout.right
                margins: 5
            }
            onClicked: {
                editingRenderer = false;
                applyRendererSettings();
            }
        }

        Behavior on width { PropertyAnimation { duration: 500 } }
    }

    function applyRendererSettings(){
        if (selectedType === minMax){
            applyMinMax(minMaxMin.itemAt(0).value, minMaxMin.itemAt(1).value, minMaxMin.itemAt(2).value,
                        minMaxMax.itemAt(0).value, minMaxMax.itemAt(1).value, minMaxMax.itemAt(2).value);
        }
        else if (selectedType === percentClip){
            applyPercentClip(percentClipMin.value, 100 - percentClipMax.value);
        }
        else if (selectedType === stdDeviation){
            applyStandardDeviation(sdFactor.realValue);
        }
    }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.