Skip to content

Commit

Permalink
script to generate README doc images
Browse files Browse the repository at this point in the history
  • Loading branch information
cyschneck committed Apr 12, 2024
1 parent 7d108af commit 7a23df9
Show file tree
Hide file tree
Showing 55 changed files with 428 additions and 17 deletions.
27 changes: 15 additions & 12 deletions README.md
Expand Up @@ -537,7 +537,7 @@ equal_axis will set the x and y axis of the plot to be equal. Useful to show the

Two options for measuring and displaying coordinates. The two options are "Decimal Degrees" and "Relative Distance". "Decimal Degrees" is the default option that uses the original data coordinate system with latitude/longitude. "Relative Distance" changes the coordinates of each point to be the distance (in meters) from the first point on the left bank

| coordinate_unit="Decimal Degrees" | remove_intersections="Relative Distance" |
| coordinate_unit="Decimal Degrees" | coordinate_unit="Relative Distance" |
| ------------- | ------------- |
| ![dd_coords+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/river_coords_width_decimal_degrees.png) | ![rd_coords+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/river_coords_width_relative_distance.png)|

Expand Down Expand Up @@ -580,42 +580,45 @@ Note: it is best practice to plot the centerline and width with same arguments i
The centerline is defined by the greatest distance from the right and left bank, created from a Voronoi Diagram. The remaining paths within the river are filtered through Dijkstra's algorithm to find the shortest path that is the centerline

### Right and Left bank points are plotted (X-Axis for Latitude, Y-Axis for Longitude)
![example+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/example1.png)
![algorithm_step1+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/algorithm_step1.png)

### Generate a polygon to encapsulate the river between the right and left banks to define in and outside of river
![example+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/example2.png)
![algorithm_step2+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/algorithm_step2.png)

### Generate a Voronoi diagram based on the points along the riverbanks
![example+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/example3.png)
![algorithm_step3+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/algorithm_step3.png)

### Display Voronoi ridge vertices that lie within the polygon (within the riverbanks)
![example+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/example4.png)
Filter out any point pairs that only have one connection to filter out the short dead end paths

### Filter out any point pairs that only have one connection to filter out the short dead end paths
With the vertices removed, it is possible to form multiple unconnected graphs within the polygon. The largest subgraph is assumed to contain the centerline and the other subgraphs are filtered out
![example+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/example6.png)
![algorithm_step4+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/algorithm_step4.png)

### Define Top and Bottom of Polygon
The top of the river is defined as the last plotted points in the data, while the bottom of the river is the first plotted points
![algorithm_step5+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/algorithm_step5.png)

### Find the starting and ending node based on distance from the top and bottom of polygon
The starting/ending node is defined by the vertex closest to the top/bottom of the polygon along the longest path
![example+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/example7.png)
![algorithm_step6+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/algorithm_step6.png)

### Find the shortest path from the starting node to the ending node ([Dijkstra's Algorithm](https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.shortest_paths.generic.shortest_path.html#networkx.algorithms.shortest_paths.generic.shortest_path))
| Points on Riverbank | NetworkX Graph of Points on Riverbank |
| ------------- | ------------- |
| ![example+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/example10.png) | ![example+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/example9.png) |
| ![algorithm_step7+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/algorithm_step7.png) | ![algorithm_step8+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/algorithm_step8.png) |

### Display the centerline found by connecting the starting/ending node with the shortest path
![example+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/example8.png)
![algorithm_step9+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/algorithm_step9.png)

This is an attempt at a more robust algorithm working from raw data to ensure that all dead ends are removed, and no gaps exist in the centerline

Points that only have one connection are removed, but limiting the number of connections for a point to just two will create gaps. The Voronoi vertices connect to other vertex values, but some connect to more and some only connect to one other point. Removing additional values will create gaps, so this is avoided in this code by not applying additional filters.

**All vertices:**
![example+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/example4.png)
![algorithm_step4+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/algorithm_step4.png)

