Adding Upstream / Downstream Links

Updated September 16, 2002
Author:        Paul Jendrowski
Organization: NOAA, National Weather Service, Blacksburg, VA
email: paul.jendrowski@noaa.gov

Overview

The AMBER Basin Customization extension requires specific attributes to identify basins and link each basin to its immediate upstream and downstream basins. The basins as delivered do not have attributes that directly indicate the basin-to-basin connectivity. However, the streamlink theme does have To and From node attributes which can be used to establish the basin-to-basin connectivity. However, due to the way the basins are delineated from the DEM by HUCs and the way the streamlink grid is converted to a polyline shape, there are typically many more streamlinks than basins. Therefore, the streamlink shapefile must be edited to obtain a one-to-one relationship between each stream segment and basin polygon.

The procedure to convert the streamlink and basin shapefiles can be summarized as:
  1. Convert To and From node attributes in the original streamlink shapefile to upstream and downstream link attributes.
  2. Identify and correct broken upstream/downstream links.
  3. Convert multiple line segments within a basin into a single line.
  4. Map streamlink segments to basins with a spatial join to assign the correct Pfafstetter code to the streamlinks.
  5. Assign the upstream/downstream attributes from the streamlinks to the basins by joining on the Pfafstetter fields in the streamlink and basin shapefiles.
While this seems to be a fairly straight forward process, it can take quite a lot of manual work to arrive at the goal of a one-to-one spatial relationship between line segments in the streamlink shapefile and polygons in the basins shapefile. The follow steps are guide to editing the streamlink theme and some of the steps will have to be repeated as additional discrepancies are found. It is highly recommended that the streamlinks are saved frequently to back up the previous editing step before going on to the next step. It is also recommended that notes be taken to document the changes made. Most of the AMBER Basin Customization extension functions make brief notes to the theme's comments and these can be added to manually from the Theme Properties window. (Theme comments belong to the project files and not the shapefiles. Comments will be lost if the theme is deleted from the View).


Tips

Here are some tips for working with the conversion process.

Procedure


1. Preprocess the original streamlink theme kxxx_str_gen.shp

You can perform some preliminary edits to the streamlink theme to have less features to process in later steps. Make a copy of the original file and perform edits to the copy.

2. Add upstream and downstream links to attribute table

  1. Make the stream link theme active and run " Create Links " from the Bsn-Tools menu. Use slcreatelinks.shp for the new shapefile name.
  2. Now the Select Upstream/Downstream Tools will work. Try the Select Upstream and Select Downstream tools on different stream segments.
The resulting shapefile will have the following new attributes: [Basin_id], [Parent_id], [Upstream1] and [Upstream2] . There may be a number of additional "Upstream" fields. The upstream fields should never be edited and the function "Add Upstream Links" used to recompute these fields. Also, the [Pfaf_orig] field will be renamed [Pfaf_id] to avoid confusion with the [Pfaf_orig] field in the basin polygon shapefile when joining. Once this step is done, deleting and merging features should only be done through the Bsn-Tools menu and not through the Edit menu.

3. Add end points to the attribute table

Streamlink end points The final step in the mapping of the streamlinks to the basin polygons will be to perform a spatial join. This will associate each streamlink to a basin. For optimum results, it is best to perform the spatial join using the streamlinks represented as points. To do this, the Streamlink Points function adds the coordinates of either the first, last, center or combination of center and first end points to the attribute table. These coordinates in the attribute table can then be used to add an event theme to the view (a new theme based on the coordinates in an attribute table). The figure to the left demonstrates how the first or upstream end point of a streamlink will normally fall within the basin the line segment should be associated with. The last or downstream point generally will fall into the downstream basin. It may seem logical to use the center point to map the the streamlink to a basin, but the center point of very short stream links (i.e. representing one grid cell from the DEM) often falls in the downstream basin instead of the correct basin.

