Skip to content

Commit

Permalink
option to save Equal Distance csv/mat, default to 10 meters
Browse files Browse the repository at this point in the history
  • Loading branch information
cyschneck committed Jun 22, 2023
1 parent c11b859 commit d822646
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@ centerline_width.riverCenterline(csv_data=None,
interpolate_data=False,
interpolate_n=5,
interpolate_n_centerpoints=None,
equal_distance=None)
equal_distance=10)
```
* **[REQUIRED]** csv_data (string): File location of the text file to convert
* [OPTIONAL] optional_cutoff (int): Include only the first x number of the data to chart (useful for debugging)
* [OPTIONAL] interpolate_data (bool): Interpolate between existing data by adding additional points
* [OPTIONAL] interpolate_n (int): Number of additional points to add between existing data, defaults to 5 (note: larger numbers will take exponentially longer to run, recommends less than 15)
* [OPTIONAL] interpolate_n_centerpoints (int): Number of points used to interpolate the Voronoi centerline, defaults to the the length of the data frame (df_len)
* [OPTIONAL] equal_distance (int): Equal distance between points (in meters) used to interpolate the Voronoi centerline, defaults 1/10th the length fo the Voronoi centerline
* [OPTIONAL] equal_distance (int): Equal distance between points (in meters) used to interpolate the Voronoi centerline, defaults 10 meters

**Solutions for sparse data:**

Expand Down Expand Up @@ -198,7 +198,7 @@ centerline_width.riverCenterline(csv_data=None,
* left_bank_coordinates (list of tuples): list of coordinates of the left bank generated from the csv file (`[(x, y), (x, y)]`)
* right_bank_coordinates (list of tuples) list of coordinates of the right bank generated from the csv file (`[(x, y), (x, y)]`)
* df_len (int): Length of the data frame of the csv data (spliced by the optional_cutoff)
* equal_distance (int): Distance between points (in meters) used in centerlineEqualDistance, defaults to 1/10th the length of the centerline
* equal_distance (int): Distance between points (in meters) used in centerlineEqualDistance, defaults to points every 10 meters
* bank_polygon (Shapley Polygon): Multi-sided polygon generated to encapsulate river bank (used to define an inside and an outside of the river)
* top_bank (Shapley Linestring): Linestring that represents the top of the river/polygon
* bottom_bank (Shapley Linestring): Linestring that represents the bottom of the river/polygon
Expand Down Expand Up @@ -243,7 +243,7 @@ Centerline coordinates are formed by Equally Distanced vertices, set by `equal_d
river_object.centerlineEqualDistance
```

Centerline coordinates are formed by Evenly Spaced vertices
Centerline coordinates are formed by Evenly Spaced vertices, set by `interpolate_n_centerpoints`
```
river_object.centerlineEvenlySpaced
```
Expand All @@ -268,7 +268,7 @@ Save the centerline coordinates to a csv file with columns for latitude and long
saveCenterlineCSV(save_to_csv=None, centerline_type="Voronoi")
```
* **[REQUIRED]** save_to_csv (str): CSV filename, requires a .csv extension
* [OPTIONAL] centerline_type (str): Centerline type to save to CSV (not case-sensitive), options: ["Voronoi", "Evenly Spaced", "Smoothed"], defaults to "Voronoi"
* [OPTIONAL] centerline_type (str): Centerline type to save to CSV (not case-sensitive), options: ["Voronoi", "Evenly Spaced", "Smoothed", "Equal Distance"], defaults to "Voronoi"
* [OPTIONAL] latitude_header (str): Column header for latitude values, defaults to `<centerline_type> Centerline Latitude (Deg)`
* [OPTIONAL] longitude_header (str): Column header for Longitude values, defaults to `<centerline_type> Centerline Longitude (Deg)`

