Before tackling this tutorial, you will need to download and install a dataset following these instructions:
Create a folder called MapAlgebraGlobal somewhere under your personal directory (e.g. C:\Users\jdoe\Documents\Tutorials\MapAlgebraGlobal\).
Download the data for this exercise then extract the contents of MapAlgebraGlobal.zip into your newly created MapAlgebraGlobal folder.
Make sure that you have the Spatial Analyst extension enabled for this exercise. For a refresher on how to enable the extension, click here.
Open the Zonal_Global.aprx map document.
The map consists of Walmart store point locations across the US. This tutorial will explore the use of global and zonal raster operations. The objectives will be to estimate the average distance to the closest Walmart stores nationwide and the average distances to the closest Walmart within each state.
The first step will therefore involve creating a euclidean distance raster layer from the point layer—a global operation.
NOTE:
Earlier versions of this tutorial made use of the Euclidean Distance tool. Esri plans to deprecate this tool in a future release of the software and is therefore recommending that the Distance Accumulation tool be used instead. This is the function used in this updated version of the tutorial.
In the Geoprocessing search window, type Distance Accumulation .
Click on the Distance Accumulation tool associated with the Spatial Analyst extension.
Set the input feature source to Walmarts.
Name the output raster Distance2Walmarts.tif.
Recall from earlier tutorials that raster files can be stored in many different file formats such as .img or .tif. You must therefore explicitly define the raster file format with the filename extension. In this tutorial, we'll stick with the .tif file format.
The output raster will adopt the same extent used to define the Walmarts point layer extent (the input layer in this example). This will mean that not all parts of the contiguous US states will have a pixel value (the point layer's extent is smaller then the States layer's extent) . To change the output extent, you can define a different output extent in the Environments settings.
Click on the Environments tab.
Under Processing Extent, click on the layers pull-down menu and select the States layer.
The States layer encompasses all of the 48 states. This will ensure that the output raster will cover the same extent as that of the States layer.
You'll note that the Environments settings will also allow you to define the desired output coordinate system. By default, the output will inherit the input layer's coordinate system (and not necessarily that of the map).
Because we are creating a new raster from scratch, we should explicitly define the pixel dimension. In this tutorial we will adopt a 10 km pixel size
While still in the Environments tab, type 10000 in the Cell Size field under the Raster Analysis rubric.
Given that the tool does not offer an option to specify the cell size units, we must assume that the tool will adopt the units associated with the layer's coordinate system (meters in this example).
We'll also define the mask. The mask is used to assign NoData values to pixels outside of a defined boundary. Here, we'll set the boundary to the States layer.
Set the Mask to States.
Note that the mask option will restrict the input points to the extent defined by the mask, this is not a problem here since the mask encompasses all the points. However, if input points or features are outside of the mask, it’s best to leave the mask field blank and clip the output euclidean distance raster output using the Extract by Mask tool.
Don't forget to turn off any overlying polygon layers in the Contents pane to view the output raster since the raster will be added to the bottom of the stack.
NOTE:
Each pixel of the output raster displays the distance from that pixel to the closest Walmart point feature. The distance units are those of the layer's coordinate system (meters in this example). Also note that the distance is sensitive to the coordinate system used (i.e. you should choose one that preserves distance)! If you are unsure if your coordinate system preserves distance and if computational resources are not an issue, you should adopt the geodesic method of distance measurement over the default planar method in the Euclidean distance tool.
Next, you will identify all locations (pixels) that are within 20 km of a Walmart.
We'll reclassify the euclidean distance raster to binary values: 0’s for distances greater than 20 km and 1’s for distances less than or equal to 20 km. There are at least two ways in which this step can be accomplished: one approach is to use the Raster Calculator tool and the other is to use the Reclassify tool (see the Local Operations tutorial for a refresher). Regardless which method you choose to use make, sure to name the output raster Dist20k.tif.
In this example, we'll use the Raster Calculator tool.
Open the Raster Calculator tool.
Define the expression as:
Con("Distance2Walmarts.tif" <= 20000, 1, 0)
Note the upper case "C" in "Con"--the function is case sensitive.
Name the output raster Dist20k.tif.
Click Run.
The output map is a binary raster. As such, it has an attribute table listing the number of 0 and 1 pixels in the raster.
From these values we can compute the percentage of all locations within the 48 states that are within 20 km of a nearest Walmart, or 24,626 / (56,101 + 24,626 ) = 30.5%.
Note that had you used a geodesic method in computing the euclidean distance raster in the earlier step, you would have ended up with a different (and more accurate) set of values ( 25.6% vs 30.5%)--this despite the projected coordinate system adopted in this exercise being identified as an "equidistant" projection!
In this next step, you will learn how to summarize pixel values by state using a zonal operation.
Note that zonal operations should be performed on coordinate systems that preserve area so as to ensure proper representation of all locations within each polygon.
For brevity, we'll assume that this coordinate system does a decent job in preserving area in this tutorial, but in practice, you would want to reproject the layers to a CS that preserves area.
Open the Zonal Statistics as Table geoprocessing tool (open the one associated with the Spatial Analyst extension).
The zone layer can be either a raster or a vector. In this working example, we will use the States vector layer as the feature zone data.
Set the Zone field to Name (this will be the input field name that will populate the output table).
Set the input value raster to Distance2Walmarts.tif.
Name the output table Dist2Wal_by_State.dbf. Don't forget to add the extension name and be sure to save it outside of the geodatabase.
ArcGIS will not directly export to a CSV or Excel file. The only valid output format is a .dbf file if it's saved outside of a geodatabase.
Click Run.
Open the newly created table to view its contents.
For each polygon in the States layer, a set of distance-to-Walmart summary statistics is tabulated. The output table copies the Name column from the input States layer—this will allow us to join this table back to the States vector layer in the following step.
Note that the zonal statistics tool adds a Count column giving the total number of pixels covered by each polygon region and the total (surface) Area covered by those pixels in the layer's coordinate system units (meters in our working example).
Using techniques covered in the Joining tables tutorial, join this table back to the States layer, then symbolize the features by Mean distance to the closest Walmart.
This wraps up this exercise.