Showing posts with label ModelBuilder. Show all posts
Showing posts with label ModelBuilder. Show all posts

Monday, November 12, 2018

Miscellaneous Hydrology Tools for ArcGIS - Find Inflow Cells Tool

Back in my September 29, 2018 post I promised a three part blog post on the Miscellaneous Hydrology Tools for ArcGIS. After a long absence here is part II - a detailed description of Find Inflow Cells Tool.  You can read the original blog post by clicking HERE or download the tool be clicking HERE.
There are plenty of examples of situations in which we may want to figure out which cells flow in and which ones flow out of a watershed.  Standard watershed tools, such as Basin in Spatial Analyst, will easily give us the outflow cells.  Finding the inflow cells can be a little bit trickier, hence the reason for this new tool.

On the left is an example of a watershed in which I digitized a cut line that separates the northern 1/4 from the rest of the watershed. The goal in this example is the use the Find Inflow Cells tool to identify which cells from the northern 1/4 flow into the rest of the watershed. This could be useful for identifying likely entry points into a watershed. One scenario might be for a proposed development within a watershed in which we want to identify all entry points and mitigate for those by implementing some sort of erosion control. This tool would be well suited for those sorts of applications.  If we were interested in identifying downslope cells that are likely to be affected then we may use this tool in conjunction with the Trace Downstream tool that I will cover in my next post.

The image on the right illustrates the first step that the Find Inflow Cells undertakes. The entire watershed is rasterized and the Expand and Shrink tools in Spatial Analyst are used to generate an "inner buffer" and an "outer buffer".  These are one cell wide buffers both inside and outside of the watershed. The inner buffer refers to the outermost cells within the watershed; candidates into which flow can occur. The outer buffer refers to the cells immediately adjacent from which flow can flow from. In the image on the right the outer buffer is blue and the inner buffer is green. The remaining cells in the watershed are red and the cells outside the watershed are gray.

The image on the left shows the model as seen in ModelBuilder. Bear with me as I know that it is a little difficult to read.  If you are really interested in the inner workings of this tool or any other I'd encourage you to crack open the model in ModelBuilder and examine the steps on your own computer. You'll see that it is actually quite repetitive and not nearly as complicated as it looks. It performs the standard hydrologic steps of filling the DEM, calculating flow direction, and calculating flow accumulation. Then the tool shifts the flow direction, flow accumulation, and outer buffer rasters in each of the eight directions. The following types of raster calculator statements are used to determine if a cell has positive inflow: ("%inner%" * "%ne_con%" * (Con("%ne_fdr%" == 8,1,0)))*8. A value of 8 is used to determine flow from the northeast to southwest directions.  This is repeated for all of the directions using values of  16, 32, 64, 128, 1, 2, and 4 to represent the east, southeast, south, southwest, west, northwest, and north neighbors.  A similar, but simpler, statement is used for flow accumulation: ("%inner%" * "%ne_con%"*"%ne_fac%").  Finally, values are summed to produce the flowdirection2 raster and then reclassified into 1 and 0 to produce the flowdirection1 raster.  Similarly, flow accumulations are summed. Finally, the raster cells with inflow are converted to points.


Inflow2 and Inflow1 differ, because Inflow2 can be used to determine which cells flow into the focal cell.  Inflow1, in contrast, just codes all cells with inflow as 1 and all cells that have no inflow as 0.  In the example table in the left image most cells have no inflow or are not boundary cells (99.9%). The most common direction of inflow is from the northeast (value=8), followed by north, east, and southeast. The values of 6 and 12 are not values of flow direction, but rather represent combinations of two values. Six is most likely a combination of 1 north and 1 east flowing cell. Twelve is most likely a combination of 8 and 4 representing northeast and north respectively.


The image on the right shows the spatial representation of the attribute table shown above. This is the Inflow2 raster.  The lilac color represents flow crossing the barrier from northeast to southwest. The next most common color green representing flow from north to south.  The cell at the bottom of the drainage that is red represents flow from the northwest to southeast.


The image to the right shows the Inflow1 raster. It represents cells with inflow and are shown as bright green.  Cells around the perimeter of the watershed have no inflow because the watershed was defined using standard hydrological tools in Spatial Analyst (Fill, Flow Direction, Flow Accumulation, and Watershed).



