Raster data provides a unique way of analyzing and visualizing geographic phenomena. Rasters consist of a matrix of cells, with each cell containing a value. Rasters can have multiple dimensions or bands, for example, the red, green, and blue channels in an aerial photo. Rasters are different from vectors, which use points, lines, and polygons to represent features. For more information on raster data, including advantages and disadvantages of using it, see What is raster data? in ArcGIS Desktop help.

Raster data is represented by the Raster class. Your ArcGIS Runtime app can work with many sources of raster data including raster files, mosaic datasets, raster data shared through image services, or the results of raster functions. A raster function can take any of these rasters as input for analysis.

Create a raster from a raster file

To add raster files stored on your desktop or device to your app, create aRaster object using the path of the raster file.

// create a raster from a path to a supported raster format
Raster myRaster = new Raster(pathToRaster);
// create a RasterLayer using the Raster
RasterLayer newRasterLayer = new RasterLayer(myRaster);

Load a raster from a GeoPackage

A GeoPackage is an open, standards-based, platform-independent, portable, self-describing, compact format for transferring geospatial information. It is a platform-independent SQLite database file that contains data and metadata tables. For details, refer to the OGC GeoPackage specification. Using ArcGIS Runtime SDK, you can read a local GeoPackage and load the feature tables and rasters it contains.

Open a GeoPackage using the path to the file (.gpkg). The GeoPackageRasters property returns a collection of all rasters in the package. You can work with a GeoPackageRaster as you would any other Raster, including adding it as a RasterLayer to your app's map.

// Open a local GeoPackage (.gpkg)
GeoPackage myGeoPackage = await GeoPackage.OpenAsync(geoPackageFilePath);
// Get the collection of rasters in the package
IReadOnlyList<GeoPackageRaster> packageRasters = myGeoPackage.GeoPackageRasters;
// Get the first raster in the collection
GeoPackageRaster firstRaster = packageRasters[0];
// Create a RasterLayer using the GeoPackageRaster (which inherits from Raster)
RasterLayer newRasterLayer = new RasterLayer(firstRaster);

Create a raster from a mobile mosaic dataset

Raster data stored in a mobile mosaic dataset should be read through the MosaicDatasetRaster, which inherits from Raster. The MosaicDatasetRaster object is instantiated with a path of the mobile geodatabase and a name of the dataset.

Create a new mobile mosaic dataset and add raster files to it

MosaicDatasetRaster can also be used to create a mobile mosaic dataset in a new mobile geodatabase and save it to the device. Once the mobile mosaic dataset is created, individual raster files can be asynchronously added to it. The mobile geodatabase is created when the MosaicDatasetRaster is loaded successfully.

Use the AddRastersParameters class to set the input directory containing the raster files to be added and control other properties of the mosaic such as minimum and maximum pixel sizes.

Create a raster from an image service

Raster and image data can be shared as an image service using ArcGIS Server. An image service provides access to raster data through a web service. A single raster dataset or a mosaic dataset which contains a collection of raster datasets can be served as one image service. The mosaic dataset can dynamically process and mosaic the images on-the-fly. An image service supports accessing both the mosaicked image and its catalog, as well as individual rasters in the catalog. For more information on image services, see Key concepts for image services in the ArcGIS help.

Use the ImageServiceRaster class to work with image services in your ArcGIS Runtime app. You can create an ImageServiceRaster with the URL of an image service. And then if you want to display the raster data on a map, create a raster layer for it.

ImageServiceRaster is a subclass of Raster, so any operation that can be applied to the Raster class, such as raster functions, can also be applied to ImageServiceRaster. Besides the common properties inherited from the Raster class, ImageServiceRaster has additional properties and capabilities such as the image service metadata and rendering rules. Once the image service raster has been loaded, the metadata of the image service can be retrieved through the service info property, which is represented by ArcGISImageServiceInfo. However, only a subset of the metadata including attribution text and a list of info of predefined service rendering rules are exposed in ArcGIS Runtime. For more info on the metadata of an image service, see Image Service in the ArcGIS REST API help.

// Create an image service raster from a URI
ImageServiceRaster serviceRaster = new ImageServiceRaster(new Uri("http://sampleserver6.arcgisonline.com/arcgis/rest/services/CharlotteLAS/ImageServer"));
// When the image service raster loads, the service info and rendering rule info will be available
serviceRaster.Loaded += (s, e) =>
{
// Get service info
ArcGISImageServiceInfo serviceInfo = serviceRaster.ServiceInfo;
// Get rendering rule info list
IReadOnlyList<RenderingRuleInfo> renderingRuleInfos = serviceInfo.RenderingRuleInfos;
// Call a function to load the raster with one of the rules
// (Note: the rendering rule cannot be set on an ImageServiceRaster that is already loaded)
AddRasterWithRenderingRule(renderingRuleInfos[3]);
};
// Load the image service raster
serviceRaster.LoadAsync();

