Просмотр исходного кода

wxGUI/profile: fix https://trac.osgeo.org/grass/ticket/1787 - wxplot now converts distance from meters to the current units

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@61269 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 10 лет назад
Родитель
Сommit
a9decf6024
1 измененных файлов с 19 добавлено и 1 удалено
  1. 19 1
      gui/wxpython/wxplot/profile.py

+ 19 - 1
gui/wxpython/wxplot/profile.py

@@ -43,6 +43,22 @@ from gui_core.toolbars import BaseToolbar, BaseIcons
 from wxplot.dialogs    import ProfileRasterDialog, PlotStatsFrame
 from core.gcmd         import RunCommand, GWarning, GError, GMessage
 
+
+def get_unit_conversion():
+    """Get conversion factor to convert output from r.profile to current units.
+    Module r.profile always outputs distance in meters.
+
+    .. todo:: create a wrapper for g.proj in grass.core    
+    """
+    proj = RunCommand(prog='g.proj', read=True, flags='g').strip()
+    if not proj:
+        # TODO put some warning here
+        return 1.
+
+    proj = grass.parse_key_val(proj, sep='=')
+    return 1 / float(proj.get('meters', 1))
+
+
 class ProfileFrame(BasePlotFrame):
     """Mainframe for displaying profile of one or more raster maps. Uses wx.lib.plot.
     """
@@ -59,6 +75,7 @@ class ProfileFrame(BasePlotFrame):
             self.SetToolBar(self.toolbar)
         self.SetTitle(_("GRASS Profile Analysis Tool"))
         self._units = units
+        self._conversion = get_unit_conversion()
 
         #
         # Init variables
@@ -258,7 +275,8 @@ class ProfileFrame(BasePlotFrame):
             if dist == None or dist == '' or dist == 'nan' or \
                 elev == None or elev == '' or elev == 'nan':
                 continue
-            dist = float(dist)
+            # remove conversion if one day r.profile starts to output distance in projection units!
+            dist = self._conversion * float(dist)
             elev = float(elev)
             datalist.append((dist,elev))