**Vertices that have at least two connections (that would create gaps):**
![example+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/example5.png)
![algorithm_step10+png](https://raw.githubusercontent.com/cyschneck/centerline-width/main/data/doc_examples/algorithm_step10.png)

## Debugging, Error Handling, and Edge Cases
### Wide Start/End of River
Expand Down
1 change: 1 addition & 0 deletions centerline_width/__init__.py
Expand Up @@ -21,6 +21,7 @@

# centerline.py function calls
from .centerline import centerlinePath
from .centerline import generateNXGraph
from .centerline import networkXGraphShortestPath
from .centerline import equalDistanceCenterline
from .centerline import evenlySpacedCenterline
Expand Down
11 changes: 6 additions & 5 deletions centerline_width/centerline.py
Expand Up @@ -7,7 +7,7 @@
import networkx as nx
from scipy import interpolate
from shapely.geometry import Point, LineString
import pyproj
from pyproj import Geod
import geopy.distance

# Internal centerline_width reference to access functions, global variables, and error handling
Expand Down Expand Up @@ -79,7 +79,7 @@ def networkXGraphShortestPath(nx_graph=None,
"[FAILED] No direct path found from starting node to ending node. To view gaps, plotCenterline(display_all_possible_paths=True). Recommended fix, rerun riverCenterline: set interpolate_data=True or (if interpolate_data=True) increase interpolate_n"
)
return None
#nx.draw(graph_connections, with_labels=True, font_size=10)
#nx.draw(nx_graph, with_labels=True, font_size=10)
return shortest_path
else:
return None
Expand All @@ -88,7 +88,8 @@ def networkXGraphShortestPath(nx_graph=None,
def centerlinePath(river_voronoi=None,
river_polygon=None,
top_polygon_line: LineString = None,
bottom_polygon_line: LineString = None):
bottom_polygon_line: LineString = None,
multiple_connections: int = 0):
# Return the starting node, ending node, all possible paths positions, and all paths starting/end position as a dictionary
start_end_points_dict = centerline_width.pointsFromVoronoi(
river_voronoi,
Expand All @@ -102,7 +103,7 @@ def centerlinePath(river_voronoi=None,
for start_point, end_point_list in start_end_points_dict.items():
if len(
end_point_list
) > 0: # TESTING TESTING: Show only the end points that have multiple connections (set to 0 during production)
) > multiple_connections: # TESTING TESTING: Show only the end points that have multiple connections (set to 0 during production)
# Find the starting and ending node based on distance from the top and bottom of the polygon
if starting_node is None:
starting_node = start_point
Expand Down Expand Up @@ -158,7 +159,7 @@ def equalDistanceCenterline(centerline_coordinates: list = None,

equal_distance_between_centerline_coordinates = []

geodesic = pyproj.Geod(ellps=ellipsoid)
geodesic = Geod(ellps=ellipsoid)

# Iterate through coordinates based on a set distance (distance_m)
lon_start, lat_start = centerline_coordinates[0]
Expand Down
2 changes: 2 additions & 0 deletions centerline_width/width.py
Expand Up @@ -359,6 +359,8 @@ def riverWidthFromCenterline(

width_dict = {}

geodesic = Geod(ellps=river_object.ellipsoid)

for centerline_coord, _ in right_width_coordinates.items():
# store the distance between the lat/lon position of the right/left bank
lon1, lat1 = right_width_coordinates[centerline_coord]
Expand Down
Binary file added data/doc_examples/algorithm_step1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/doc_examples/algorithm_step10.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/doc_examples/algorithm_step2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/doc_examples/algorithm_step3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/doc_examples/algorithm_step4.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/doc_examples/algorithm_step5.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/doc_examples/algorithm_step6.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/doc_examples/algorithm_step7.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/doc_examples/algorithm_step8.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/doc_examples/algorithm_step9.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/doc_examples/equal_distance_centerline.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/doc_examples/equal_distance_centerline_relative.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/doc_examples/evenly_spaced_centerline.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/doc_examples/evenly_spaced_centerline_relative.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed data/doc_examples/example1.png
Binary file not shown.
Binary file removed data/doc_examples/example10.png
Binary file not shown.
Binary file removed data/doc_examples/example2.png
Binary file not shown.
Binary file removed data/doc_examples/example3.png
Binary file not shown.
Binary file removed data/doc_examples/example4.png
Binary file not shown.
Binary file removed data/doc_examples/example5.png
Binary file not shown.
Binary file removed data/doc_examples/example6.png
Binary file not shown.
Binary file removed data/doc_examples/example7.png
Binary file not shown.
Binary file removed data/doc_examples/example8.png
Binary file not shown.
Binary file removed data/doc_examples/example9.png
Binary file not shown.
Binary file modified data/doc_examples/interpolate_n_centerpoints_200.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/doc_examples/interpolate_n_centerpoints_75.png
Binary file modified data/doc_examples/river_coords_centerline.png
Binary file modified data/doc_examples/river_coords_equal_ax.png
Binary file modified data/doc_examples/river_coords_not_equal_default_ax.png
Binary file modified data/doc_examples/river_coords_transect_avg.png
Binary file modified data/doc_examples/river_coords_transect_direct.png
Binary file modified data/doc_examples/river_coords_width.png
Binary file modified data/doc_examples/river_coords_width_dark_mode_false.png
Binary file modified data/doc_examples/river_coords_width_dark_mode_true.png
Binary file modified data/doc_examples/river_coords_width_decimal_degrees.png
Binary file modified data/doc_examples/river_coords_width_keep_intersections.png
Binary file modified data/doc_examples/river_coords_width_relative_distance.png
Binary file modified data/doc_examples/river_coords_width_remove_intersections.png
Binary file modified data/doc_examples/river_coords_width_transect_30.png
Binary file modified data/doc_examples/river_coords_width_transect_6.png
Binary file modified data/doc_examples/river_coords_width_with_smoothing.png
Binary file modified data/doc_examples/river_coords_width_without_smoothing.png
Binary file modified data/doc_examples/river_coords_with_centerline.png
Binary file modified data/doc_examples/river_coords_without_centerline.png
Binary file modified data/doc_examples/river_example.png
Binary file modified data/doc_examples/river_relative_distance_coords_centerline.png
Binary file modified data/doc_examples/smoothed_centerline.png
Binary file modified data/doc_examples/smoothed_centerline_relative.png
Binary file modified data/doc_examples/voronoi_centerline.png
Binary file modified data/doc_examples/voronoi_centerline_relative.png

0 comments on commit 7a23df9

Please sign in to comment.