This tutorial will expose you to the fundamentals of local map algebra operations applied to raster data models. This tutorial was created using ArcGIS Pro version 3.3.
Note that this tutorial makes use of the Spatial Analyst extension. Your installation of ArcGIS Pro should therefore be configured with the Spatial Analyst extension enabled.
Before starting this tutorial, you will need to download and install a dataset following these instructions:
Create a folder called local_operations in your tutorials directory (e.g. C:\Users\yourname\Documents\ArcPro_tutorials\local_operations\).
Download the data for this exercise then extract the contents of local_operations.zip into your newly created local_operations folder.
You will want to read Chapter 10 of the textbook before completing this lab.
Open the local_operations.aprx file.
The project consists of two data layers: the bathymetry.img raster and the elevation.img raster. The former shows ocean depth measurements (positive downwards) and elevation measurements above mean sea level (positive upwards). In both rasters, a value of 0 is assigned to any negative measurements. Hence, for the bathymetry layer, any measurement above mean sea level is assigned a value of 0. Likewise, in the elevation raster, any measurement below mean sea level is assigned a value of 0. Cell units are in meters.
The goal is to combine the two complementary rasters into a single elevation raster. This, and subsequent raster operations will make use of geoprocessing tools only accessible via the Spatial Analyst extension.
Since the two rasters complement one another (i.e. one represents elevation above mean sea level and the other represents elevation below mean sea level), we can combine them algebraically as we would with matrices. However, the bathymetric values are positive downward which is a problem since elevation values are positive in the upward direction. So we need to multiply the bathymetry layer by -1 before adding it to the elevation layer.
In the Geoprocessing pane search window, type raster calculator.
Click on the Raster Calculator (Spatial Analyst Tools) tool (this may be the second option in the search results).
Note that the same tool may appear under different toolboxes. Here, Raster Calculator is available under both the Spatial Analysts toolbox and the Image Analyst toolbox.
In the Raster Calculator expression box, type the following expression:
"elevation.img" - "bathymetry.img"
You are encouraged to double-click on the layer names under the Rasters block window. This will automatically populate the expression box thus minimizing typos.
Name the output elev.img (note the .img extension specified in the filename--see grey block below). Be sure to save it outside of a geodatabase.
Click Run.
When not saving a raster inside of a geodatabase, it's important to specify the raster file format via the extension name. Two popular formats include *.img and *.tif. In this tutorial, we will be adopting the *.img file format. In subsequent tutorials, we will adopt the more popular *.tif format.
When saving a raster inside of a geodatabase, do not add an extension to the raster name. Doing so will throw an error.
The new raster incorporates both elevation values and bathymetric values (which are now assigned negative numbers).
In this step, you will perform another local operation where the output raster will be binary: a value of 0 will represent water pixels and a value of 1 will represent land pixels. The input elevation values will be used to determine the cutoff (i.e. all elevation pixels greater than or equal to zero will be 1 in the output and all values less than zero will be 0).
We will implement three different approaches. Each will generate the same raster output:
the first option will use the Con() function;
the second option will use a simple algebraic expression;
the third option will make use of a reclassification tool.
This method makes use of the Con() function for conditional evaluation.
Open the Raster Calculator geoprocessing tool then type the following expression
Con( "Elev.img" >= 0, 1, 0)
Note the uppercase “C” in Con (the function is case sensitive).
Name the output land_water.img (don't forget the .img extension).
The above conditional statement reads “if a pixel from the Elev.img layer has a value greater than or equal to 0 set the output pixel value to 1 if not, set it to 0”.
If you want the output to be NoData when the condition is not met, you can simply leave the third argument blank. For example: Con( "elev.img" >= 0 , 1 , ) will assign NoData values to pixels whose elev.img values are less than 0.
Note that leaving the second argument blank (i.e. attempting to assign NoData if the condition is met), will generate an error.
A more succinct approach to creating the land/water raster is to apply a simple algebraic operation, i.e. “Elev” >= 0.
Open the Raster Calculator geoprocessing tool, then type the following expression
"Elev.img" >= 0
Name the output land_water.img (don't forget the .img extension). If you already created this raster in the previous step, name it land_water2.img.
The above condition is evaluated for each pixel, if it’s true (i.e. if the pixel value is greater than or equal to 0), the output pixel of the new raster will be assigned a value of 1 (for TRUE), if not, it will be assigned a value of 0 (for FALSE).
The third method makes use of the reclassification tool.
In the Geoprocessing search window, type Reclassify. Select the Reclassify tool associated with the Spatial Analyst extension.
Set the Input raster to elev.img.
Set the Reclass field to Value (these are the input values that will be reclassified).
To define the classification breaks, we will make use of the Classify option. Click on Classify
Do not change the Classification method just yet, doing so will ghost out the Classes field (the default should be set to Natural Breaks).
Set the number of classes to 2
Set the Upper values for each bin to -1 (this is the largest "water" pixel value) and 6821 (the last value being the largest value in the raster).
Once you change the upper bound values, you will note the classification method switch to Manual Interval.
Click OK.
Change the New values to 0 and 1.
Name the output land_water.img (or land_water3.img if you created the output raster using the two previous methods).
Click Run.
All three methods should generate the same binary (two values) layer.
If the raster data has values stored as integers, and if there are no more than 65,535 unique pixel values (see ArcGIS reference) a raster attribute table is usually present.
The land_raster.img raster is stored as an integer. This will enable us to tally the pixel counts for each unique pixel value.
Right-click on the land_water.img layer and select Attribute Table.
You should see two rows in the attribute table--each indicating the number of times (Count field) a value (Value field) is present in the raster. The value 0 (representing water) is found 391,205 times while the value 1 is found 191,995 times.
Since the pixels (or grid cells) have the same dimensions across the entire raster extent, the fraction of the earth’s surface covered by water can be estimated from these pixel counts alone. However, the current raster is in a WGS 1984 geographic coordinate system. This is problematic since ArcGIS applies a cylindrical coordinate system to GCS rasters (most likely a Plate Carrée projection) which may not properly preserve area across the map's entire extent.
We therefore must project the land_water raster to a coordinate system that preserves area to ensure that the distribution of land and water pixels are properly represented across the map's extent. In the following steps, you will project the raster layer to a World Sinusoidal PCS--one of many coordinate system that preserves area across the globe.
In the geoprocessing window pane, navigate back to the Search window by clicking on the back arrow in the upper left-hand corner of the pane.
Type Project Raster in the search window.
Click on the Project Raster tool from the search results.
Set land_water.img as the input layer.
Name the output land_water_sin.img.
Set the output coordinate system to World Sinusoidal (Projected Coordinate Systems >> World >> Sinusoidal (world) )
Keep the other defaults.
Click Run.
At first glance, the sinusoidal raster does not look different from that of the unprojected (GCS) raster. However, when zooming in near the polar regions, you’ll note that the sinusoidal pixels are distorted (i.e. they are not square shaped).
To view the new raster layer in its native coordinate system, change the Map’s coordinate system to World Sinusoidal by right-clicking on the map’s name and selecting Properties then the Coordinate system tab. You can select the coordinate system from the Layer’s folder instead of navigating through the different PCS options.
Close the Properties window.
Note: As of version 3.0 of ArcGIS Pro, the software may not properly update the count field in the projected raster attribute table. This results in erroneous pixel counts! A workaround is to run the Build Raster Attribute Table on this table to update the count values. This step is shown next.
Navigate back to the Search field in the Geoprocessing pane.
Type build raster in the search field.
Click on the Build Raster Attribute Table tool from the list of options.
Set land_water_sin.img as the input layer.
Check the Overwrite box. This will overwrite the current count field.
Click Run.
Note that you might need to close, then reopen the attribute table to see the changes in count values.
The new (corrected) Value counts for 0’s and 1’s should now read 264,984 and 106,082 respectively.
Recall that 0’s represent water, hence the fraction of water covering the earth’s surface can be estimated from this raster as 264,984 / (264,984 + 106,082) = 0.71 (or 71%).
This wraps up this in-class lab activity.