{"id":702122,"date":"2020-02-06T09:30:13","date_gmt":"2020-02-06T17:30:13","guid":{"rendered":"https:\/\/www.esri.com\/arcgis-blog\/?post_type=blog&#038;p=702122"},"modified":"2020-10-13T19:26:06","modified_gmt":"2020-10-14T02:26:06","slug":"unleash-the-power-of-rastercelliterator-to-perform-custom-raster-analysis","status":"publish","type":"blog","link":"https:\/\/www.esri.com\/arcgis-blog\/products\/spatial-analyst\/analytics\/unleash-the-power-of-rastercelliterator-to-perform-custom-raster-analysis","title":{"rendered":"Unleash the power of RasterCellIterator to perform custom raster analysis"},"author":8212,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","format":"standard","meta":{"_acf_changed":false,"_searchwp_excluded":""},"categories":[23341],"tags":[24341,540462,540482,39421,540472],"industry":[],"product":[37031],"class_list":["post-702122","blog","type-blog","status-publish","format-standard","hentry","category-analytics","tag-python","tag-raster-cell-iterator","tag-raster-info","tag-spatial-analyst","tag-whats-new-in-pro-2-5","product-spatial-analyst"],"acf":{"short_description":"Use Raster Cell Iterator, a new functionality in the Spatial Analyst module to solve some real-world problems.","flexible_content":[{"acf_fc_layout":"content","content":"<p>If you&#8217;ve read through the <a href=\"https:\/\/www.esri.com\/arcgis-blog\/?post_type=blog&amp;p=708092\">Introducing the Raster Cell Iterator<\/a> blog, you&#8217;ll be familiar with the basic concepts of the <a href=\"https:\/\/pro.arcgis.com\/en\/pro-app\/help\/analysis\/spatial-analyst\/raster-cell-iterator\/what-is-the-raster-cell-iterator.htm\">Raster Cell Iterator<\/a> (RCI), a new ArcPy class added in ArcGIS Pro 2.5 in the <a href=\"https:\/\/pro.arcgis.com\/en\/pro-app\/arcpy\/spatial-analyst\/what-is-the-spatial-analyst-module.htm\">Spatial Analyst module<\/a> that allows you to iterate over raster cells, query and modify individual cell values.<\/p>\n<p>In this blog, let\u2019s explore how RCI can be used to customize your analysis on problems that cannot be easily solved using the existing out-of-the-box geoprocessing tool. In the first example, we will use RCI to create a new raster with a specific spatial pattern \u2013 checkerboard. And in two other examples, we will use RCI to customize two focal operations: 1) count the number of neighboring cells that have a different value from the center cell, and 2) calculate the minimum slope from a DEM.<\/p>\n<p>&nbsp;<\/p>\n<h2>Create a new raster with the checkerboard pattern<\/h2>\n<p>In atmospheric modeling, a heterogenous surface raster represented by a checkerboard pattern can be used as an initial condition for idealized model simulations. However, there is not an existing geoprocessing tool with which you can create such a raster directly. In earlier ArcGIS releases, you can accomplish this task by using NumPy, but it would require a multi-step workflow to do so.\u00a0 In ArcGIS Pro 2.5 with RCI, this task has become much easier! You simply need to assign a binary value to each cell based on the current row and column while iterating through a raster.\u00a0 Following is a simple code sample which does exactly that.<\/p>\n"},{"acf_fc_layout":"content","content":"<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre style=\"margin: 0;line-height: 125%\"> 1\r\n 2\r\n 3\r\n 4\r\n 5\r\n 6\r\n 7\r\n 8\r\n 9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30\r\n31\r\n32\r\n33\r\n34\r\n35<\/pre>\n<\/td>\n<td>\n<pre style=\"margin: 0;line-height: 125%\"><span style=\"color: #0000ff\">import<\/span> json    \r\n<span style=\"color: #0000ff\">from<\/span> arcpy.sa <span style=\"color: #0000ff\">import<\/span> RasterInfo, Raster  \r\n  \r\n<span style=\"color: #008000\"># Create an empty RasterInfo object  <\/span>\r\nmyRasterInfo = RasterInfo()  \r\n  \r\n<span style=\"color: #008000\"># Load raster info from a Python dictionary  <\/span>\r\nmyRasterInfoData = {  \r\n  <span style=\"color: #a31515\">'bandCount'<\/span>: 1,  \r\n  <span style=\"color: #a31515\">'extent'<\/span>: {  \r\n    <span style=\"color: #a31515\">'xmin'<\/span>: -107.0,  \r\n    <span style=\"color: #a31515\">'ymin'<\/span>: 38.0,  \r\n    <span style=\"color: #a31515\">'xmax'<\/span>: -104.0,  \r\n    <span style=\"color: #a31515\">'ymax'<\/span>: 40.0,  \r\n    <span style=\"color: #a31515\">'spatialReference'<\/span>: {<span style=\"color: #a31515\">'wkid'<\/span>: 4326},  \r\n  },  \r\n  <span style=\"color: #a31515\">'pixelSizeX'<\/span>: 0.01,  \r\n  <span style=\"color: #a31515\">'pixelSizeY'<\/span>: 0.01,  \r\n  <span style=\"color: #a31515\">'pixelType'<\/span>: <span style=\"color: #a31515\">'U8'<\/span>,  \r\n}  \r\n\t  \r\n<span style=\"color: #008000\"># Convert myRasterInfoData to a JSON string and load into myRasterInfo  <\/span>\r\nmyRasterInfo.fromJSONString(json.dumps(myRasterInfoData))  \r\n  \r\n<span style=\"color: #008000\"># Create a new Raster object based on myRasterInfo  <\/span>\r\nmyRaster = Raster(myRasterInfo)  \r\n  \r\n<span style=\"color: #0000ff\">for<\/span> (r, c) <span style=\"color: #0000ff\">in<\/span> myRaster:   \r\n    <span style=\"color: #008000\"># Checkerboard with 10 pixels width  <\/span>\r\n    <span style=\"color: #0000ff\">if<\/span> r % 20 &lt; 10 <span style=\"color: #0000ff\">and<\/span> c % 20 &lt; 10 <span style=\"color: #0000ff\">or<\/span> r % 20 &gt;= 10 <span style=\"color: #0000ff\">and<\/span> c % 20 &gt;= 10:  \r\n        myRaster[r, c] = 1  \r\n    <span style=\"color: #0000ff\">else<\/span>:  \r\n        myRaster[r, c] = 0\r\n\r\nmyRaster.save(r <span style=\"color: #a31515\">'C:\\output\\checkerboard.tif'<\/span>)  \r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n"},{"acf_fc_layout":"content","content":"<p>From the code snippet above, lines 8-23 show the steps to construct a <strong>RasterInfo<\/strong> object from scratch. Line 26 creates an empty raster based on the raster info specified in the previous step. Lines 28-33 show the main logic of creating a checkerboard pattern raster by assigning binary values to the cell based on the current row and column. An implicit way of using Raster Cell Iterator is demonstrated by calling a simple <em>For<\/em> loop to go through all the cells. Since there is only one raster involved in this analysis, you don\u2019t need to create a <strong>RasterCellIterators<\/strong> object explicitly. It is recommended to follow this pattern when you are working with only one raster. Finally, at line 35, we are saving the output raster. Figure 1 shows the output raster with the checkerboard pattern.<\/p>\n"},{"acf_fc_layout":"image","image":{"ID":702162,"id":702162,"title":"2019-12-04_23-07-02","filename":"2019-12-04_23-07-02.png","filesize":182,"url":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/2019-12-04_23-07-02.png","link":"https:\/\/www.esri.com\/arcgis-blog\/products\/spatial-analyst\/analytics\/unleash-the-power-of-rastercelliterator-to-perform-custom-raster-analysis\/2019-12-04_23-07-02","alt":"Output raster with the checkerboard pattern","author":"8212","description":"","caption":"Figure 1. Output raster with the checkerboard pattern","name":"2019-12-04_23-07-02","status":"inherit","uploaded_to":702122,"date":"2020-01-13 23:57:50","modified":"2020-01-14 00:30:03","menu_order":0,"mime_type":"image\/png","type":"image","subtype":"png","icon":"https:\/\/www.esri.com\/arcgis-blog\/wp-includes\/images\/media\/default.png","width":309,"height":205,"sizes":{"thumbnail":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/2019-12-04_23-07-02-213x200.png","thumbnail-width":213,"thumbnail-height":200,"medium":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/2019-12-04_23-07-02.png","medium-width":309,"medium-height":205,"medium_large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/2019-12-04_23-07-02.png","medium_large-width":309,"medium_large-height":205,"large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/2019-12-04_23-07-02.png","large-width":309,"large-height":205,"1536x1536":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/2019-12-04_23-07-02.png","1536x1536-width":309,"1536x1536-height":205,"2048x2048":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/2019-12-04_23-07-02.png","2048x2048-width":309,"2048x2048-height":205,"card_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/2019-12-04_23-07-02.png","card_image-width":309,"card_image-height":205,"wide_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/2019-12-04_23-07-02.png","wide_image-width":309,"wide_image-height":205}},"image_position":"center","orientation":"horizontal","hyperlink":""},{"acf_fc_layout":"content","content":"<h2>Custom Focal Operations<\/h2>\n<p>Focal operations produce an output raster dataset in which the output value at each cell is a function of the input cell value at that location and its neighboring cell values. With RCI, you can customize these kinds of focal operations with more flexibility.<\/p>\n<h3>Count the number of neighboring cells that have a different value from the center cell<\/h3>\n<p>Stathakis &amp; Tsilimigkas (2015) proposed several metrics to calculate the compactness of cities using land use adjacency information. To derive the compactness metric, one of the pre-processing steps is to iterate through the land use data and count the number of neighboring cells that have a value different to the center cell. This focal operation process is illustrated in Figure 2.<\/p>\n"},{"acf_fc_layout":"image","image":{"ID":702172,"id":702172,"title":"f2","filename":"f2-e1578962025582.png","filesize":69856,"url":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/f2-e1578962025582.png","link":"https:\/\/www.esri.com\/arcgis-blog\/products\/spatial-analyst\/analytics\/unleash-the-power-of-rastercelliterator-to-perform-custom-raster-analysis\/f2","alt":"Examples of input and output with the operation counting the number of neighboring cells that have a value different to the center cell.","author":"8212","description":"","caption":"Figure 2. Examples of input and output with the operation counting the number of neighboring cells that have a value different to the center cell.  ","name":"f2","status":"inherit","uploaded_to":702122,"date":"2020-01-13 23:59:54","modified":"2020-01-14 00:30:13","menu_order":0,"mime_type":"image\/png","type":"image","subtype":"png","icon":"https:\/\/www.esri.com\/arcgis-blog\/wp-includes\/images\/media\/default.png","width":400,"height":485,"sizes":{"thumbnail":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/f2-213x200.png","thumbnail-width":213,"thumbnail-height":200,"medium":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/f2-e1578962025582.png","medium-width":215,"medium-height":261,"medium_large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/f2-e1578962025582.png","medium_large-width":400,"medium_large-height":485,"large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/f2-e1578962025582.png","large-width":400,"large-height":485,"1536x1536":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/f2-e1578962025582.png","1536x1536-width":400,"1536x1536-height":485,"2048x2048":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/f2-e1578962025582.png","2048x2048-width":400,"2048x2048-height":485,"card_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/f2-384x465.png","card_image-width":384,"card_image-height":465,"wide_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/f2-e1578962025582.png","wide_image-width":400,"wide_image-height":485}},"image_position":"center","orientation":"horizontal","hyperlink":""},{"acf_fc_layout":"content","content":"<p>RCI makes it much easier to iterate over all cells and compare each cell value with its neighbors using a simple <em>if <\/em>logic. Here\u2019s how you can do it yourself<strong>:<\/strong><\/p>\n"},{"acf_fc_layout":"content","content":"<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre style=\"margin: 0;line-height: 125%\"> 1\r\n 2\r\n 3\r\n 4\r\n 5\r\n 6\r\n 7\r\n 8\r\n 9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22<\/pre>\n<\/td>\n<td>\n<pre style=\"margin: 0;line-height: 125%\"><span style=\"color: #0000ff\">from<\/span> math <span style=\"color: #0000ff\">import<\/span> isnan    \r\n<span style=\"color: #0000ff\">from<\/span> arcpy.sa <span style=\"color: #0000ff\">import<\/span> Raster, RasterCellIterator    \r\n    \r\nlandu = Raster(<span style=\"color: #a31515\">r\"C:\\sample_data\\landuse.tif\"<\/span>)    \r\n<span style=\"color: #008000\"># Create a temporary output raster based on the raster info of landuse    <\/span>\r\noutput = Raster(landu.getRasterInfo())    \r\n   \r\n<span style=\"color: #0000ff\">with<\/span> RasterCellIterator({<span style=\"color: #a31515\">'rasters'<\/span>:[landu, output]}) <span style=\"color: #0000ff\">as<\/span> rci:    \r\n    <span style=\"color: #0000ff\">for<\/span> i,j <span style=\"color: #0000ff\">in<\/span> rci:    \r\n        count = 0     \r\n        <span style=\"color: #008000\"># Assign NoData value to the output if the input is NoData    <\/span>\r\n        <span style=\"color: #0000ff\">if<\/span> isnan(landu[i,j]):    \r\n            output[i,j] = math.nan    \r\n            <span style=\"color: #0000ff\">continue<\/span>    \r\n        <span style=\"color: #008000\"># Create a moving window    <\/span>\r\n        <span style=\"color: #0000ff\">for<\/span> x <span style=\"color: #0000ff\">in<\/span> [-1,0,1]:    \r\n            <span style=\"color: #0000ff\">for<\/span> y <span style=\"color: #0000ff\">in<\/span> [-1,0,1]:    \r\n                <span style=\"color: #008000\"># Count the number of adjacent cells with a different value      <\/span>\r\n                <span style=\"color: #0000ff\">if<\/span> <span style=\"color: #0000ff\">not<\/span> isnan(landu[i+x,j+y]) <span style=\"color: #0000ff\">and<\/span> landu[i+x,j+y] != landu[i,j]:    \r\n                    count+=1    \r\n        output[i,j] = count    \r\noutput.save(<span style=\"color: #a31515\">r\"C:\\output\\landuse_diff_count.tif\"<\/span>)   \r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n"},{"acf_fc_layout":"content","content":"<p>In line 6, we are creating a new empty raster using the land use raster as an input template. Line 8 creates a <strong>RasterCellIterator<\/strong> object explicitly using input and output. In lines 9-21, we are looping through all cells in the input raster, and for each cell comparing its value to each of its immediate neighbors based on its relative position.<\/p>\n<p>While performing the analysis, it is required to check for the NoData cells in the input, so that an appropriate value can be assigned to the output raster.\u00a0 In lines 12 and 19, we are using <strong>isnan()<\/strong> function from the <strong>math <\/strong>module to check if the cell value in the input raster is NoData.\u00a0 Line 13 uses <strong>nan<\/strong> from the same <strong>math <\/strong>module to represent NoData. In this example, NoData values are not considered while iterating through the cells and they are excluded from the neighbor cells when counting. The input land use data and the final output raster used in the sample code are shown in Figure 3.<\/p>\n"},{"acf_fc_layout":"image","image":{"ID":702202,"id":702202,"title":"f3","filename":"f3.png","filesize":407974,"url":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/f3.png","link":"https:\/\/www.esri.com\/arcgis-blog\/products\/spatial-analyst\/analytics\/unleash-the-power-of-rastercelliterator-to-perform-custom-raster-analysis\/f3","alt":"The figure on the left shows the input land use raster dataset. The figure on the right shows the output raster with values ranging from 0 to 8, which counts the number of neighboring cells that have a different value from the center cell.","author":"8212","description":"","caption":"Figure 3. The figure on the left shows the input land use raster dataset. The figure on the right shows the output raster with values ranging from 0 to 8, which counts the number of neighboring cells that have a different value from the center cell.","name":"f3","status":"inherit","uploaded_to":702122,"date":"2020-01-14 00:22:34","modified":"2020-01-14 00:30:25","menu_order":0,"mime_type":"image\/png","type":"image","subtype":"png","icon":"https:\/\/www.esri.com\/arcgis-blog\/wp-includes\/images\/media\/default.png","width":1629,"height":646,"sizes":{"thumbnail":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/f3-213x200.png","thumbnail-width":213,"thumbnail-height":200,"medium":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/f3.png","medium-width":464,"medium-height":184,"medium_large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/f3.png","medium_large-width":768,"medium_large-height":305,"large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/f3.png","large-width":1629,"large-height":646,"1536x1536":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/f3-1536x609.png","1536x1536-width":1536,"1536x1536-height":609,"2048x2048":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/f3.png","2048x2048-width":1629,"2048x2048-height":646,"card_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/f3-826x328.png","card_image-width":826,"card_image-height":328,"wide_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/01\/f3.png","wide_image-width":1629,"wide_image-height":646}},"image_position":"center","orientation":"horizontal","hyperlink":""},{"acf_fc_layout":"content","content":"<h3>Calculate minimum slope from a DEM<\/h3>\n<p>For the <a href=\"https:\/\/pro.arcgis.com\/en\/pro-app\/tool-reference\/3d-analyst\/slope.htm\">Slope<\/a> geoprocessing tool, the slope value of each cell is determined by the rates of change of the elevation in the horizontal and vertical directions from the center cell (<a href=\"https:\/\/pro.arcgis.com\/en\/pro-app\/tool-reference\/3d-analyst\/how-slope-works.htm\">How slope works<\/a>). In some cases, you might be interested in calculating the slope using a different equation. For an example, when building a fish trawlability model, an analyst might want to use a slope of the seabed that is based on the minimum change of elevation across each cell. By creating a custom focal operation with RCI, the following example shows how to calculate the minimum slope for your bathymetric DEM:<\/p>\n"},{"acf_fc_layout":"content","content":"<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre style=\"margin: 0;line-height: 125%\"> 1\r\n 2\r\n 3\r\n 4\r\n 5\r\n 6\r\n 7\r\n 8\r\n 9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30\r\n31\r\n32\r\n33\r\n34\r\n35\r\n36\r\n37<\/pre>\n<\/td>\n<td>\n<pre style=\"margin: 0;line-height: 125%\"><span style=\"color: #0000ff\">from<\/span> arcpy.sa <span style=\"color: #0000ff\">import<\/span> Raster, RasterCellIterator\r\n\r\ndem = Raster(<span style=\"color: #a31515\">r'C:\\sample_data\\demtif.tif'<\/span>)\r\ncell_x = dem.meanCellWidth\r\ncell_y = dem.meanCellHeight\r\ncell_diag = math.sqrt(cell_x**2+cell_y**2)\r\nraster_info = dem.getRasterInfo()\r\nneighbors = {\r\n    <span style=\"color: #008000\"># pixel offset: distance<\/span>\r\n    (-1,-1): cell_diag,\r\n    (-1,0): cell_y,\r\n    (-1,1): cell_diag,\r\n    (0,-1): cell_x,\r\n    (0,1): cell_x,\r\n    (1,-1): cell_diag,\r\n    (1,0): cell_y,\r\n    (1,1): cell_diag\r\n}\r\nradian_to_degree = 180 \/ math.pi\r\n\r\n<span style=\"color: #008000\"># Set the output pixel type to be float 32 <\/span>\r\nraster_info.setPixelType(<span style=\"color: #a31515\">'F32'<\/span>)\r\nmin_slope = Raster(raster_info)\r\n<span style=\"color: #0000ff\">with<\/span> RasterCellIterator({<span style=\"color: #a31515\">'rasters'<\/span>:[dem, min_slope]}) <span style=\"color: #0000ff\">as<\/span> rci:\r\n    <span style=\"color: #0000ff\">for<\/span> r,c <span style=\"color: #0000ff\">in<\/span> rci:\r\n        slopes = []\r\n        <span style=\"color: #008000\"># Iterate through 8 neighbors to calculate the slope from center cell<\/span>\r\n        <span style=\"color: #0000ff\">for<\/span> x,y <span style=\"color: #0000ff\">in<\/span> neighbors:\r\n            delta_y = abs(dem[r,c]-dem[r+x,c+y])\r\n            <span style=\"color: #008000\"># Calculate percent slope<\/span>\r\n            slope = delta_y \/ neighbors[(x,y)]\r\n            <span style=\"color: #008000\"># Calculate degree slope<\/span>\r\n            <span style=\"color: #008000\"># slope = math.atan2(delta_y, neighbors[(x,y)]) * radian_to_degree<\/span>\r\n            slopes.append(slope)\r\n        <span style=\"color: #008000\"># Assign the minimum slope to the output cell value <\/span>\r\n        min_slope[r,c] = min(slopes)\r\nmin_slope.save(<span style=\"color: #a31515\">r'C:\\output\\min_slope.tif'<\/span>)\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n"},{"acf_fc_layout":"content","content":"<p>In the code sample, lines 26-36 implement the main logic for calculating the minimum slope. For each cell from DEM, we iterate through its eight neighbors and calculate the rate of change. Then we find the minimum slope and assign that value to the output cell. Note that in line 22, the pixel type is set as \u2018F32\u2019, which means that the output is expected to be a 32-bit floating raster. In this example, the raster info of the slope output is inherited from the input DEM data. If the pixel type of your DEM data is integer, you need this step to make sure that the slope value of each cell is calculated as a floating-point value instead of an integer.<\/p>\n<p>&nbsp;<\/p>\n<h2>Summary<\/h2>\n<p>In this blog, we went through three different examples of using Raster Cell Iterator in ArcPy, each of them showing how easy it is to perform custom raster analysis. We hope you start using this simple but powerful capability to extend your own raster analysis capabilities.\u00a0 Please let us know if you have any questions or want to see other examples and use cases.\u00a0 You can also pass along any cool applications you come up with, and we can share your solutions with the community at large!<\/p>\n<p>&nbsp;<\/p>\n<h2>Reference:<\/h2>\n<p>Stathakis, D., &amp; Tsilimigkas, G. (2015). Measuring the compactness of European medium-sized cities by spatial metrics based on fused data sets.\u00a0<em>International Journal of Image and Data Fusion<\/em>,\u00a0<em>6<\/em>(1), 42-64.<\/p>\n"}],"authors":[{"ID":8212,"user_firstname":"Hao","user_lastname":"Hu","nickname":"h.hu","user_nicename":"h-hu","display_name":"Hao Hu","user_email":"h.hu@esri.com","user_url":"","user_registered":"2018-07-31 20:42:18","user_description":"Hao Hu is a product engineer in the raster analysis group at Esri. He specializes in large geospatial raster data processing that leverages distributed computing and storage technologies. Before joining Esri in 2018, Hao completed his Doctoral degree in Geography from the University of Illinois at Urbana-Champaign researching on high-performance geospatial computing and machine learning.","user_avatar":"<img data-del=\"avatar\" src='https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/07\/avatar-e1574284767589.jpeg' class='avatar pp-user-avatar avatar-96 photo ' height='96' width='96'\/>"},{"ID":8232,"user_firstname":"Yu","user_lastname":"Wang","nickname":"y.wang","user_nicename":"y-wang","display_name":"Yu Wang","user_email":"y.wang@esri.com","user_url":"","user_registered":"2018-08-03 23:07:49","user_description":"Yu Wang is a Product Engineer in the Spatial Analyst team focused on multidimensional scientific data management and analysis. Yu's education background includes Ph.D. degree in Geography, with a concentration on applied meteorology and MS degree in Computer Science at the University of Florida. Her research interest includes using Geospatial Metrics to better understand landfalling Tropical Cyclone rainfall patterns.","user_avatar":"<img data-del=\"avatar\" src='https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/08\/head.jpg' class='avatar pp-user-avatar avatar-96 photo ' height='96' width='96'\/>"}],"related_articles":[{"ID":443452,"post_author":"8112","post_date":"2019-02-26 08:52:12","post_date_gmt":"2019-02-26 16:52:12","post_content":"","post_title":"Beginner's guide to Python in ArcGIS Pro, Part 1: Why?","post_excerpt":"","post_status":"publish","comment_status":"closed","ping_status":"closed","post_password":"","post_name":"beginners-guide-to-python-in-arcgis-pro-part-1-why","to_ping":"","pinged":"","post_modified":"2019-03-18 11:20:43","post_modified_gmt":"2019-03-18 18:20:43","post_content_filtered":"","post_parent":0,"guid":"http:\/\/www.esri.com\/arcgis-blog\/?post_type=blog&#038;p=443452","menu_order":0,"post_type":"blog","post_mime_type":"","comment_count":"0","filter":"raw"},{"ID":447382,"post_author":"8112","post_date":"2019-02-27 09:16:32","post_date_gmt":"2019-02-27 17:16:32","post_content":"","post_title":"Beginner\u2019s guide to Python in ArcGIS Pro, Part 2: How?","post_excerpt":"","post_status":"publish","comment_status":"closed","ping_status":"closed","post_password":"","post_name":"beginners-guide-to-python-in-arcgis-pro-part-2-how","to_ping":"","pinged":"","post_modified":"2020-06-19 10:56:16","post_modified_gmt":"2020-06-19 17:56:16","post_content_filtered":"","post_parent":0,"guid":"http:\/\/www.esri.com\/arcgis-blog\/?post_type=blog&#038;p=447382","menu_order":0,"post_type":"blog","post_mime_type":"","comment_count":"0","filter":"raw"},{"ID":708092,"post_author":"6871","post_date":"2020-02-06 09:00:18","post_date_gmt":"2020-02-06 17:00:18","post_content":"","post_title":"Introducing the Raster Cell Iterator","post_excerpt":"","post_status":"publish","comment_status":"closed","ping_status":"closed","post_password":"","post_name":"introducing-the-raster-cell-iterator","to_ping":"","pinged":"","post_modified":"2021-08-02 23:56:28","post_modified_gmt":"2021-08-03 06:56:28","post_content_filtered":"","post_parent":0,"guid":"https:\/\/www.esri.com\/arcgis-blog\/?post_type=blog&#038;p=708092","menu_order":0,"post_type":"blog","post_mime_type":"","comment_count":"0","filter":"raw"}],"card_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/02\/RCI_banner.png","wide_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/02\/RCI_BannerFinal-1.jpg"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.9 (Yoast SEO v25.9) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Unleash the power of RasterCellIterator to perform custom raster analysis<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.esri.com\/arcgis-blog\/products\/spatial-analyst\/analytics\/unleash-the-power-of-rastercelliterator-to-perform-custom-raster-analysis\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Unleash the power of RasterCellIterator to perform custom raster analysis\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.esri.com\/arcgis-blog\/products\/spatial-analyst\/analytics\/unleash-the-power-of-rastercelliterator-to-perform-custom-raster-analysis\" \/>\n<meta property=\"og:site_name\" content=\"ArcGIS Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/esrigis\/\" \/>\n<meta property=\"article:modified_time\" content=\"2020-10-14T02:26:06+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@ESRI\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/spatial-analyst\/analytics\/unleash-the-power-of-rastercelliterator-to-perform-custom-raster-analysis#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/spatial-analyst\/analytics\/unleash-the-power-of-rastercelliterator-to-perform-custom-raster-analysis\"},\"author\":{\"name\":\"Hao Hu\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/person\/eb6b374285ef2dd0f5dd6ee67111bbe3\"},\"headline\":\"Unleash the power of RasterCellIterator to perform custom raster analysis\",\"datePublished\":\"2020-02-06T17:30:13+00:00\",\"dateModified\":\"2020-10-14T02:26:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/spatial-analyst\/analytics\/unleash-the-power-of-rastercelliterator-to-perform-custom-raster-analysis\"},\"wordCount\":10,\"publisher\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#organization\"},\"keywords\":[\"python\",\"Raster Cell Iterator\",\"Raster info\",\"Spatial Analyst\",\"What\u2019s new in Pro 2.5\"],\"articleSection\":[\"Analytics\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/spatial-analyst\/analytics\/unleash-the-power-of-rastercelliterator-to-perform-custom-raster-analysis\",\"url\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/spatial-analyst\/analytics\/unleash-the-power-of-rastercelliterator-to-perform-custom-raster-analysis\",\"name\":\"Unleash the power of RasterCellIterator to perform custom raster analysis\",\"isPartOf\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#website\"},\"datePublished\":\"2020-02-06T17:30:13+00:00\",\"dateModified\":\"2020-10-14T02:26:06+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/spatial-analyst\/analytics\/unleash-the-power-of-rastercelliterator-to-perform-custom-raster-analysis#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.esri.com\/arcgis-blog\/products\/spatial-analyst\/analytics\/unleash-the-power-of-rastercelliterator-to-perform-custom-raster-analysis\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/spatial-analyst\/analytics\/unleash-the-power-of-rastercelliterator-to-perform-custom-raster-analysis#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.esri.com\/arcgis-blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Unleash the power of RasterCellIterator to perform custom raster analysis\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#website\",\"url\":\"https:\/\/www.esri.com\/arcgis-blog\/\",\"name\":\"ArcGIS Blog\",\"description\":\"Get insider info from Esri product teams\",\"publisher\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.esri.com\/arcgis-blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#organization\",\"name\":\"Esri\",\"url\":\"https:\/\/www.esri.com\/arcgis-blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/04\/Esri.png\",\"contentUrl\":\"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/04\/Esri.png\",\"width\":400,\"height\":400,\"caption\":\"Esri\"},\"image\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/esrigis\/\",\"https:\/\/x.com\/ESRI\",\"https:\/\/www.linkedin.com\/company\/5311\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/person\/eb6b374285ef2dd0f5dd6ee67111bbe3\",\"name\":\"Hao Hu\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/07\/avatar-e1574284767589.jpeg\",\"contentUrl\":\"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/07\/avatar-e1574284767589.jpeg\",\"caption\":\"Hao Hu\"},\"description\":\"Hao Hu is a product engineer in the raster analysis group at Esri. He specializes in large geospatial raster data processing that leverages distributed computing and storage technologies. Before joining Esri in 2018, Hao completed his Doctoral degree in Geography from the University of Illinois at Urbana-Champaign researching on high-performance geospatial computing and machine learning.\",\"url\":\"https:\/\/www.esri.com\/arcgis-blog\/author\/h-hu\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Unleash the power of RasterCellIterator to perform custom raster analysis","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.esri.com\/arcgis-blog\/products\/spatial-analyst\/analytics\/unleash-the-power-of-rastercelliterator-to-perform-custom-raster-analysis","og_locale":"en_US","og_type":"article","og_title":"Unleash the power of RasterCellIterator to perform custom raster analysis","og_url":"https:\/\/www.esri.com\/arcgis-blog\/products\/spatial-analyst\/analytics\/unleash-the-power-of-rastercelliterator-to-perform-custom-raster-analysis","og_site_name":"ArcGIS Blog","article_publisher":"https:\/\/www.facebook.com\/esrigis\/","article_modified_time":"2020-10-14T02:26:06+00:00","twitter_card":"summary_large_image","twitter_site":"@ESRI","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/www.esri.com\/arcgis-blog\/products\/spatial-analyst\/analytics\/unleash-the-power-of-rastercelliterator-to-perform-custom-raster-analysis#article","isPartOf":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/products\/spatial-analyst\/analytics\/unleash-the-power-of-rastercelliterator-to-perform-custom-raster-analysis"},"author":{"name":"Hao Hu","@id":"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/person\/eb6b374285ef2dd0f5dd6ee67111bbe3"},"headline":"Unleash the power of RasterCellIterator to perform custom raster analysis","datePublished":"2020-02-06T17:30:13+00:00","dateModified":"2020-10-14T02:26:06+00:00","mainEntityOfPage":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/products\/spatial-analyst\/analytics\/unleash-the-power-of-rastercelliterator-to-perform-custom-raster-analysis"},"wordCount":10,"publisher":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/#organization"},"keywords":["python","Raster Cell Iterator","Raster info","Spatial Analyst","What\u2019s new in Pro 2.5"],"articleSection":["Analytics"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.esri.com\/arcgis-blog\/products\/spatial-analyst\/analytics\/unleash-the-power-of-rastercelliterator-to-perform-custom-raster-analysis","url":"https:\/\/www.esri.com\/arcgis-blog\/products\/spatial-analyst\/analytics\/unleash-the-power-of-rastercelliterator-to-perform-custom-raster-analysis","name":"Unleash the power of RasterCellIterator to perform custom raster analysis","isPartOf":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/#website"},"datePublished":"2020-02-06T17:30:13+00:00","dateModified":"2020-10-14T02:26:06+00:00","breadcrumb":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/products\/spatial-analyst\/analytics\/unleash-the-power-of-rastercelliterator-to-perform-custom-raster-analysis#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.esri.com\/arcgis-blog\/products\/spatial-analyst\/analytics\/unleash-the-power-of-rastercelliterator-to-perform-custom-raster-analysis"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.esri.com\/arcgis-blog\/products\/spatial-analyst\/analytics\/unleash-the-power-of-rastercelliterator-to-perform-custom-raster-analysis#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.esri.com\/arcgis-blog\/"},{"@type":"ListItem","position":2,"name":"Unleash the power of RasterCellIterator to perform custom raster analysis"}]},{"@type":"WebSite","@id":"https:\/\/www.esri.com\/arcgis-blog\/#website","url":"https:\/\/www.esri.com\/arcgis-blog\/","name":"ArcGIS Blog","description":"Get insider info from Esri product teams","publisher":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.esri.com\/arcgis-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.esri.com\/arcgis-blog\/#organization","name":"Esri","url":"https:\/\/www.esri.com\/arcgis-blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/04\/Esri.png","contentUrl":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/04\/Esri.png","width":400,"height":400,"caption":"Esri"},"image":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/esrigis\/","https:\/\/x.com\/ESRI","https:\/\/www.linkedin.com\/company\/5311\/"]},{"@type":"Person","@id":"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/person\/eb6b374285ef2dd0f5dd6ee67111bbe3","name":"Hao Hu","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/person\/image\/","url":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/07\/avatar-e1574284767589.jpeg","contentUrl":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/07\/avatar-e1574284767589.jpeg","caption":"Hao Hu"},"description":"Hao Hu is a product engineer in the raster analysis group at Esri. He specializes in large geospatial raster data processing that leverages distributed computing and storage technologies. Before joining Esri in 2018, Hao completed his Doctoral degree in Geography from the University of Illinois at Urbana-Champaign researching on high-performance geospatial computing and machine learning.","url":"https:\/\/www.esri.com\/arcgis-blog\/author\/h-hu"}]}},"text_date":"February 6, 2020","author_name":"Multiple Authors","author_page":"https:\/\/www.esri.com\/arcgis-blog\/products\/spatial-analyst\/analytics\/unleash-the-power-of-rastercelliterator-to-perform-custom-raster-analysis","custom_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2020\/02\/RCI_BannerFinal-1.jpg","primary_product":"ArcGIS Spatial Analyst","tag_data":[{"term_id":24341,"name":"python","slug":"python","term_group":0,"term_taxonomy_id":24341,"taxonomy":"post_tag","description":"","parent":0,"count":171,"filter":"raw"},{"term_id":540462,"name":"Raster Cell Iterator","slug":"raster-cell-iterator","term_group":0,"term_taxonomy_id":540462,"taxonomy":"post_tag","description":"","parent":0,"count":2,"filter":"raw"},{"term_id":540482,"name":"Raster info","slug":"raster-info","term_group":0,"term_taxonomy_id":540482,"taxonomy":"post_tag","description":"","parent":0,"count":1,"filter":"raw"},{"term_id":39421,"name":"Spatial Analyst","slug":"spatial-analyst","term_group":0,"term_taxonomy_id":39421,"taxonomy":"post_tag","description":"","parent":0,"count":49,"filter":"raw"},{"term_id":540472,"name":"What\u2019s new in Pro 2.5","slug":"whats-new-in-pro-2-5","term_group":0,"term_taxonomy_id":540472,"taxonomy":"post_tag","description":"","parent":0,"count":1,"filter":"raw"}],"category_data":[{"term_id":23341,"name":"Analytics","slug":"analytics","term_group":0,"term_taxonomy_id":23341,"taxonomy":"category","description":"","parent":0,"count":1329,"filter":"raw"}],"product_data":[{"term_id":37031,"name":"ArcGIS Spatial Analyst","slug":"spatial-analyst","term_group":0,"term_taxonomy_id":37031,"taxonomy":"product","description":"","parent":36981,"count":93,"filter":"raw"}],"primary_product_link":"https:\/\/www.esri.com\/arcgis-blog\/?s=#&products=spatial-analyst","_links":{"self":[{"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/blog\/702122","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/blog"}],"about":[{"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/types\/blog"}],"author":[{"embeddable":true,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/users\/8212"}],"replies":[{"embeddable":true,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/comments?post=702122"}],"version-history":[{"count":0,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/blog\/702122\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/media?parent=702122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/categories?post=702122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/tags?post=702122"},{"taxonomy":"industry","embeddable":true,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/industry?post=702122"},{"taxonomy":"product","embeddable":true,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/product?post=702122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}