Individual flow directions can be obtained by running the tool from the ModelBuilder dialog window (right-click and select edit). This  is an optional, but potentially useful, step that some advanced users may be interested in.


 In the picture on the left inflow cells are colored by flow accumulation. Most of the cells with inflow (blue) are located close to ridges but contribute less flow than cells in the valley bottom (red).

In the picture at the bottom of the page cells have been converted into points which are shown as graduated symbols. Larger dots represent more flow than small dots. As can be seen the cells with the most inflow are located in the valley bottom.

This is it for this week.  Next up will be a post on the Trace Downstream Tool, which is a companion and extension for this tool.



Thursday, December 15, 2016

An improved zonal statistics for dealing with overlapping buffers

A while back I posted an article about two alternative options for summarizing and extracting data from around points.  The two solutions that I posited where zonal statistics and neighborhood statistics.  Each has its advantages and disadvantages.  The standard zonal statistics tool in ArcGIS doesn't deal with overlapping polygons, which is a common problem.  The neighborhood approach tends to be slow, but has the advantage that it can deal with overlaps effectively and necessary for people doing wall-to-wall predictive maps (such as species distribution modeling).

There is, however, a third option.  The zonal statistics tool can be modified to accommodate overlaps.  That is exactly what I have done.  Below is the model that I created in Model Builder to achieve this.

I plan to have this out soon as a tool available to download.  In the mean time there are a couple of key features to this model that I'd like to point out. 

1) Iteration by Field Values - This step iterates through a categorical raster, lets say land cover classes, producing an output that represents to proportion cover for each type.

2) Intersect/Erase - Buffers are generated and the intersect and erase tools are used identify the "normal non-overlapping" portion of the buffer as well as the overlapping portion.  Unfortunately the Erase tool requires a full ArcGIS Advanced license so I'll need to put some more thought into how to make this available to folks with lower license levels.

3) Zonal statistics - The tool performs a couple of zonal statistics operations.  It sums the number of cells in each class and then sums the total number of cells to get the proportional cover.

4) Once the proportional cover has been calculated for overlapping buffer areas and non-overlapping buffer areas there is a need to put this information together.  The field calculator is used with the following formula max( !Prpn_Overlap_Raster!, !Prpn!).  This effectively deals with the fact that there are Null values from one output when there are data values from the other and visa versa.  This seems to be an effective way of getting around trying to make field mapping work.

Look soon for a new tool to automate this process.

Tuesday, October 25, 2016

New tool - Line Intercept Mapping for ArcGIS

I've got a new tool for displaying the results from line intercept mapping in GIS.  You can download that tool HERE .

Line intercept is one of the most common sampling methods of sampling in ecology. Despite its widespread popularity a lack of tools exists for automatically importing and visualizing line interrcept data in a GIS. This tool alleviates this problem making line intercept mapping easier. The tool can be run using any of the three licensed versions of ArcGIS and does not require any extensions. The tool is capable of generating overlapping line segments. The tool does not require linear referencing because transect lines are assumed straight. The tool requires that your data be in two tables: a transect coordinate table and a start-stop table. The transect coordinate table should have four fields: a TransectID, easting (or longitude for the GCS version of the tool), northing (or latitude for the GCS version of the tool), and supposed line length (length of the line as measured in the field). The start-stop table requires four fields: a TransectID, a start distance, a stop distance, and at least one field with a descriptive attribute that you are trying to map.

Monday, October 5, 2015

Came across a way to pull out one raster from a multiband in Modelbuilder

Sometimes it is nice to have a quick and simple way of pulling out the single bands from a multi-band image stack without having to resort to a python script.  This stack exchange post shows how to do it in a nice, easy, and straightforward manner in ArcGIS ModelBuilder. Kudos to xyz for coming up with this answer. I was able to use this approach recently to perform principal component analysis and then continue to work with the raster downstream.


In this example the parse path tool is used to pull out the path and file name. Then Band_1 is appended in the output name of the raster calculator using the following function: "%Path%\%File%\Band_1"*1