In the original streamlinks shapefile, there is a preliminary mapping to the Pfafstetter ID of the basins. If this attribute is not available, a point theme would have to be created from the streamlink coordinate, and then spatially joined with the basin polygon theme. This would associate the attributes of the basin polygons to the streamlink theme. This then would be the starting point to get a one-to-one mapping of streamlinks (using the Basin_id field) to the basin polygons (using the Pfaf_orig field).

To add the end points:
  1. From the Bsn-Tools menu select " StreamLink Points ".
  2. At the prompt for point to extract, select "First node" and then click the OK button. The coordinates will appear in the attribute table labeled "X_first" and "Y_first".
  3. The option for "Mixed" is useful for obtaining a coordinate for creating a point theme for labeling. The mixed mode uses the center point unless the streamlink is a headwater; then the first point is returned.

4. Check for mislabeled stream segments

  1. Open the streamlink theme's attribute table.
  2. Check for records where Pfaf_id is undefined (sort on the [Pfaf_id] field).
  3. Select individual records on the the sorted table and then use Zoom to Selected button on the View window to examine each feature to determine what action needs to be taken. In this case, some need to have the Pfaf_id from the basin shapefile assigned to it and some need to be deleted. Either write down the the Basin_id's of the segments that need to be redefined or use a graphic symbol to mark the segment on the View.
  4. Make the table active and from the Table menu, select "Start Editing".
  5. Manually enter any new Pfaf_ids in the Attribute table. Use the identify tool on the basin shapefile to determine the Pfaf_id to enter.
  6. Stop editing the table when done and save the edits.
  7. Select any streamlinks that need to be deleted.
  8. From the Bsn-Tools menu, select " Delete Basins ".

5. Repair broken links

