Raster data provides a unique way to analyze and visualize 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? and Imagery and raster in ArcGIS Pro in the ArcGIS Desktop help.
Raster data is represented by the Raster class. Your 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 a Raster object using the path of the raster file.
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. You can read a local GeoPackage and load the feature tables and rasters that it contains.
Open a GeoPackage using the path to the .gpkg file. 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.
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
// create a raster from a path to a supported raster formatval geoPackagePath = getExternalFilesDir(null)?.path.toString() + File.separator + localGeopackageName
// open the GeoPackageval geoPackage = GeoPackage(geoPackagePath)
lifecycleScope.launch {
geoPackage.load().onSuccess {
val geoPackageRasters = geoPackage.geoPackageRasters
if (geoPackageRasters.isNotEmpty()) {
// read raster images ane get the first oneval geoPackageRaster = geoPackageRasters[0]
// create a layer to display the rasterval rasterLayer = RasterLayer(geoPackageRaster)
mapView.map?.operationalLayers?.add(rasterLayer)
}
}.onFailure { Log.e(localClassName, "Geopackage failed to load.") }
}
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.
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Get mosaic dataset names in the SQLite database.val sqliteDbPath = getExternalFilesDir(null)?.path.toString() + File.separator + sqliteDbName
val rasterNames = MosaicDatasetRaster.getNames(sqliteDbPath)
// check that the rasterNames list is not emptyif (rasterNames.isNotEmpty()) {
// Get the first raster name in the list rasterNames.val rasterName = rasterNames[0]
// Create a raster from a mosaic dataset.val raster = MosaicDatasetRaster(sqliteDbPath, rasterName)
// Create a raster layer using the raster.val rasterLayer = RasterLayer(raster)
// Load the raster layer lifecycleScope.launch {
rasterLayer.load().onSuccess {
val extent = rasterLayer.fullExtent ?: return@launch showError("Error retrieving extent of the raster layer.")
mapView.setViewpoint(Viewpoint(extent))
}.onFailure { showError("Raster layer failed to load.") }
}
// Add the raster layer to the map's operational layers map.operationalLayers.add(rasterLayer)
}
Create a mobile mosaic dataset and add raster files
MosaicDatasetRaster can also be used to create a mobile mosaic dataset in a new mobile geodatabase and save it to the device. After 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 perform tasks, such as the following:
Set the input directory containing the raster files to be added
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 that 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 app. You can create an ImageServiceRaster with the URL of an image service. And if you want to display the raster data on a map, create a raster layer for it.
For mosaicked images, a mosaic rule defines how the individual rasters are combined. You can use the default rule defined with the service or, starting with 100.9.0, define rule settings to control how overlapping areas in the mosaic are handled. In addition to how it's displayed, the mosaic rule may effect values returned when identifying, computing a histogram, or exporting the image.
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. After 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 information on predefined service rendering rules, is exposed by this API. For more information on the metadata of an image service, see Image Service in the ArcGIS services reference.
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Create an image service raster from a URIval imageServiceURL = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Toronto/ImageServer"val serviceRaster = ImageServiceRaster(imageServiceURL)
// When the image service raster loads, the service info and renderingrule info will be available lifecycleScope.launch {
// Load the service raster so you can get its list of rendering rule infos serviceRaster.load().onSuccess {
// Get service info.val serviceInfo = serviceRaster.serviceInfo
//Get rendering rule info list.val renderingRuleInfos = serviceInfo?.renderingRuleInfos ?: return@launch showError("renderingRuleInfos is null")
// Load the raster with one of the rendering rules.val myRenderingRule = RenderingRule(renderingRuleInfos[3])
// Note: the rendering rule cannot be set on an ImageServiceRaster that is already loaded.// So you must create a new image service raster if you wish to display it.val myImageServiceRaster = ImageServiceRaster(imageServiceURL).apply {
renderingRule = myRenderingRule
}
// Load the image service raster you just created myImageServiceRaster.load().onSuccess {
val rasterLayer = RasterLayer(myImageServiceRaster)
mapView.map?.operationalLayers?.add(rasterLayer)
val viewpoint = Viewpoint(43.68214855521651, -79.39198661793522, 400000.0)
mapView.setViewpoint(viewpoint)
}.onFailure { showError("myImageServiceRaster failed to load.") }
}.onFailure { showError("serviceRaster failed to load.") }
}
Create a raster from a raster function
Raster functions can be applied to a raster to process that data. This processing is not permanently applied to the data; instead, it is applied on the fly as the rasters are accessed.
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
// Create raster function from json string.// If RasterFunction.fromJson() returns null, then return from current function, showing error message.val hillsideRasterFunctionFromJson = RasterFunction.fromJsonOrNull(getString(R.string.hillshade_simplified))
?: return showError("Error creating raster function from Json file.")
// Get parameter name value pairs used by hillside.val hillsideRasterFunctionArguments = hillsideRasterFunctionFromJson.arguments
// Get a list of raster names associated with the raster function.val rasterNames = hillsideRasterFunctionArguments?.rasterNames
// Set an existing raster as an argument to the raster function. This is the raster that will be// modified by the function. hillsideRasterFunctionArguments?.setRaster(rasterNames?.get(0).toString(), raster)
// Create a Raster object for the modified raster returned by the raster function.// Then create a raster layer from it.val modifiedRaster = Raster.createWithRasterFunction(hillsideRasterFunctionFromJson)
val hillshadeRasterLayer = RasterLayer(modifiedRaster)
mapView.map?.operationalLayers?.add(hillshadeRasterLayer)
Supported Raster functions
The supported raster functions are detailed in this section, along with the syntax for using them. Note that the syntax is similar to the ArcGIS REST syntax for the same functions but is not exactly the same.
The general syntax for raster functions is the following:
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
{
"raster_function":{"type":"<Raster Function Name>"},
"raster_function_arguments":
{
"argument1":"<JSON Value Object>",
"argument2":"<JSON Value Object>",
"argumentN":"<JSON Value Object>",
"type":"Raster_function_arguments" },
"type":"Raster_function_template"}
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. See Layers for more information about creating and working with raster layers.
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
70
71
72
73
74
75
76
77
78
79
// create a raster layer using the rasterval rasterLayer = RasterLayer(raster)
lifecycleScope.launch {
rasterLayer.load().onSuccess {
// Create a basemap using the raster layer. Then pass the basemap to the ArcIGSMap constructor.val map = ArcGISMap(Basemap(rasterLayer))
// Alternatively, you could add the raster layer as an operational layer.// map.operationalLayers.add(rasterLayer) }.onFailure { Log.e(localClassName, "Raster layer failed to load.") }
}
You can add a raster layer 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 added to the map.
Supported raster formats
This API supportes a subset of raster file formats that ArcGIS Desktop supports. The supported raster file formats include: