[GRASS-SVN] r60696 - in grass/trunk: gui/wxpython/mapdisp scripts scripts/d.what.rast scripts/d.what.vect
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jun 3 19:40:24 PDT 2014
Author: annakrat
Date: 2014-06-03 19:40:24 -0700 (Tue, 03 Jun 2014)
New Revision: 60696
Added:
grass/trunk/scripts/d.what.rast/
grass/trunk/scripts/d.what.rast/Makefile
grass/trunk/scripts/d.what.rast/d.what.rast.html
grass/trunk/scripts/d.what.rast/d.what.rast.py
grass/trunk/scripts/d.what.vect/
grass/trunk/scripts/d.what.vect/Makefile
grass/trunk/scripts/d.what.vect/d.what.vect.html
grass/trunk/scripts/d.what.vect/d.what.vect.py
Modified:
grass/trunk/gui/wxpython/mapdisp/frame.py
grass/trunk/gui/wxpython/mapdisp/main.py
Log:
d.mon: implement d.what.vect, d.what.rast
Modified: grass/trunk/gui/wxpython/mapdisp/frame.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/frame.py 2014-06-03 19:28:38 UTC (rev 60695)
+++ grass/trunk/gui/wxpython/mapdisp/frame.py 2014-06-04 02:40:24 UTC (rev 60696)
@@ -232,6 +232,10 @@
self.dialogs['vnet'] = None
self.dialogs['query'] = None
+ # initialize layers to query (d.what.vect/rast)
+ self._vectQueryLayers = []
+ self._rastQueryLayers = []
+
self.measureController = None
def GetMapWindow(self):
@@ -712,31 +716,35 @@
@param x,y coordinates
@param layers selected tree item layers
"""
- layers = self._giface.GetLayerList().GetSelectedLayers(checkedOnly=False)
- rast = []
- vect = []
- for layer in layers:
- name, found = GetLayerNameFromCmd(layer.cmd)
- if not found:
- continue
- ltype = layer.maplayer.GetType()
- if ltype == 'raster':
- rast.append(name)
- elif ltype in ('rgb', 'his'):
- for iname in name.split('\n'):
- rast.append(iname)
- elif ltype in ('vector', 'thememap', 'themechart'):
- vect.append(name)
- if vect:
- # check for vector maps open to be edited
- digitToolbar = self.GetToolbar('vdigit')
- if digitToolbar:
- lmap = digitToolbar.GetLayer().GetName()
- for name in vect:
- if lmap == name:
- self._giface.WriteWarning(_("Vector map <%s> "
- "opened for editing - skipped.") % lmap)
- vect.remove(name)
+ if self._vectQueryLayers or self._rastQueryLayers:
+ rast = self._rastQueryLayers
+ vect = self._vectQueryLayers
+ else:
+ layers = self._giface.GetLayerList().GetSelectedLayers(checkedOnly=False)
+ rast = []
+ vect = []
+ for layer in layers:
+ name, found = GetLayerNameFromCmd(layer.cmd)
+ if not found:
+ continue
+ ltype = layer.maplayer.GetType()
+ if ltype == 'raster':
+ rast.append(name)
+ elif ltype in ('rgb', 'his'):
+ for iname in name.split('\n'):
+ rast.append(iname)
+ elif ltype in ('vector', 'thememap', 'themechart'):
+ vect.append(name)
+ if vect:
+ # check for vector maps open to be edited
+ digitToolbar = self.GetToolbar('vdigit')
+ if digitToolbar:
+ lmap = digitToolbar.GetLayer().GetName()
+ for name in vect:
+ if lmap == name:
+ self._giface.WriteWarning(_("Vector map <%s> "
+ "opened for editing - skipped.") % lmap)
+ vect.remove(name)
if not (rast + vect):
GMessage(parent = self,
@@ -760,6 +768,15 @@
if vect:
self.QueryMap(east, north, qdist, rast = [], vect = vect)
+ def SetQueryLayersAndActivate(self, ltype, maps):
+ """!Activate query mode and set layers to query.
+ This method is used for querying in d.mon using d.what.rast/vect"""
+ self.toolbars['map'].SelectTool(self.toolbars['map'].query)
+ if ltype == 'vect':
+ self._vectQueryLayers = maps
+ elif ltype == 'rast':
+ self._rastQueryLayers = maps
+
def QueryMap(self, east, north, qdist, rast, vect):
"""!Query raster or vector map layers by r/v.what
@@ -798,6 +815,8 @@
def _oncloseQueryDialog(self, event):
self.dialogs['query'] = None
+ self._vectQueryLayers = []
+ self._rastQueryLayers = []
event.Skip()
def _onRedirectQueryOutput(self, output, style='log'):
Modified: grass/trunk/gui/wxpython/mapdisp/main.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/main.py 2014-06-03 19:28:38 UTC (rev 60695)
+++ grass/trunk/gui/wxpython/mapdisp/main.py 2014-06-04 02:40:24 UTC (rev 60696)
@@ -81,6 +81,8 @@
self.mapfile = monFile['map'] + '.ppm'
# signal sent when d.out.file appears in cmd file, attribute is cmd
self.saveToFile = Signal('DMonMap.saveToFile')
+ # signal sent when d.what.rast/vect appears in cmd file, attribute is cmd
+ self.query = Signal('DMonMap.query')
def GetLayersFromCmdFile(self):
"""!Get list of map layers from cmdfile
@@ -95,13 +97,25 @@
lines = fd.readlines()
fd.close()
# detect d.out.file, delete the line from the cmd file and export graphics
- if len(lines) > 0 and lines[-1].startswith('d.out.file'):
- dOutFileCmd = lines[-1].strip()
- fd = open(self.cmdfile, 'w')
- fd.writelines(lines[:-1])
- fd.close()
- self.saveToFile.emit(cmd=utils.split(dOutFileCmd))
- return
+ if len(lines) > 0:
+ if lines[-1].startswith('d.out.file'):
+ dOutFileCmd = lines[-1].strip()
+ fd = open(self.cmdfile, 'w')
+ fd.writelines(lines[:-1])
+ fd.close()
+ self.saveToFile.emit(cmd=utils.split(dOutFileCmd))
+ return
+ if lines[-1].startswith('d.what'):
+ dWhatCmd = lines[-1].strip()
+ fd = open(self.cmdfile, 'w')
+ fd.writelines(lines[:-1])
+ fd.close()
+ if '=' in utils.split(dWhatCmd)[1]:
+ maps = utils.split(dWhatCmd)[1].split('=')[1].split(',')
+ else:
+ maps = utils.split(dWhatCmd)[1].split(',')
+ self.query.emit(ltype=utils.split(dWhatCmd)[0].split('.')[-1], maps=maps)
+ return
existingLayers = self.GetListOfLayers()
@@ -345,6 +359,7 @@
# self.SetTopWindow(Map)
self.mapFrm.GetMapWindow().SetAlwaysRenderEnabled(True)
self.Map.saveToFile.connect(lambda cmd: self.mapFrm.DOutFile(cmd))
+ self.Map.query.connect(lambda ltype, maps: self.mapFrm.SetQueryLayersAndActivate(ltype=ltype, maps=maps))
self.mapFrm.Show()
if __name__ == "__main__":
Added: grass/trunk/scripts/d.what.rast/Makefile
===================================================================
--- grass/trunk/scripts/d.what.rast/Makefile (rev 0)
+++ grass/trunk/scripts/d.what.rast/Makefile 2014-06-04 02:40:24 UTC (rev 60696)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = d.what.rast
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script
Added: grass/trunk/scripts/d.what.rast/d.what.rast.html
===================================================================
--- grass/trunk/scripts/d.what.rast/d.what.rast.html (rev 0)
+++ grass/trunk/scripts/d.what.rast/d.what.rast.html 2014-06-04 02:40:24 UTC (rev 60696)
@@ -0,0 +1,22 @@
+<h2>DESCRIPTION</h2>
+
+<em>d.what.rast</em> d.what.rast outputs the category value(s)
+associated with user-specified location(s) in user-specified raster map layer(s).
+The active monitor can be selected with <em>d.mon</em>.
+
+<h2>SEE ALSO</h2>
+
+<em>
+ <a href="d.what.vect.html">d.what.vect</a>,
+ <a href="d.redraw.html">d.redraw</a>,
+ <a href="d.erase.html">d.erase</a>,
+ <a href="d.rast.html">d.rast</a>,
+ <a href="d.vect.html">d.vect</a>,
+ <a href="d.mon.html">d.mon</a>
+</em>
+
+<h2>AUTHOR</h2>
+
+Anna Petrasova, <a href="http://gis.ncsu.edu/osgeorel/">NCSU OSGeoREL</a>
+
+<p><i>Last changed: $Date: 2014-03-26 11:49:20 -0400 (Wed, 26 Mar 2014) $</i>
Added: grass/trunk/scripts/d.what.rast/d.what.rast.py
===================================================================
--- grass/trunk/scripts/d.what.rast/d.what.rast.py (rev 0)
+++ grass/trunk/scripts/d.what.rast/d.what.rast.py 2014-06-04 02:40:24 UTC (rev 60696)
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+############################################################################
+#
+# MODULE: d.what.rast
+# AUTHOR(S): Anna Petrasova <kratochanna gmail.com>
+# PURPOSE: Script for querying raster maps in d.mon
+# COPYRIGHT: (C) 2014 by the GRASS Development Team
+#
+# This program is free software under the GNU General
+# Public License (>=v2). Read the file COPYING that
+# comes with GRASS for details.
+#
+#############################################################################
+
+#%module
+#% description: Allows the user to interactively query raster map layers at user-selected locations.
+#% keywords: display
+#% keywords: vector
+#%end
+#%option G_OPT_R_INPUTS
+#% key: map
+#%end
+
+
+from grass.script import core as gcore
+
+
+def main():
+ options, flags = gcore.parser()
+ gisenv = gcore.gisenv()
+ if 'MONITOR' in gisenv:
+ cmd_file = gisenv['MONITOR_{monitor}_CMDFILE'.format(monitor=gisenv['MONITOR'].upper())]
+ dout_cmd = 'd.what.rast'
+ for param, val in options.iteritems():
+ if val:
+ dout_cmd += " {param}={val}".format(param=param, val=val)
+ with open(cmd_file, "a") as file_:
+ file_.write(dout_cmd)
+ else:
+ gcore.fatal(_("No graphics device selected. Use d.mon to select graphics device."))
+
+
+if __name__ == "__main__":
+ main()
Added: grass/trunk/scripts/d.what.vect/Makefile
===================================================================
--- grass/trunk/scripts/d.what.vect/Makefile (rev 0)
+++ grass/trunk/scripts/d.what.vect/Makefile 2014-06-04 02:40:24 UTC (rev 60696)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = d.what.vect
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script
Added: grass/trunk/scripts/d.what.vect/d.what.vect.html
===================================================================
--- grass/trunk/scripts/d.what.vect/d.what.vect.html (rev 0)
+++ grass/trunk/scripts/d.what.vect/d.what.vect.html 2014-06-04 02:40:24 UTC (rev 60696)
@@ -0,0 +1,22 @@
+<h2>DESCRIPTION</h2>
+
+<em>d.what.vect</em> d.what.vect outputs the category value(s)
+associated with user-specified location(s) in user-specified vector map layer(s).
+The active monitor can be selected with <em>d.mon</em>.
+
+<h2>SEE ALSO</h2>
+
+<em>
+ <a href="d.what.rast.html">d.what.rast</a>,
+ <a href="d.redraw.html">d.redraw</a>,
+ <a href="d.erase.html">d.erase</a>,
+ <a href="d.rast.html">d.rast</a>,
+ <a href="d.vect.html">d.vect</a>,
+ <a href="d.mon.html">d.mon</a>
+</em>
+
+<h2>AUTHOR</h2>
+
+Anna Petrasova, <a href="http://gis.ncsu.edu/osgeorel/">NCSU OSGeoREL</a>
+
+<p><i>Last changed: $Date: 2014-03-26 11:49:20 -0400 (Wed, 26 Mar 2014) $</i>
Added: grass/trunk/scripts/d.what.vect/d.what.vect.py
===================================================================
--- grass/trunk/scripts/d.what.vect/d.what.vect.py (rev 0)
+++ grass/trunk/scripts/d.what.vect/d.what.vect.py 2014-06-04 02:40:24 UTC (rev 60696)
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+############################################################################
+#
+# MODULE: d.what.vect
+# AUTHOR(S): Anna Petrasova <kratochanna gmail.com>
+# PURPOSE: Script for querying vector maps in d.mon
+# COPYRIGHT: (C) 2014 by the GRASS Development Team
+#
+# This program is free software under the GNU General
+# Public License (>=v2). Read the file COPYING that
+# comes with GRASS for details.
+#
+#############################################################################
+
+#%module
+#% description: Allows the user to interactively query vector map layers at user-selected locations.
+#% keywords: display
+#% keywords: vector
+#%end
+#%option G_OPT_V_INPUTS
+#% key: map
+#%end
+
+
+from grass.script import core as gcore
+
+
+def main():
+ options, flags = gcore.parser()
+ gisenv = gcore.gisenv()
+ if 'MONITOR' in gisenv:
+ cmd_file = gisenv['MONITOR_{monitor}_CMDFILE'.format(monitor=gisenv['MONITOR'].upper())]
+ dout_cmd = 'd.what.vect'
+ for param, val in options.iteritems():
+ if val:
+ dout_cmd += " {param}={val}".format(param=param, val=val)
+ with open(cmd_file, "a") as file_:
+ file_.write(dout_cmd)
+ else:
+ gcore.fatal(_("No graphics device selected. Use d.mon to select graphics device."))
+
+
+if __name__ == "__main__":
+ main()
More information about the grass-commit
mailing list