Rendering rules

A rendering rule defines how the requested image should be rendered or processed. ImageServiceRaster allows you to apply service-defined or client-defined rendering rules on an image service by setting its rendering rule property. You can create a RenderingRule from a RenderingRuleInfo object or a JSON string that specifies a service-defined or client-defined rendering rule and then set it on the image service raster. For the syntax of rendering rules, see raster function (JSON) objects in the ArcGIS REST API help.

The following example uses a raster function (stored in a local JSON file).

// Create a new hillshade raster function from a JSON definition (stored in a text file).
var hillshadeFunction = new RasterFunction(pathToHillshadeFunctionJSON);
// Get the function's arguments.
RasterFunctionArguments rasterFunctionArguments = hillshadeFunction.Arguments;
// Assuming rasterNames has 1 entry, set the input raster.
IReadOnlyList<string> rasterNames = rasterFunctionArguments.GetRasterNames();
var inputRaster = new Raster(pathToInputTIF);
rasterFunctionArguments.SetRaster(rasterNames[0], inputRaster);
// Create a new raster based on the function.
Raster raster = new Raster(hillshadeFunction);
// Create a RasterLayer to display the Raster, add it to the map.
RasterLayer rasterLayer = new RasterLayer(raster);
MyMapView.Map = new Map(new Basemap(rasterLayer));

Raster functions supported by ArcGIS Runtime

ArcGIS Runtime supports a subset of raster functions supported by the ArcGIS REST API. The raster functions supported by ArcGIS Runtime are provided in this section, along with the syntax for using them. The syntax is close to the ArcGIS REST syntax for the same functions but is not exactly the same.

The general syntax for ArcGIS Runtime raster functions is the following:

Add a raster using a raster layer

It's not necessary to display the raster data you work with in your app. However, if you want your users to view raster data on a map, add the raster using the RasterLayer class. RasterLayer can render raster data from any type of Raster.

You can add it to a map as either a basemap or an operational layer. When adding a raster layer as an operational layer to a map with different spatial reference, the layer will be reprojected on the fly and be added to the map.

You can also change the renderer, as described below, to control how the data is visualized on the map.

See Layers and tables for more information about creating and working with raster layers.

Change the renderer

When a raster layer is created from a raster, a default renderer is used to display the data on a map. As with other layer types supported by ArcGIS Runtime, a raster layer allows you to change how it is symbolized by creating a raster renderer (RasterRenderer) and applying it to the layer. When you change the renderer of a raster layer, only the display properties of the layer are updated. The underlying raster data won’t be affected.

RasterRenderer is the base class inherited by all renderers available to display a raster layer and allows you to control how raster data are presented (visualized). Each of the following renderers are types of RasterRenderer and can be used to display your raster layer in different ways.

HillshadeRenderer—Creates a grayscale 3D representation of an elevation surface, with the sun's (hypothetical) position taken into account for shading the image. It can be applied to a raster layer created with single-band raster data.

BlendRenderer—Blends a hillshade image (derived from the raster) with the original raster. This provides a look similar to the original raster but with some terrain shading, for a rich, textured look.

ColormapRenderer—Provides a discrete mapping of raster pixel values to colors. All pixels matching the specified value are rendered using the mapped color. This can be useful for tasks such as land classification.

StretchRenderer—Displays continuous raster cell values across a gradual ramp of colors. Use the stretch renderer to draw a single band of continuous data. The stretch renderer works well when you have a large range of values to display, such as in imagery, aerial photographs, or elevation models.

RGBRenderer—Uses the same methods as the stretch renderer but allows you to combine bands as red, green, and blue composites.

About raster data

A raster consists of a matrix of cells (pixels) organized into rows and columns (a grid, in other words) where each cell contains a value representing information. Rasters are things like digital aerial photographs, imagery from satellites, digital pictures, elevation models, output from spatial analysis, and so on. Rasters used as GIS data are generally categorized into two broad types: thematic, representing discrete features on the ground in much the same way a polygon data set might (zoning or land use, for example) and continuous, modeling a phenomenon that changes continuously across a surface (temperature or elevation, for example). Photographs and scanned images are another type of raster data that you might use in your mapping app, perhaps for visualizing an area or as additional information associated with features in your map.