Skip to content

Commit

Permalink
Do not crash for consecutive points with identical coordinates.
Browse files Browse the repository at this point in the history
Fix #1571
  • Loading branch information
joernu76 committed Sep 30, 2022
1 parent e647124 commit d30e871
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
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])
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

0 comments on commit d30e871

Please sign in to comment.