There may be streamlinks that do not trace all the way downstream. While the stream segments may appear to be joined in the display, the attribute table [Parent_id] links may have the stream ending prematurely. The [Parent_id] field is set to 0 to indicate the downstream end of the stream network. To fix broken links, the Parent_id field must be manually set to indicate the correct downstream segment it flows into.
  1. To identify possible broken links, perform the following query on the streamlink theme: "([Parent_id] = 0)" using "New Set".
  2. Normally, all streams will flow out of the coverage area so look for selected segments in the interior (you will probably have to zoom and pan to see the selected segments). There should be only a few segments selected but coastal sites will have much larger number of valid segments with [Parent_id] = 0. Write down the [Basin_id] of the broken segments or mark their location with a graphic symbol.
  3. After all broken links are identified, open the streamlink theme's attribute table and select "Start Editing" from the Table menu.
  4. Return to the View containing the streamlink theme and for each broken link:
    1. Using the normal selection tool, select the downstream stream link and the immediate upstream segments (only those that had ([Parent_id] = 0) to link together.
    2. From the Bsn-Tools menu, select " Link Selected Basins ".
    3. The edit can be checked by using the Select Next Downstream tool on the upstream segments that were linked. When using the tool, the upstream and downstream segments will be highlighted. The upstream links have not been corrected yet so the Select Upstream tools will not work.
  5. After all links are repaired, open the attribute table and from the Table menu, select "Stop Editing".
  6. From the Bsn-Tools menu, Select " Add Upstream Links ". This is required to recompute the upstream links and must always be performed anytime "Link Selected Basins" is used.
Always run "Add Upstream Links" on the attribute table after any manual edits to [Parent_id] field.

6. Delete Stream segments outside the basin polygons

Search along the outside edge of the basin polygons for stream segments that need to be deleted. The Bsn-Tools Delete function is designed to process multiple selected features. Therefore, all features are normally selected first, then run the tool to delete multiple features. The tool deletes features from the current theme so it is highly recommended that the shapefile is copied to a new theme (Theme menu, Convert to Shapefile) and then work on the new theme.
  1. Use the normal select tool to select individual stream segments or use the Select Upstream and Downstream tools.
    1. For the standard ArcView selection tool, remember to hold the shift key down to toggle on/off the selection with out losing any previous selection. For the basin selection tools, hold down the shift key to add to the selection and hold down the control key to subtract from the selection.
    2. Save the project frequently. Saving the project also saves the selection. Therefore, if you accidentally lose the selection, you can restart the project at some intermediate point in the selection process and not have to start over.
  2. Once all the features are selected, from the Bsn-Tools menu, select "Delete Basins ". This performs the edits on the shapefile, hence the reason for making a copy of the shapefile before editing.

7. Merge multiple line segments

Merge Single Streamlinks
There may be multiple line segments per basin in the original stream network shapefile, and these need to be merged to create a one-to-one relationship between the basin polygons and the streamlink segments. Some of these can be processed automatically with the " Merge Multiple Stream Segments " function. Line segments merged by this function are identified by as having only a single upstream link ([Upstream1] > 0 and [Upstream2] = 0) and the same [Pfaf_id] value as the upstream segment.
  1. Make the streamlink theme active.
  2. From the Bsn-Tools menu, select "Merge Multiple Stream Segments". This will save the edits to a new shapefile. Name this new shapefile slmrgsingle.shp.
This step is generally run once. However, if the [Pfaf_id] is manually edited, this step can be run again if the editing creates 2 segments in the same basin with the same [Pfaf_id].

8. Merge phantom streamlinks

Due to the way the streamlink grid is converted to a bifurcated line network, there may be some streamlinks that are not associated with a true basin. Instead, the grid to line function in ArcInfo may create a very short streamlink segment in places where more than 2 basins flow into the same point.
Phantom Streamlinks
The easiest way to handle this situation and to maintain the proper stream network topology, the phantom streamlinks should be merged with the downstream streamlink. The phantom streamlink will usually have the Pfafstetter ID of one of the upstream basins. This upstream basin then has 2 stream segments mapped to it. To find these phantom stream segments, the "Check for Duplicates" function (Table window, Bsn-Tools menu) is used.
  1. Open the attribute table for the streamlink theme (i.e., slmrgsingle.shp).
  2. Return to the view and from the View menu, select "Add Event Theme..."
    1. For the table, select the attribute table for the streamlink theme.
    2. For the X and Y fields, choose "X_first" and "Y_first", then click the OK button. A point theme will be added to the view.
  3. Make the new point theme the active theme, and select "Properties" from the theme menu.
    1. Rename the theme to sl-pts (this is to avoid confusion with the streamlink theme's attribute table).
  4. Open the attribute table for the sl-pts theme.
  5. From the Bsn-Tools menu, select "Check for Duplicates" and select the [Pfaf_id] field.
  6. Inspect all selected records using the points to guide where to look but examining the spatial relationship between the line segments and the basin polygons. There may be some records where the [Pfaf_id] needs to be changed, the line segment merged or deleted. For this step, focus only on the segments that need to be merged (ignore other needed corrections for now). You will primarily be looking for situations as in the figure above, however there may be other situations where the line segments should be merged.
    1. On the streamlink theme, select the line segments to be joined using the "Select Next Downstream" tool (inverted triangle symbol) or the normal select tool.
    2. Beware of pairs of segments to be joined that are immediately downstream of each other. These may be merged into one segment instead of the desired sets. In this case, these basins will have to be merged in multiple iterations of this process.
    3. Remember to save the project often in case you accidentally lose the previous selections.
  7. Once all streamlinks to be merged have been selected, from the Bsn-Tools menu, select "Merge Basins " Name the new shapefile slmrgphantom.shp . Select "No" at the prompt to compute Area/Length (this will be done later).
  8. Delete the sl-pts theme from the View and its attribute table from the project. If a temporary theme of the selection was created, delete the theme, its attribute table and clean up the files on disk.

9. Other Edits to Streamlink

Perform final checks on the edited stream link theme. This step may have to be repeated until there are no features with duplicate [Pfaf_id].
  1. Open the attribute table for the streamlink theme (i.e., slmrgphantom.shp) .
  2. Return to the view and from the View menu, select "Add Event Theme..."
    1. For the table, select the Attribute table for the streamlink theme.
    2. For the X and Y fields, choose "X_first" and "Y_first", then click the OK button. A point theme will be added to the view.
  3. Make the new point theme the active theme.
    1. Select "Properties" from the theme menu.
    2. Rename the theme to sl-pts (this is to avoid confusion with the stream link polyline theme's attribute table).
  4. Open the attribute table for the sl-pts theme.
  5. From the Bsn-Tools menu, select "Check for Duplicates" and select the [Pfaf_id] field.
  6. Inspect all selected records using the points to guide where to look but examining the spatial relationship between the line segments and the basin polygons. There may be some records where the [Pfaf_id] needs to be changed, the line segment merged or deleted. Focus on one type of change (merge, delete, reset [Pfaf_id]) for each pass.
  7. Delete the sl-pts theme from the View and attribute tables from the project. If a temporary theme of the selection was created, delete the theme, its attribute table and clean up the files on disk.
  8. Repeat these steps until there are no duplicate [Pfaf_id] values in the streamlink attribute table.

10. Check final streamlink theme with Spatial Join

This process is a final check to ensure the [Pfaf_id] values in the streamlink attribute table match the [Pfaf_orig] values in the basin attribute table.
  1. Open the attribute table for the streamlink theme.
  2. Return to the view and from the View menu, select "Add Event Theme..."
    1. For the table, select the Attribute table for the streamlink theme.
    2. For the X and Y fields, choose "X_first" and "Y_first", then click the OK button. A point theme will be added to the view.
  3. Make the new point theme the active theme, and select "Properties" from the theme menu. Rename the theme to sl-pts (this is to avoid confusion with the streamlink polyline theme's attribute table).
  4. Make the streamlink points theme and the basin polygon theme active.
  5. Click on the Open Tables button to open the attribute tables for both the streamlink points theme and the basin polygon theme.
  6. Select the [Shape] field in both tables.
  7. Make the streamlink points table active and click on the "Join" button. Since the shape field is the active field in each table, this will perform a spatial join and link the attributes of the polygons to each point that falls within it.
  8. Perform the following query on the streamlink points table: ([Pfaf_id] <> [Pfaf_orig]). This will select streamlink points where the Pfafstetter code currently assigned to the streamlink does not match the basin's Pfafstetter code.
  9. Correct any streamlinks than need correcting by redoing any of the previous processing steps (merge, delete, reset [Pfaf_id]).
  10. Remove the streamlink points theme and attribute table.
  11. Once all edits to the streamlink are completed, update/create length in miles:
    1. Make the streamlink theme the active theme.
    2. From the Bsn-Tools menu, select " Area/Length ".

11. Join streamlink attributes to basin attribute table

The upstream/downstream relationships are added to the basins by using the attributes from the final edited streamlink theme. This is done by joining the streamlink attributes to the basins attributes using the [Pfaf_id] field in the streamlink table and the [Pfaf_orig] field in the basin table.
  1. Open the streamlink table.
  2. From the Table menu, select "Properties". Turn off the Visible check mark for the [Flow_acc] field and any other unneeded fields or fields that are duplicated in the basin attribute table. Do not turn off the following fields:
    1. Shape
    2. Basin_id
    3. Parent_id
    4. Any "Upstream" fields.
    5. Pfaf_id
  3. In the streamlink table, select the [Pfaf_id] field.
  4. Open the attribute table for the basin theme and select the [Pfaf_orig] field.
  5. Make sure both the streamlink and basin attribute tables are open and make the basin table the active table. Click on the "Join" button. The streamlink table will automatically close.
  6. Return to the view with the basin theme and make the basin theme the active theme.
    1. Clear any selection on the basin theme.
    2. From the Theme menu, select "Convert to Shapefile..." and save to kxxx_ref_basins.shp. Answer yes to add the new theme to the view.
  7. Return to the original basin table with the streamlinks joined to it.
    1. In the View, make the basin theme the only active theme,
    2. Click on the Open Theme Table button.
    3. From the Table menu, select "Remove all Joins".
    4. Remove the table from the project.
  8. Open the attribute table for the new basin theme.
    1. In the View, make the kxxx_ref_basins.shp theme the only active theme.
    2. Click on the Open Theme Table button.
    3. From the Bsn-Tools menu, Select " Init Basin_id ". This will insure the basins that did not have a corresponding streamlink will have valid [Basin_id], [Parent_id] and upstream values. The changed features will now be selected.
    4. The selection now contains basins where there was no streamlink to set the [Basin_id] field. Examine these basins and determine if any of these basins should be deleted or needed to be linked to other basins. Perform any additional edits that are required.
  9. The upstream links are always sorted by flow accumulation. However, the flow accumulation values used by the streamlinks may not represent the basin areas so it is a good idea to recompute the flow accumulation based on the basin areas. First, the flow accumulation must be reset to zero. You may also want to identify basins that receive flow into them from outside the extent of the shapefile and set their flow accumulation to a flag or reasonable value. This will help identify the mainstem segments better.
    1. Make the basin theme active.
    2. Manually select basins that receive flow into them from outside the theme.
    3. Open the attribute table and from the Table menu, select "Start Editing".
      1. Select the [Flow_acc] field.
      2. Click the Calculate button and enter a value (9999 for a major river like Mississippi or 999 for a major stream) to be applied to all the selected basins. Click the Ok button.
      3. From the Edit menu, select "Switch Selection".
      4. Click the Calculate button and enter 0 for the value. Click the Ok button.
      5. From the Table menu, select "Stop Editing".
    4. Return to the View and make the kxxx_ref_basins.shp theme active.
    5. From the Bsn-Tools menu, select " Area/Length ".
    6. From the Bsn-Tools menu, select " Compute Flow Accum ". This will take a while (> 30 minutes) depending on number of streamlinks, stream network topology and CPU speed.
    7. From the Bsn-Tools menu, select " Add Upstream Links ".
This completes the edits to add the upstream and downstream links to the basins. Save and back up this shapefile and use is as the reference set for your site.

12. Join the basin attributes to the streamlink

The basin theme now has the proper topology established by flow accumulation. To make the basin and streamlink themes consistent, the basin attributes need to be added to the streamlink theme. This will be done through a table join using the [Basin_id] field.
  1. In the View, make the kxxx_ref_basins.shp theme the only active theme.
  2. Click on the "Open Theme Table" button.
  3. From the table menu, select "Properties..." and turn on the Visible check mark for all fields.
  4. Make the [Basin_id] field active.
  5. Open the streamlink table.
  6. From the Table menu, select "Properties..."
  7. Turn off the Visible check mark for fields that are duplicated in the basin theme including the [Pfaf_id], [Parent_id], [Flow_acc], and "Upstream" fields. The fields that must remain on are:
    1. Shape
    2. Basin_id
  8. Make the [Basin_id] field active.
  9. Make sure both the streamlink and basin attribute tables are open and make the streamlink table the active table. Click on the "Join" button. The basin table will automatically close.
  10. Return to the View and make the streamlink theme the active theme.
  11. Clear any selections on the theme.
  12. From the Theme menu, select "Convert to Shapefile...". Save the new shapefile as kxxx_ref_sl.shp . Save this shapefile as the reference streamlink theme that corresponds to kxxx_ref_basins.shp.
  13. Make the streamlink theme with the join the active theme.
    1. Click on the "Open Theme Table" button.
    2. From the Table menu, select "Remove All Joins".

Done!


On to getting getting basins ready for FFMP.