Flow Direction and Accumulation

This topic continues from the Watersheds topic.  

 

Given a single-channel image showing terrain elevations, we use the TileFlowDirAccumPar SQL function (the parallel version of TileFlowDirAccum) to compute flow direction and accumulation.  The function returns a table for a dual image, that is a table with fields for X and Y plus two tile fields: FlowDir and FlowAccum.  When a table has two tile fields, two images can be created from the same table, in this case one image showing flow direction and the other showing flow accumulation.

 

The flow direction value for each pixel is the direction in which water is flowing over that pixel as it makes its way downstream.   The flow accumulation value for each pixel is the sum of all flows from upstream of that pixel, that is the accumulated value, or magnitude of the stream that flows over that pixel.

 

This topic should be read together with other watershed topics:

 

 

 

 

 

 

 

 

 

Consider our Montara terrain as seen above, using the Montara Filled Sinks version of the image created in the Watershed Prepare: Filling Sinks topic.

 

 

We choose View - New Command Window - SQL to launch a Command window.

 

 

To use the TileFlowDirAccumPar function to build an image showing flow direction and flow accumulation, we write a query as seen above, with the query text used below:

 

VALUE @cores NVARCHAR = ThreadConfig(SystemCpuCount());

 

SELECT [x], [Y], [FlowDir], [FlowAccum]

  INTO [FlowDirAccum Table]

  FROM CALL TileFlowDirAccumPar([Montara filled sinks], 0, @cores);

 

The VALUE declaration at the beginning declares a global value called @cores that contains the total number of cores in our system.  

 

"Par" variations of SQL functions are explicitly parallelized functions that take a final argument that is a JSON configuration string which gives the numbers of cores to use for parallel processing, which we create using the ThreadConfig function, that in turn calls the SystemCpuCount function to get the total number of cores in our system.   We use the global value for no other purpose but greater legibility.  Using @cores as an argument is a way to keep the arguments used in the TileFlowDirAccumPar function from getting too intimidating and hard to follow.   Using global values can keep things simpler and clearer.

 

We press the ! Run command button in the main toolbar to run the query.   It creates a table called FlowDirAccum Table.

 

 

The table has been created with two tile fields, one tile field providing tiles for the flow direction computation, and the other tile field providing tiles for flow accumulation.   We can use those tile fields to create images from the table that show flow direction and flow accumulation.    

 

We note that the FlowDir tile uses a data type of int8 in tiles that are 128x128 in size.    The FlowAccum tile uses a data type of float64 in tiles that are 128x128 in size.

 

The results table inherits both the Rect and the coordinate system of the original image.  We will use those to create new images based on the FlowDir and FlowAccum tile fields in the table.

Create an Image Showing Flow Direction

Before creating an image, we right-click onto the Montara Filled Sinks image in the Project pane and choose Properties, so we can make note of the Rect property, that is, the size of the Montara Filled Sinks image from which we have computed flow direction and flow accumulation.  

 

 

We note the Rect property reports a value of

 

[ 0, 0, 1152, 1408 ]

 

We Copy that, so we can Paste it in the next dialog we use, without needing to manually keyboard it.     

 

We also take a look in the Info pane, to note the coordinate system used by the Montara Filled Sinks image, and we save that coordinate system as a Favorite, making sure to choose the override metrics option when saving the favorite, so we can use it again with one click.   

 

To create a flow direction image from the table, we right click onto FlowDirAccum Table in the Project pane and choose Create - New Image.

 

 

In the New Image dialog, we provide the name Flow Direction.   We choose FlowDir as the Tile field and int8 for the data type.  

 

In the Bounds box we Paste the value copied earlier from the Rect value in the Properties dialog for the Montara Filled Sinks image, [ 0, 0, 1152, 1408].

 

 We click the coordinate picker button to set the coordinate system to be the same as used by the Montara Filled Sinks image, in this case Universal Transverse Mercator - Zone 10 (N).  We thoughtfully added that coordinate system to our Favorites so we can specify it with one click, making sure to choose the override metrics option when saving the favorite.    We press Create Image.

 

We could have, of course, created the image and set the bounding box and the coordinate system in the query at the same time that we created a table.  However, sometimes it is easier and clearer to use a mix of queries and point-and-click dialogs, keeping our query simple and creating the image using the New Image dialog.

 

 

When we drag and drop the new Flow Direction image into our map.   We see an alert message in the tab, so we visit View - Messages to display the image by updating intermediate levels.   The result is a disappointing, all-black display.   We must style the image for it to provide a useful visual display.

 

 

Launching the Style dialog, we choose Channel 0 as the single channel.    We choose unique values as the method, and Tally using any convenient number greater than 8, the number of unique values which are used to indicate direction.    We apply a palette of gray colors as seen above, and we press Update Style.

 

 

The result is an image that colors each pixel based on the direction that water flows over that pixel as the water finds its way downstream.

 

 

