[GRASS-SVN] r62394 - in grass/branches/releasebranch_7_0: gui/wxpython/core gui/wxpython/lmgr gui/wxpython/mapdisp scripts

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Oct 26 16:53:27 PDT 2014


Author: annakrat
Date: 2014-10-26 16:53:27 -0700 (Sun, 26 Oct 2014)
New Revision: 62394

Modified:
   grass/branches/releasebranch_7_0/gui/wxpython/core/utils.py
   grass/branches/releasebranch_7_0/gui/wxpython/lmgr/frame.py
   grass/branches/releasebranch_7_0/gui/wxpython/mapdisp/frame.py
   grass/branches/releasebranch_7_0/gui/wxpython/mapdisp/main.py
   grass/branches/releasebranch_7_0/scripts/Makefile
Log:
d.to.rast: new module for wxGUI and d.mon to save map display content as raster map (merge from trunk, r62281)

Modified: grass/branches/releasebranch_7_0/gui/wxpython/core/utils.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/core/utils.py	2014-10-26 23:49:40 UTC (rev 62393)
+++ grass/branches/releasebranch_7_0/gui/wxpython/core/utils.py	2014-10-26 23:53:27 UTC (rev 62394)
@@ -1002,6 +1002,7 @@
                  'd.colortable'   : 'colortable',
                  'd.graph'        : 'graph',
                  'd.out.file'     : 'export',
+                 'd.to.rast'      : 'torast',
                  'd.text'         : 'text'
                  }
 ltype2command = {}

Modified: grass/branches/releasebranch_7_0/gui/wxpython/lmgr/frame.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/lmgr/frame.py	2014-10-26 23:49:40 UTC (rev 62393)
+++ grass/branches/releasebranch_7_0/gui/wxpython/lmgr/frame.py	2014-10-26 23:53:27 UTC (rev 62394)
@@ -660,6 +660,16 @@
             GUI(parent=self, show=False).ParseCommand(command,
                                                       completed=(self.GetMapDisplay().DOutFileOptData,
                                                                  '', ''))
