Skip to content

Commit

Permalink
Fixed environment and code to cull points when too close
Browse files Browse the repository at this point in the history
  • Loading branch information
draguve committed Oct 4, 2024
1 parent a3c5fa4 commit 4bd746a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
4 changes: 3 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ dependencies:
- scikit-image
- tqdm
- conda-forge::scikit-learn
- conda-forge::gmsh
- conda-forge::fastkml
- conda-forge::shapely
- conda-forge::matplotlib
- conda-forge::folium
- conda-forge::netcdf4
- conda-forge::geopy
- gmsh
- conda-forge::python-gmsh
- conda-forge::meshio
prefix: C:\Users\ritwi\.conda\envs\geo
35 changes: 34 additions & 1 deletion merge_and_smooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ def main(
resolution: Annotated[int, typer.Option(
help="Distance(in m) between the points when using smoothing/Resolution of smoothed output")] = 1000,
cat_mull_room_alpha: Annotated[float, typer.Option(
help="0.5 for the centripetal spline, 0.0 for the uniform spline, 1.0 for the chordal spline.")] = 0.5
help="0.5 for the centripetal spline, 0.0 for the uniform spline, 1.0 for the chordal spline.")] = 0.5,
remove_close_points: Annotated[bool, typer.Option(help="Remove points if they're too close")] = True,
remove_threshold: Annotated[float, typer.Option(help="Threshold for removing points in m")] = 5.0,
print_distance: Annotated[bool, typer.Option(help="Print distance's between the points")] = False,
):
data = read_csv(input_filename)
lines = {}
Expand Down Expand Up @@ -163,10 +166,40 @@ def main(
extended_points, catmull = None, all_points
else:
extended_points, catmull = generate_catmull_rom(all_points, resolution, cat_mull_room_alpha)
catmull = catmull[0:-2]
final_num_points += catmull.shape[0]
outputs.append([id, name, "", all_points, extended_points, catmull])
print(f"Final paths have {final_num_points} points")

if remove_close_points:
deleted_points = 0
for output in outputs:
indexes = [0, ]
last_added = 0
rom = output[-1]
for i in range(1, rom.shape[0]):
p1 = rom[last_added][0:2]
p2 = rom[i][0:2]
distance_p1_p2 = distance.distance(p1[::-1], p2[::-1]).m
if distance_p1_p2 > remove_threshold:
indexes.append(i)
last_added = i
else:
deleted_points += 1
indexes = np.array(indexes)
output[-1] = output[-1][indexes]
print(f"Deleted {deleted_points} points for being too close")

# Print Distance between points
if print_distance:
for output in outputs:
rom = output[-1]
for i in range(1, rom.shape[0]):
p1 = rom[i - 1][0:2]
p2 = rom[i][0:2]
distance_p1_p2 = distance.distance(p1[::-1], p2[::-1]).m
print(distance_p1_p2)

if plot:
for output in outputs:
plt.plot(output[3][:, 0], output[3][:, 1], c="blue", linestyle="-", linewidth=0.5)
Expand Down

0 comments on commit 4bd746a

Please sign in to comment.