Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not crash for consecutive points with identical coordinates. #1574

Merged
merged 1 commit into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions mslib/msui/mpl_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,14 +694,18 @@ def gcpoints2(self, lon0, lat0, lon1, lat1, del_s=100., map_coords=True):
# use great circle formula for a perfect sphere.
_, _, dist = self.gc.inv(lon0, lat0, lon1, lat1)
npoints = int((dist + 0.5 * 1000. * del_s) / (1000. * del_s))
lonlats = self.gc.npts(lon0, lat0, lon1, lat1, npoints)
lons = [lon0]
lats = [lat0]
for lon, lat in lonlats:
lons.append(lon)
lats.append(lat)
lons.append(lon1)
lats.append(lat1)
if npoints == 0:
lons = [lon0, lon1]
lats = [lat0, lat1]
else:
lonlats = self.gc.npts(lon0, lat0, lon1, lat1, npoints)
lons = [lon0]
lats = [lat0]
for lon, lat in lonlats:
lons.append(lon)
lats.append(lat)
lons.append(lon1)
lats.append(lat1)
if map_coords:
x, y = self(lons, lats)
else:
Expand Down
10 changes: 6 additions & 4 deletions mslib/msui/remotesensing_dockwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,12 @@ def direction_coordinates(self, gc_lines):
Returns: List of tuples of longitude/latitude coordinates

"""
lins = [(_line[0][mid], _line[0][mid + 1],
_line[1][mid], _line[1][mid + 1]) for _line, mid in
zip(gc_lines, [len(_line[0]) // 2 for _line in gc_lines])]
lens = [np.hypot(_line[0][0] - _line[0][-1], _line[0][0] - _line[0][-1]) * 110. for _line in gc_lines]
lins = [(_line[0][mid], _line[0][mid + 1], _line[1][mid], _line[1][mid + 1])
Copy link
Member

@ReimarBauer ReimarBauer Oct 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as bug fix okay, but that is not getting better readable. When there are tests written may be some of the methods can be extracted as functions to a remotesensing utils

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.
However, I did also not see how to clean this up easily, or how to rewrite this using "numpy" terminology. The whole thing should be very slow and I am surprised it is still real-time capable.

for _line, mid in zip(gc_lines, [len(_line[0]) // 2 for _line in gc_lines])
if len(_line[0]) > 2]
lens = [np.hypot(_line[0][0] - _line[0][-1], _line[0][0] - _line[0][-1]) * 110.
for _line in gc_lines
if len(_line[0]) > 2]
lins = [(x0 * np.cos(np.deg2rad(np.mean([y0, y1]))), x1 * np.cos(np.deg2rad(np.mean([y0, y1]))), y0, y1)
for x0, x1, y0, y1 in lins]
lins = [_x for _x, _l in zip(lins, lens) if _l > 10]
Expand Down