+        elif layertype == 'torast':
+            if len(command) <= 1:
+                task = GUI(parent=self, show=True).ParseCommand(command,
+                                                                completed=(self.GetMapDisplay().DToRastOptData,
+                                                                '', ''))
+            else:
+                task = GUI(parent=self, show=None).ParseCommand(command,
+                                                                completed=(self.GetMapDisplay().DToRastOptData,
+                                                                '', ''))
+                self.GetMapDisplay().DToRast(command=task.get_cmd())
         else:
             # add layer into layer tree
             lname, found = GetLayerNameFromCmd(command, fullyQualified = True,

Modified: grass/branches/releasebranch_7_0/gui/wxpython/mapdisp/frame.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/mapdisp/frame.py	2014-10-26 23:49:40 UTC (rev 62393)
+++ grass/branches/releasebranch_7_0/gui/wxpython/mapdisp/frame.py	2014-10-26 23:53:27 UTC (rev 62394)
@@ -35,7 +35,7 @@
 from vdigit.toolbars    import VDigitToolbar
 from mapdisp.toolbars   import MapToolbar, NvizIcons
 from mapdisp.gprint     import PrintOptions
-from core.gcmd          import GError, GMessage
+from core.gcmd          import GError, GMessage, RunCommand
 from dbmgr.dialogs      import DisplayAttributesDialog
 from core.utils         import ListOfCatsToRange, GetLayerNameFromCmd, _
 from gui_core.dialogs import GetImageHandlers, ImageSizeDialog
@@ -649,6 +649,76 @@
 
         self.DOutFile(dcmd)
 
+    def DToRast(self, command):
+        """Saves currently loaded composition of layers as a raster map.
+        """
+        if self.IsPaneShown('3d'):
+            self._giface.WriteError(_('d.to.rast can be used only in 2D mode.'))
+            return
+        outputRaster = None
+        overwrite = False
+        for param in command[1:]:
+            try:
+                p, val = param.split('=')
+                if p == 'output':
+                    outputRaster = val
+            except ValueError:
+                if param.startswith('--overwrite'):
+                    overwrite = True
+
+        if not outputRaster:
+            return
+        # output file as PNG
+        tmpName = 'd_to_rast_tmp'
+        pngFile = grass.tempfile(create=False) + '.png'
+        dOutFileCmd = ['d.out.file', 'output=' + pngFile, 'format=png']
+        self.DOutFile(dOutFileCmd)
+        # import back as red, green, blue rasters
+        returncode, messages = RunCommand('r.in.png', input=pngFile, output=tmpName,
+                                          quiet=True, overwrite=overwrite, getErrorMsg=True)
+        if not returncode == 0:
+            self._giface.WriteError(_('Failed to run d.to.rast:\n') + messages)
+            return
+        # set region for composite
+        grass.use_temp_region()
+        returncode, messages = RunCommand('g.region', rast=tmpName + '.r',
+                                          quiet=True, getErrorMsg=True)
+        if not returncode == 0:
+            grass.del_temp_region()
+            self._giface.WriteError(_('Failed to run d.to.rast:\n') + messages)
+            return
+        # composite
+        returncode, messages = RunCommand('r.composite', red=tmpName + '.r',
+                                          green=tmpName + '.g', blue=tmpName + '.b',
+                                          output=outputRaster, quiet=True,
+                                          overwrite=overwrite, getErrorMsg=True)
+        grass.del_temp_region()
+        RunCommand('g.remove', type='rast', flags='f', quiet=True,
+                   names=[tmpName + '.r', tmpName + '.g', tmpName + '.b'])
+        if not returncode == 0:
+            self._giface.WriteError(_('Failed to run d.to.rast:\n') + messages)
+            grass.try_remove(pngFile)
+            return
+
+        # alignExtent changes only region variable
+        oldRegion = self.GetMap().GetCurrentRegion().copy()
+        self.GetMap().AlignExtentFromDisplay()
+        region = self.GetMap().GetCurrentRegion().copy()
+        self.GetMap().region.update(oldRegion)
+        RunCommand('r.region', map=outputRaster, n=region['n'], s=region['s'],
+                   e=region['e'], w=region['w'], quiet=True)
+
+        grass.try_remove(pngFile)
+
+    def DToRastOptData(self, dcmd, layer, params, propwin):
+        """Dummy function which is called when d.to.rast is called
+        and returns parsed and validated command which is then passed
+        to DToRast method."""
+        if not dcmd:
+            return
+
+        self.DToRast(dcmd)
+
     def _prepareSaveToFile(self):
         """!Get wildcards and format extensions."""
         if self.IsPaneShown('3d'):

Modified: grass/branches/releasebranch_7_0/gui/wxpython/mapdisp/main.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/mapdisp/main.py	2014-10-26 23:49:40 UTC (rev 62393)
+++ grass/branches/releasebranch_7_0/gui/wxpython/mapdisp/main.py	2014-10-26 23:53:27 UTC (rev 62394)
@@ -80,8 +80,9 @@
 
         # generated file for g.pnmcomp output for rendering the map
         self.mapfile = monFile['map'] + '.ppm'
-        # signal sent when d.out.file appears in cmd file, attribute is cmd
+        # signal sent when d.out.file/d.to.rast appears in cmd file, attribute is cmd
         self.saveToFile = Signal('DMonMap.saveToFile')
+        self.dToRast = Signal('DMonMap.dToRast')
         # signal sent when d.what.rast/vect appears in cmd file, attribute is cmd
         self.query = Signal('DMonMap.query')
 
@@ -99,12 +100,15 @@
             fd.close()
             # detect d.out.file, delete the line from the cmd file and export graphics
             if len(lines) > 0:
-                if lines[-1].startswith('d.out.file'):
-                    dOutFileCmd = lines[-1].strip()
+                if lines[-1].startswith('d.out.file') or lines[-1].startswith('d.to.rast'):
+                    dCmd = lines[-1].strip()
                     fd = open(self.cmdfile, 'w')
                     fd.writelines(lines[:-1])
                     fd.close()
-                    self.saveToFile.emit(cmd=utils.split(dOutFileCmd))
+                    if lines[-1].startswith('d.out.file'):
+                        self.saveToFile.emit(cmd=utils.split(dCmd))
+                    else:
+                        self.dToRast.emit(cmd=utils.split(dCmd))
                     return
                 if lines[-1].startswith('d.what'):
                     dWhatCmd = lines[-1].strip()
@@ -360,6 +364,7 @@
         # self.SetTopWindow(Map)
         self.mapFrm.GetMapWindow().SetAlwaysRenderEnabled(True)
         self.Map.saveToFile.connect(lambda cmd: self.mapFrm.DOutFile(cmd))
+        self.Map.dToRast.connect(lambda cmd: self.mapFrm.DToRast(cmd))
         self.Map.query.connect(lambda ltype, maps: self.mapFrm.SetQueryLayersAndActivate(ltype=ltype, maps=maps))
         self.mapFrm.Show()
         

Modified: grass/branches/releasebranch_7_0/scripts/Makefile
===================================================================
--- grass/branches/releasebranch_7_0/scripts/Makefile	2014-10-26 23:49:40 UTC (rev 62393)
+++ grass/branches/releasebranch_7_0/scripts/Makefile	2014-10-26 23:53:27 UTC (rev 62394)
@@ -3,6 +3,7 @@
 SUBDIRS = \
 	d.correlate \
 	d.out.file \
+	d.to.rast \
 	d.polar \
 	d.rast.edit \
 	d.rast.leg \



More information about the grass-commit mailing list