Manifold codes flow direction using eight, integer numbers, from 0 to 7, where 0 indicates a flow directly North, and the other numbers indicating flow directions every 45 degrees in clockwise order, as shown above.   All pixels that have a value of 4, for example, have a flow direction of South, that is, water flowing over those pixels is flowing due South.   Flow directions on a per-pixel basis are estimates, so only eight categories of flow are used.

Create an Image Showing Flow Accumulation

We follow workflow similar to the above to create a flow accumulation image from the FlowDirAccum Table.   We right click onto FlowDirAccum Table in the Project pane and choose Create - New Image.

 

 

In the New Image dialog, we provide the name Flow Accumulation.   We choose FlowAccum as the Tile field.

 

 Important: We choose float64 for the data type.   That will match the data type of the tile used in the table, that we noted earlier.

 

In the Bounds box we Paste the value copied earlier from the Rect value in the Properties dialog for the Montara Filled Sinks image, [ 0, 0, 1152, 1408].

 

 We click the coordinate picker button to set the coordinate system to be the same as used by the Montara Filled Sinks image, in this case Universal Transverse Mercator - Zone 10 (N).

 

We press Create Image.

 

 

When we drag and drop the new Flow Accumulation image into our map.   We see an alert message in the tab, so we visit View - Messages to display the image by updating intermediate levels.   We see that this image also could use an application of Style.

 

 

We style the image using the above settings.  With one unit of water falling on each pixel, pixels accumulate flow very rapidly, so most flows are high.  We use exponential intervals given the very rapid growth in accumulated flow.

 

 

The new style shows how flows rapidly accumulate downstream from pixel to pixel, with red color showing very large flows in the main streams lines.

 

 

Zooming in, we can see how the highest flow value pixels, in colors closer to red,  are those that correspond to stream lines.  The lowest value pixels, in colors closer to blue, are those that correspond to ridges between catchment basins.

 

Videos

Manifold vs Arc - Fifty times Faster than Spatial Analyst -  The first video in a series of comparisons. We compare Manifold Release 9 to ESRI's ArcMap with Spatial Analyst. ArcMap instead of ArcGIS Pro is used to ensure maximum possible speed with no slowdowns from AGOL connections. Starting with a terrain 5300 x 5300 elevation raster we compare Manifold workflow and speed creating streams (watershed lines) with ESRI ArcMap and Spatial Analyst doing the same task. ArcMap requires four operations calculating intermediate steps, taking a total of three minutes and 30 seconds to compute streams.  Manifold does the same job in a single operation in under four seconds, over fifty times faster than Arc, and with the convenience of a single click.  ArcMap plus Spatial Analyst cost over $5000 per seat while Manifold costs under $500.  As data sizes scale up, Manifold gets even faster than Arc. Works in the free Viewer, too!

 

Manifold vs Arc - Watersheds Sixty Five times Faster than Arc -  Another video comparing Manifold speed to ESRI ArcMap with Spatial Analyst, this time computing upstream watersheds on a 5300 x 5300 terrain elevation raster for a few dozen locations.  ArcMap requires three geoprocessing tool operations calculating intermediate steps, taking a minute and a half.  Manifold does the same job in a single click in less than 1.4 seconds, over 65 times faster than ESRI. The larger and more complex the geoprocessing, the greater Manifold's speed advantage.   ArcMap plus Spatial Analyst cost over $5000 per seat while Manifold costs under $500. Works in the free Viewer, too!

 

Manifold vs Arc - Seven Seconds vs Four Minutes - Finding basins in a 5300 x 5300 terrain elevation raster, we compare Manifold workflow speed and ease of workflow to ESRI's ArcMap with Spatial Analyst.  ArcMap Standard plus Spatial Analyst costs a total of $5250 so it should work better than a Manifold package that sells for under $500, right?  No way! Manifold absolutely crushes the comparison, taking only a single click and seven seconds to do what takes the $5000+ package three geoprocessing operations and four minutes, not counting the time to setup and launch three operations. Works in the free Viewer, too!

 

Manifold vs Arc - 100x Faster on an Affordable Desktop - Watch Manifold do in 0.9 seconds what takes ArcMap plus Spatial Analyst over a minute and a half.  That's over 100 times faster!   Some  comments on previous comparisons have stated that Manifold was so super fast compared to ESRI because tests were run on a high-end, Threadripper machine that could run 48 threads. This video shows Manifold is faster even with fewer cores on an affordable desktop system.  We re-run Manifold trials on a  Ryzen 9 3900x computer, with three different tasks taking only 0.9 seconds, 5.4 seconds and 3 seconds.  AMD's 3900x CPU now retails for as low as $450, setting a new baseline for affordable GIS desktop computing.  Everything shown in the video works in the free Viewer, too!

 

See Also

Tables

 

Maps

 

Drawings

 

Images

 

Labels

 

Style

 

Style: Thematic Formatting

 

Transform Pane

 

Transform Topics

 

Transform Reference

 

Transform - Tiles

 

Watersheds

 

Example:  Create Watershed Areas

 

Example: Create Watershed Lines

 

Shreve Order and Strahler Order

 

Watershed Areas, Sinks

 

Watershed Prepare: Filling Sinks

 

Upstream Areas and Lines

 

Downstream Lines