RGB renderer

View on GitHubSample viewer app

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

RGB renderer settings RGB renderer edited

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 the toolbar button to change the settings for the RGB renderer. You can change the stretch type and the parameters for each type.

How it works

  1. Create an AGSRaster from a local raster file.
  2. Create an AGSRasterLayer from the raster.
  3. Create an AGSBasemap from the raster layer and set it to the map.
  4. Create an AGSRGBRenderer, specifying the stretchParameters and other properties.
  5. Set the raster layer's renderer to the AGSRGBRenderer.

Relevant API

  • AGSBasemap
  • AGSRaster
  • AGSRasterLayer
  • AGSRGBRenderer
  • AGSStretchParameters

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

RGBRendererViewController.swiftRGBRendererViewController.swiftRGBRendererSettingsViewController.swift
Use dark colors for code blocksCopy
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
//
// Copyright 2016 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.

import UIKit
import ArcGIS

class RGBRendererViewController: UIViewController, RGBRendererSettingsViewControllerDelegate {
    @IBOutlet var mapView: AGSMapView!

    private var rasterLayer: AGSRasterLayer?

    override func viewDidLoad() {
        super.viewDidLoad()

        // add the source code button item to the right of navigation bar
        (navigationItem.rightBarButtonItem as! SourceCodeBarButtonItem).filenames = ["RGBRendererViewController", "RGBRendererSettingsViewController", "OptionsTableViewController"]

        // create raster
        let raster = AGSRaster(name: "Shasta", extension: "tif")

        // create raster layer using the raster
        let rasterLayer = AGSRasterLayer(raster: raster)
        self.rasterLayer = rasterLayer

        // initialize a map with raster layer as the basemap
        let map = AGSMap(basemap: AGSBasemap(baseLayer: rasterLayer))
        // assign map to the map view
        mapView.map = map
    }

    // MARK: - RGBRendererSettingsViewControllerDelegate

    func rgbRendererSettingsViewController(_ rgbRendererSettingsViewController: RGBRendererSettingsViewController, didSelectStretchParameters parameters: AGSStretchParameters) {
        let renderer = AGSRGBRenderer(stretchParameters: parameters, bandIndexes: [], gammas: [], estimateStatistics: true)
        rasterLayer?.renderer = renderer
    }

    // MARK: - Navigation

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if let navController = segue.destination as? UINavigationController,
            let controller = navController.viewControllers.first as? RGBRendererSettingsViewController {
            controller.preferredContentSize = CGSize(width: 375, height: 135)
            controller.delegate = self
            if let parameters = (rasterLayer?.renderer as? AGSRGBRenderer)?.stretchParameters {
                controller.setupForParameters(parameters)
            }
            navController.presentationController?.delegate = self
        }
    }
}

extension RGBRendererViewController: UIAdaptivePresentationControllerDelegate {
    func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
        return .none
    }
}

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