Skip to content

Commit

Permalink
wxGUI/wxplot: fix profile plot segmentation points position (#3601)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmszi committed Apr 17, 2024
1 parent 2bf659a commit 46b406b
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion gui/wxpython/wxplot/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
from wxplot.dialogs import ProfileRasterDialog, PlotStatsFrame
from core.gcmd import RunCommand, GWarning, GError, GMessage

try:
import grass.lib.gis as gislib

haveCtypes = True
except (ImportError, TypeError):
haveCtypes = False


class ProfileFrame(BasePlotFrame):
"""Mainframe for displaying profile of one or more raster maps. Uses wx.lib.plot."""
Expand All @@ -57,6 +64,7 @@ def __init__(
self.SetTitle(_("GRASS Profile Analysis Tool"))
# in case of degrees, we want to use meters
self._units = units if "degree" not in units else "meters"
self._is_lat_lon_proj = self.Map.projinfo.get("proj") == "ll"

#
# Init variables
Expand Down Expand Up @@ -151,7 +159,9 @@ def SetupProfile(self):
"""
# create list of coordinate points for r.profile
dist = 0
segment_geodesic_dist = 0
cumdist = 0
segment_geodesic_cum_dist = 0
self.coordstr = ""
lasteast = lastnorth = None

Expand Down Expand Up @@ -182,6 +192,10 @@ def SetupProfile(self):
# title of window
self.ptitle = _("Profile of")

# Initialize lattitude-longitude geodesic distance calculation
if self._is_lat_lon_proj and haveCtypes:
gislib.G_begin_distance_calculations()

# create list of coordinates for transect segment markers
if len(self.transect) > 0:
self.seglist = []
Expand All @@ -206,14 +220,27 @@ def SetupProfile(self):
math.pow((lasteast - point[0]), 2)
+ math.pow((lastnorth - point[1]), 2)
)
if self._is_lat_lon_proj and haveCtypes:
segment_geodesic_dist = gislib.G_distance(
lasteast, lastnorth, point[0], point[1]
)
cumdist += dist
if self._is_lat_lon_proj and haveCtypes:
segment_geodesic_cum_dist += segment_geodesic_dist

# store total transect length
self.transect_length = cumdist

# build a list of distance,value pairs for each segment of
# transect
self.seglist.append((cumdist, val))
self.seglist.append(
(
segment_geodesic_cum_dist
if self._is_lat_lon_proj and haveCtypes
else cumdist,
val,
)
)
lasteast = point[0]
lastnorth = point[1]

Expand Down

0 comments on commit 46b406b

Please sign in to comment.