Expand All @@ -286,7 +286,7 @@ Save the centerline coordinates to a .mat file with columns for latitude and lon
saveCenterlineMAT(save_to_mat=None, centerline_type="Voronoi")
```
* **[REQUIRED]** save_to_mat (str): MAT filename, requires a .mat extension
* [OPTIONAL] centerline_type (str): Centerline type to save to MAT (not case-sensitive), options: ["Voronoi", "Evenly Spaced", "Smoothed"], defaults to "Voronoi"
* [OPTIONAL] centerline_type (str): Centerline type to save to MAT (not case-sensitive), options: ["Voronoi", "Evenly Spaced", "Smoothed", "Equal Distance"], defaults to "Voronoi"
* [OPTIONAL] latitude_header (str): Column header for latitude values, defaults to `<centerline_type>_Centerline_Latitude_(Deg)` (will remove spaces and special characters and replaces with underscores)
* [OPTIONAL] longitude_header (str): Column header for Longitude values, defaults to `<centerline_type>_Centerline_Longitude_(Deg)` (will remove spaces and special characters and replaces with underscores)

Expand Down
2 changes: 2 additions & 0 deletions centerline_width/centerline.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ def saveCenterlineCSV(river_object=None, save_to_csv=None, latitude_header=None,
centerline_type = centerline_type.title()

if centerline_type == "Voronoi": centerline_coordinates_by_type = river_object.centerlineVoronoi
if centerline_type == "Equal Distance": centerline_coordinates_by_type = river_object.centerlineEqualDistance
if centerline_type == "Evenly Spaced": centerline_coordinates_by_type = river_object.centerlineEvenlySpaced
if centerline_type == "Smoothed": centerline_coordinates_by_type = river_object.centerlineSmoothed

Expand All @@ -451,6 +452,7 @@ def saveCenterlineMAT(river_object=None, save_to_mat=None, latitude_header=None,
centerline_type = centerline_type.title()

if centerline_type == "Voronoi": centerline_coordinates_by_type = river_object.centerlineVoronoi
if centerline_type == "Equal Distance": centerline_coordinates_by_type = river_object.centerlineEqualDistance
if centerline_type == "Evenly Spaced": centerline_coordinates_by_type = river_object.centerlineEvenlySpaced
if centerline_type == "Smoothed": centerline_coordinates_by_type = river_object.centerlineSmoothed

Expand Down
2 changes: 1 addition & 1 deletion centerline_width/error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def errorHandlingSaveCenterlineCSV(river_object=None, save_to_csv=None, centerli
logger.critical("\nCRITICAL ERROR, [save_to_csv]: Extension must be a .csv file, current extension = '{0}'".format(save_to_csv.split(".")[1]))
exit()

centerline_type_options = ["Voronoi", "Evenly Spaced", "Smoothed"]
centerline_type_options = ["Voronoi", "Evenly Spaced", "Smoothed", "Equal Distance"]
if type(centerline_type) != str:
logger.critical("\nCRITICAL ERROR, [centerline_type]: Must be a str, current type = '{0}'".format(type(centerline_type)))
exit()
Expand Down
5 changes: 2 additions & 3 deletions centerline_width/riverCenterlineClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self,
interpolate_data=False,
interpolate_n=5,
interpolate_n_centerpoints=None,
equal_distance=None):
equal_distance=10):
centerline_width.errorHandlingRiverCenterlineClass(csv_data=csv_data,
optional_cutoff=optional_cutoff,
interpolate_data=interpolate_data,
Expand Down Expand Up @@ -64,8 +64,7 @@ def __init__(self,

# Centerline length
self.centerlineLength = centerline_width.centerlineLength(centerline_coordinates=shortest_path_coordinates)
self.equal_distance = equal_distance
if self.equal_distance is None: self.equal_distance = self.centerlineLength * 0.1 # set to 1/10th the length of the centerline
self.equal_distance = equal_distance

# The different types of Centerline coordinates
self.centerlineEqualDistance = centerline_width.equalDistanceCenterline(centerline_coordinates=self.centerlineVoronoi,
Expand Down

0 comments on commit d822646

Please sign in to comment.