diff --git a/gui/wxpython/wxplot/profile.py b/gui/wxpython/wxplot/profile.py index 88a4ec0eeb0..33458cd6a05 100644 --- a/gui/wxpython/wxplot/profile.py +++ b/gui/wxpython/wxplot/profile.py @@ -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.""" @@ -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 @@ -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 @@ -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 = [] @@ -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]