4 @brief Rendering map layers and overlays into map composition image.
12 (C) 2006-2013 by the GRASS Development Team
14 This program is free software under the GNU General Public License
15 (>=v2). Read the file COPYING that comes with GRASS for details.
17 @author Michael Barton
18 @author Jachym Cepicky
19 @author Martin Landa <landa.martin gmail.com>
31 from wx.lib.newevent
import NewEvent
35 from core
import utils
36 from core.gcmd import GException, GError, RunCommand
40 wxUpdateProgressBar, EVT_UPDATE_PRGBAR = NewEvent()
49 """!Virtual class which stores information about layers (map layers and
50 overlays) of the map composition.
52 For map layer use MapLayer class.
53 For overlays use Overlay class.
55 def __init__(self, type, cmd, name = None,
56 active =
True, hidden =
False, opacity = 1.0):
58 @todo pass cmd as tuple instead of list
60 @param type layer type ('raster', 'vector', 'overlay', 'command', etc.)
61 @param cmd GRASS command to render layer,
62 given as list, e.g. ['d.rast', 'map=elevation@PERMANENT']
63 @param name layer name, e.g. 'elevation@PERMANENT' (for layer tree)
64 @param active layer is active, will be rendered only if True
65 @param hidden layer is hidden, won't be listed in Layer Manager if True
66 @param opacity layer opacity <0;1>
71 if self.
type ==
'command':
84 Debug.msg (3,
"Layer.__init__(): type=%s, cmd='%s', name=%s, " \
85 "active=%d, opacity=%d, hidden=%d" % \
90 if self.
type ==
'overlay':
94 mapfile = tempfile.NamedTemporaryFile(suffix=tempfile_sfx, delete=
False)
99 self.
maskfile = self.mapfile.rsplit(
".",1)[0] +
".pgm"
102 Debug.msg (3,
"Layer.__del__(): layer=%s, cmd='%s'" %
106 """!Render layer to image
108 @return rendered image filename
109 @return None on error
115 if self.
type ==
'3d-raster':
118 Debug.msg (3,
"Layer.Render(): type=%s, name=%s" % \
122 layertypes = (
'raster',
'rgb',
'his',
'shaded',
'rastarrow',
'rastnum',
123 'vector',
'thememap',
'themechart',
124 'grid',
'geodesic',
'rhumb',
'labels',
125 'command',
'rastleg',
128 if self.
type not in layertypes:
129 raise GException(_(
"<%(name)s>: layer type <%(type)s> is not supported") % \
130 {
'type' : self.
type,
'name' : self.
name})
134 if self.
type ==
'overlay':
138 mapfile = tempfile.NamedTemporaryFile(suffix=tempfile_sfx, delete=
False)
142 self.
maskfile = self.mapfile.rsplit(
".",1)[0] +
".pgm"
144 if UserSettings.Get(group=
'display', key=
'driver', subkey=
'type') ==
'cairo':
146 os.environ[
"GRASS_CAIROFILE"] = self.
mapfile
154 os.environ[
"GRASS_PNGFILE"] = self.
mapfile
158 if self.
type ==
'command':
168 os.environ[
"GRASS_PNG_READ"] =
"TRUE"
170 os.environ[
"GRASS_PNG_READ"] =
"FALSE"
178 sys.stderr.write(_(
"Command '%s' failed\n") % self.
GetCmd(string =
True))
180 sys.stderr.write(_(
"Details: %s\n") % msg)
188 os.remove(self.gtemp)
189 except (OSError, TypeError):
195 if UserSettings.Get(group=
'display', key=
'driver', subkey=
'type') ==
'cairo':
202 del os.environ[
"GRASS_CAIROFILE"]
204 elif "GRASS_PNGFILE" in os.environ:
205 del os.environ[
"GRASS_PNGFILE"]
212 """!Get GRASS command as list of string.
214 @param string get command as string if True otherwise as list
216 @return command list/string
219 if self.
type ==
'command':
224 return ';'.join(scmd)
231 """!Get map layer type"""
235 """!Get map element type"""
236 if self.
type ==
'raster':
242 Get layer opacity level
244 @param float get opacity level in <0,1> otherwise <0,100>
246 @return opacity level
251 return int (self.
opacity * 100)
254 """!Get map layer name
256 @param fullyQualified True to return fully qualified name as a
257 string 'name@mapset' otherwise directory { 'name', 'mapset' }
260 @return string / directory
266 return {
'name' : self.name.split(
'@')[0],
267 'mapset' : self.name.split(
'@')[1] }
269 return {
'name' : self.
name,
273 """!Check if layer is activated for rendering"""
277 """!Set layer type"""
278 if type
not in (
'raster',
'3d-raster',
'vector',
279 'overlay',
'command',
280 'shaded',
'rgb',
'his',
'rastarrow',
'rastnum',
281 'thememap',
'themechart',
'grid',
'labels',
283 raise GException(_(
"Unsupported map layer type '%s'") % type)
288 """!Set layer name"""
292 """!Active or deactive layer"""
293 self.
active = bool(enable)
296 """!Hide or show map layer in Layer Manager"""
297 self.
hidden = bool(enable)
300 """!Set opacity value"""
309 """!Set new command for layer"""
310 if self.
type ==
'command':
316 Debug.msg(3,
"Layer.SetCmd(): cmd='%s'" % self.
GetCmd(string =
True))
322 def __init__(self, type, cmd, name = None,
323 active =
True, hidden =
False, opacity = 1.0):
324 """!Represents map layer in the map canvas
326 @param type layer type ('raster', 'vector', 'command', etc.)
327 @param cmd GRASS command to render layer,
328 given as list, e.g. ['d.rast', 'map=elevation@PERMANENT']
329 @param name layer name, e.g. 'elevation@PERMANENT' (for layer tree) or None
330 @param active layer is active, will be rendered only if True
331 @param hidden layer is hidden, won't be listed in Layer Manager if True
332 @param opacity layer opacity <0;1>
334 Layer.__init__(self, type, cmd, name,
335 active, hidden, opacity)
338 """!Get mapset of map layer
341 @return '' on error (no name given)
347 return self.name.split(
'@')[1]
353 active =
True, hidden =
True, opacity = 1.0):
354 """!Represents overlay displayed in map canvas
356 @param id overlay id (for PseudoDC)
357 @param type overlay type ('barscale', 'legend', etc.)
358 @param cmd GRASS command to render overlay,
359 given as list, e.g. ['d.legend', 'map=elevation@PERMANENT']
360 @param active layer is active, will be rendered only if True
361 @param hidden layer is hidden, won't be listed in Layer Manager if True
362 @param opacity layer opacity <0;1>
364 Layer.__init__(self,
'overlay', cmd, type,
365 active, hidden, opacity)
370 """!Map composition (stack of map layers and overlays)
392 mapfile = tempfile.NamedTemporaryFile(suffix=
'.ppm', delete=
False)
401 os.environ[
"GRASS_TRANSPARENT"] =
"TRUE"
402 os.environ[
"GRASS_BACKGROUNDCOLOR"] =
"ffffff"
407 def _runCommand(self, cmd, **kwargs):
408 """!Run command in environment defined by self.gisrc if
411 gisrc_orig = os.getenv(
"GISRC")
413 os.environ[
"GISRC"] = self.
gisrc
419 os.environ[
"GISRC"] = gisrc_orig
423 def _initGisEnv(self):
424 """!Stores GRASS variables (g.gisenv) to self.env variable
426 if not os.getenv(
"GISBASE"):
427 sys.exit(_(
"GISBASE not set. You must be in GRASS GIS to run this program."))
432 """!Get projection info"""
436 """!Return region projection and map units information
439 if not grass.find_program(
'g.proj', [
'--help']):
440 sys.exit(_(
"GRASS module '%s' not found. Unable to start map "
441 "display window.") %
'g.proj')
443 ret = self.
_runCommand(RunCommand, prog =
'g.proj',
444 read =
True, flags =
'p')
449 for line
in ret.splitlines():
451 key, val = map(
lambda x: x.strip(), line.split(
':'))
455 elif "XY location (unprojected)" in line:
456 projinfo[
'proj'] =
'xy'
457 projinfo[
'units'] =
''
463 """!Read WIND file and set up self.wind dictionary"""
465 filename = os.path.join (self.
env[
'GISDBASE'],
466 self.
env[
'LOCATION_NAME'],
470 windfile = open (filename,
"r")
472 sys.exit(_(
"Error: Unable to open '%(file)s'. Reason: %(ret)s. wxGUI exited.\n") % \
473 {
'file' : filename,
'ret' : e})
475 for line
in windfile.readlines():
477 key, value = line.split(
":", 1)
478 self.
wind[key.strip()] = value.strip()
485 """!Adjusts display resolution to match monitor size in
486 pixels. Maintains constant display resolution, not related to
487 computational region. Do NOT use the display resolution to set
488 computational resolution. Set computational resolution through
500 Debug.msg (3,
"Map.AdjustRegion(): %s" % self.
region)
505 """!Sets display extents to even multiple of current
506 resolution defined in WIND file from SW corner. This must be
507 done manually as using the -a flag can produce incorrect
520 n = float(self.
region[
'n'])
521 s = float(self.
region[
's'])
522 e = float(self.
region[
'e'])
523 w = float(self.
region[
'w'])
526 new[
'rows'] = math.fabs(
round((n-s)/nsres))
527 new[
'cols'] = math.fabs(
round((e-w)/ewres))
530 new[
's'] = nsres *
round(s / nsres)
531 new[
'w'] = ewres *
round(w / ewres)
532 new[
'n'] = new[
's'] + (new[
'rows'] * nsres)
533 new[
'e'] = new[
'w'] + (new[
'cols'] * ewres)
538 """!Align region extent based on display size from center
542 res = self.
region[
"ewres"]
544 res = self.
region[
"nsres"]
546 Debug.msg(3,
"Map.AlignExtentFromDisplay(): width=%d, height=%d, res=%f, center=%f,%f" % \
548 self.
region[
'center_northing']))
550 ew = (self.
width / 2) * res
551 ns = (self.
height / 2) * res
564 """!Change size of rendered map.
566 @param width,height map size given as tuple
568 @return True on success
569 @return False on failure
572 self.
width = int(width)
576 sys.stderr.write(_(
"Invalid map size %d,%d\n") % (self.
width, self.
height))
582 Debug.msg(2,
"Map.ChangeMapSize(): width=%d, height=%d" % \
585 def GetRegion(self, rast = [], zoom = False, vect = [], regionName = None,
586 n =
None, s =
None, e =
None, w =
None, default =
False,
588 """!Get region settings (g.region -upgc)
590 Optionally extent, raster or vector map layer can be given.
592 @param rast list of raster maps
593 @param zoom zoom to raster map (ignore NULLs)
594 @param vect list of vector maps
595 @param regionName named region or None
596 @param n,s,e,w force extent
597 @param default force default region settings
598 @param update if True update current display region settings
600 @return region settings as directory, e.g. {
601 'n':'4928010', 's':'4913700', 'w':'589980',...}
603 @see GetCurrentRegion()
607 tmpreg = os.getenv(
"GRASS_REGION")
609 del os.environ[
"GRASS_REGION"]
612 gisrc_orig = os.getenv(
"GISRC")
614 os.environ[
"GISRC"] = self.
gisrc
618 cmd[
'flags'] =
'ugpc'
624 cmd[
'region'] = regionName
637 cmd[
'zoom'] = rast[0]
639 cmd[
'rast'] =
','.join(rast)
642 cmd[
'vect'] =
','.join(vect)
651 message = _(
"Unable to zoom to raster map <%s>.") % rast[0] + \
652 "\n\n" + _(
"Details:") +
" %s" % msg
654 message = _(
"Unable to zoom to vector map <%s>.") % vect[0] + \
655 "\n\n" + _(
"Details:") +
" %s" % msg
657 message = _(
"Unable to get current geographic extent. "
658 "Force quiting wxGUI. Please manually run g.region to "
663 for r
in reg.splitlines():
664 key, val = r.split(
"=", 1)
666 region[key] = float(val)
672 os.environ[
"GISRC"] = gisrc_orig
676 os.environ[
"GRASS_REGION"] = tmpreg
678 Debug.msg (3,
"Map.GetRegion(): %s" % region)
686 """!Get current display region settings
693 """!Render string for GRASS_REGION env. variable, so that the
694 images will be rendered from desired zoom level.
696 @param windres uses resolution from WIND file rather than
697 display (for modules that require set resolution like
700 @return String usable for GRASS_REGION variable or None
706 region = copy.copy(self.
region)
707 for key
in (
'nsres',
'ewres',
'cells'):
708 region[key] = compRegion[key]
715 for key
in self.wind.keys():
717 grass_region +=
"north: %s; " % \
721 grass_region +=
"south: %s; " % \
725 grass_region +=
"east: %s; " % \
729 grass_region +=
"west: %s; " % \
732 elif key ==
"e-w resol":
733 grass_region +=
"e-w resol: %f; " % \
736 elif key ==
"n-s resol":
737 grass_region +=
"n-s resol: %f; " % \
743 grass_region +=
'cols: %d; ' % \
749 grass_region +=
'rows: %d; ' % \
753 grass_region += key +
": " + self.
wind[key] +
"; "
755 Debug.msg (3,
"Map.SetRegion(): %s" % grass_region)
762 def GetListOfLayers(self, l_type = None, l_mapset = None, l_name = None,
763 l_active =
None, l_hidden =
None):
764 """!Returns list of layers of selected properties or list of
767 @param l_type layer type, e.g. raster/vector/wms/overlay (value or tuple of values)
768 @param l_mapset all layers from given mapset (only for maplayers)
769 @param l_name all layers with given name
770 @param l_active only layers with 'active' attribute set to True or False
771 @param l_hidden only layers with 'hidden' attribute set to True or False
773 @return list of selected layers
777 if type(l_type) == types.StringType:
782 if one_type
and l_type ==
'overlay':
791 if one_type
and layer.type != l_type:
793 elif not one_type
and layer.type
not in l_type:
797 if (l_mapset !=
None and l_type !=
'overlay')
and \
798 layer.GetMapset() != l_mapset:
802 if l_name !=
None and layer.name != l_name:
806 if l_active !=
None and \
808 if layer.active == l_active
and \
809 layer.hidden == l_hidden:
810 selected.append(layer)
813 elif l_active !=
None:
814 if layer.active == l_active:
815 selected.append(layer)
818 elif l_hidden !=
None:
819 if layer.hidden == l_hidden:
820 selected.append(layer)
824 selected.append(layer)
826 Debug.msg (3,
"Map.GetListOfLayers(): numberof=%d" % len(selected))
830 def _renderLayers(self, force, mapWindow, maps, masks, opacities):
835 if layer ==
None or layer.active ==
False:
840 layer.force_render
or \
841 layer.mapfile ==
None or \
842 (
not os.path.isfile(layer.mapfile)
or not os.path.getsize(layer.mapfile)):
843 if not layer.Render():
849 event = wxUpdateProgressBar(value = ilayer)
850 wx.PostEvent(mapWindow, event)
853 if layer.type !=
"overlay":
854 maps.append(layer.mapfile)
855 masks.append(layer.maskfile)
856 opacities.append(str(layer.opacity))
858 Debug.msg (3,
"Map.Render() type=%s, layer=%s " % (layer.type, layer.name))
861 def Render(self, force = False, mapWindow = None, windres = False):
862 """!Creates final image composite
864 This function can conditionaly use high-level tools, which
865 should be avaliable in wxPython library
867 @param force force rendering
868 @param reference for MapFrame instance (for progress bar)
869 @param windres use region resolution (True) otherwise display resolution
871 @return name of file with rendered image or None
879 gisrc_orig = os.getenv(
"GISRC")
881 os.environ[
"GISRC"] = self.
gisrc
883 tmp_region = os.getenv(
"GRASS_REGION")
884 os.environ[
"GRASS_REGION"] = self.
SetRegion(windres)
885 os.environ[
"GRASS_WIDTH"] = str(self.
width)
886 os.environ[
"GRASS_HEIGHT"] = str(self.
height)
887 if UserSettings.Get(group=
'display', key=
'driver', subkey=
'type') ==
'cairo':
888 os.environ[
"GRASS_AUTO_WRITE"] =
"TRUE"
890 if "GRASS_RENDER_IMMEDIATE" in os.environ:
891 del os.environ[
"GRASS_RENDER_IMMEDIATE"]
893 os.environ[
"GRASS_PNG_AUTO_WRITE"] =
"TRUE"
894 os.environ[
"GRASS_PNG_READ"] =
"FALSE"
895 os.environ[
"GRASS_PNG_COMPRESSION"] =
"0"
896 os.environ[
"GRASS_TRUECOLOR"] =
"TRUE"
897 os.environ[
"GRASS_RENDER_IMMEDIATE"] =
"TRUE"
902 if sys.platform !=
'win32':
903 mapstr =
",".join(maps)
904 maskstr =
",".join(masks)
909 mapstr += item.replace(
'\\',
'/')
910 mapstr = mapstr.rstrip(
',')
913 maskstr += item.replace(
'\\',
'/')
914 maskstr = maskstr.rstrip(
',')
915 mapoutstr = self.mapfile.replace(
'\\',
'/')
918 bgcolor =
':'.join(map(str, UserSettings.Get(group =
'display', key =
'bgcolor',
923 os.environ[
"GRASS_REGION"] = tmp_region
925 del os.environ[
"GRASS_REGION"]
931 input =
'%s' %
",".join(maps),
932 mask =
'%s' %
",".join(masks),
933 opacity =
'%s' %
",".join(opacities),
934 background = bgcolor,
940 print >> sys.stderr, _(
"ERROR: Rendering failed. Details: %s") % msg
944 Debug.msg (3,
"Map.Render() force=%s file=%s" % (force, self.
mapfile))
948 os.environ[
"GISRC"] = gisrc_orig
956 def AddLayer(self, type, command, name = None,
957 l_active =
True, l_hidden =
False, l_opacity = 1.0, l_render =
False,
959 """!Adds generic map layer to list of layers
961 @param type layer type ('raster', 'vector', etc.)
962 @param command GRASS command given as list
963 @param name layer name
964 @param l_active layer render only if True
965 @param l_hidden layer not displayed in layer tree if True
966 @param l_opacity opacity level range from 0(transparent) - 1(not transparent)
967 @param l_render render an image if True
968 @param pos position in layer list (-1 for append)
970 @return new layer on success
971 @return None on failure
975 if l_opacity < 0: l_opacity = 0
976 elif l_opacity > 1: l_opacity = 1
977 layer =
MapLayer(type = type, name = name, cmd = command,
978 active = l_active, hidden = l_hidden, opacity = l_opacity)
982 self.layers.insert(pos, layer)
984 self.layers.append(layer)
986 Debug.msg (3,
"Map.AddLayer(): layer=%s" % layer.name)
988 if not layer.Render():
989 raise GException(_(
"Unable to render map layer <%s>.") % name)
996 """!Removes layer from list of layers
998 @param layer layer instance in layer tree
999 @param overlay delete overlay (use self.DeleteOverlay() instead)
1001 @return removed layer on success or None
1003 Debug.msg (3,
"Map.DeleteLayer(): name=%s" % layer.name)
1012 base = os.path.split(layer.mapfile)[0]
1013 mapfile = os.path.split(layer.mapfile)[1]
1014 tempbase = mapfile.split(
'.')[0]
1015 if base ==
'' or tempbase ==
'':
1017 basefile = os.path.join(base, tempbase) +
r'.*'
1018 for f
in glob.glob(basefile):
1027 """!Reorder list to match layer tree
1029 @param layerList list of layers
1034 for layer
in self.
layers:
1036 layerNameList += layer.name +
','
1037 Debug.msg (4,
"Map.ReoderLayers(): layers=%s" % \
1041 """!Change map layer properties
1043 @param layer map layer instance
1044 @param type layer type ('raster', 'vector', etc.)
1045 @param command GRASS command given as list
1046 @param name layer name
1047 @param active layer render only if True
1048 @param hidden layer not displayed in layer tree if True
1049 @param opacity opacity level range from 0(transparent) - 1(not transparent)
1050 @param render render an image if True
1052 Debug.msg (3,
"Map.ChangeLayer(): layer=%s" % layer.name)
1055 layer.SetType(kargs[
'type'])
1057 if 'command' in kargs:
1058 layer.SetCmd(kargs[
'command'])
1061 layer.SetName(kargs[
'name'])
1063 if 'active' in kargs:
1064 layer.SetActive(kargs[
'active'])
1066 if 'hidden' in kargs:
1067 layer.SetHidden(kargs[
'hidden'])
1069 if 'opacity' in kargs:
1070 layer.SetOpacity(kargs[
'opacity'])
1072 if render
and not layer.Render():
1073 raise GException(_(
"Unable to render map layer <%s>.") %
1079 """!Changes opacity value of map layer
1081 @param layer layer instance in layer tree
1082 @param l_opacity opacity level <0;1>
1085 if l_opacity < 0: l_opacity = 0
1086 elif l_opacity > 1: l_opacity = 1
1088 layer.opacity = l_opacity
1089 Debug.msg (3,
"Map.ChangeOpacity(): layer=%s, opacity=%f" % \
1090 (layer.name, layer.opacity))
1093 """!Enable or disable map layer
1095 @param layer layer instance in layer tree
1096 @param active to be rendered (True)
1098 layer.active = active
1100 Debug.msg (3,
"Map.ChangeLayerActive(): name='%s' -> active=%d" % \
1101 (layer.name, layer.active))
1104 """!Change name of the layer
1106 @param layer layer instance in layer tree
1107 @param name layer name to set up
1109 Debug.msg (3,
"Map.ChangeLayerName(): from=%s to=%s" % \
1114 """!Removes layer from layer list
1116 Layer is defined by name@mapset or id.
1118 @param name layer name (must be unique)
1119 @param id layer index in layer list
1121 @return removed layer on success
1122 @return None on failure
1127 for layer
in self.
layers:
1128 if layer.name == name:
1130 os.remove(layer.mapfile)
1131 os.remove(layer.maskfile)
1132 self.layers.remove(layer)
1136 return self.layers.pop(id)
1141 """!Get index of layer in layer list.
1143 @param layer layer instace in layer tree
1144 @param overlay use list of overlays instead
1147 @return -1 if layer not found
1155 return list.index(layer)
1160 l_active =
True, l_hidden =
True, l_opacity = 1.0, l_render =
False):
1161 """!Adds overlay (grid, barscale, legend, etc.) to list of
1164 @param id overlay id (PseudoDC)
1165 @param type overlay type (barscale, legend)
1166 @param command GRASS command to render overlay
1167 @param l_active overlay activated (True) or disabled (False)
1168 @param l_hidden overlay is not shown in layer tree (if True)
1169 @param l_render render an image (if True)
1171 @return new layer on success
1172 @retutn None on failure
1174 Debug.msg (2,
"Map.AddOverlay(): cmd=%s, render=%d" % (command, l_render))
1175 overlay =
Overlay(id = id, type = type, cmd = command,
1176 active = l_active, hidden = l_hidden, opacity = l_opacity)
1179 self.overlays.append(overlay)
1181 if l_render
and command !=
'' and not overlay.Render():
1182 raise GException(_(
"Unable to render overlay <%s>.") %
1188 """!Change overlay properities
1190 Add new overlay if overlay with 'id' doesn't exist.
1192 @param id overlay id (PseudoDC)
1193 @param type overlay type (barscale, legend)
1194 @param command GRASS command to render overlay
1195 @param l_active overlay activated (True) or disabled (False)
1196 @param l_hidden overlay is not shown in layer tree (if True)
1197 @param l_render render an image (if True)
1199 @return new layer on success
1203 overlay =
Overlay(id, type =
None, cmd =
None)
1206 overlay.SetName(kargs[
'type'])
1208 if 'command' in kargs:
1209 overlay.SetCmd(kargs[
'command'])
1211 if 'active' in kargs:
1212 overlay.SetActive(kargs[
'active'])
1214 if 'hidden' in kargs:
1215 overlay.SetHidden(kargs[
'hidden'])
1217 if 'opacity' in kargs:
1218 overlay.SetOpacity(kargs[
'opacity'])
1220 if render
and overlay.GetCmd() != []
and not overlay.Render():
1221 raise GException(_(
"Unable to render overlay <%s>.") %
1227 """!Return overlay(s) with 'id'
1229 @param id overlay id
1230 @param list return list of overlays of True
1231 otherwise suppose 'id' to be unique
1233 @return list of overlays (list=True)
1234 @return overlay (list=False)
1235 @retur None (list=False) if no overlay or more overlays found
1239 if overlay.id == id:
1253 @param overlay overlay layer
1255 @return removed overlay on success or None
1260 """!Clean layer stack - go trough all layers and remove them
1263 Removes also l_mapfile and l_maskfile
1265 @return False on failure
1266 @return True on success
1269 dir = os.path.dirname(self.
mapfile)
1271 removepath = os.path.join(dir,base)+
r'*'
1272 for f
in glob.glob(removepath):
1274 for layer
in self.
layers:
1276 dir = os.path.dirname(layer.mapfile)
1277 base = os.path.basename(layer.mapfile).
split(
'.')[0]
1278 removepath = os.path.join(dir,base)+
r'*'
1279 for f
in glob.glob(removepath):
1281 self.layers.remove(layer)
1285 dir = os.path.dirname(overlay.mapfile)
1286 base = os.path.basename(overlay.mapfile).
split(
'.')[0]
1287 removepath = os.path.join(dir,base)+
r'*'
1288 for f
in glob.glob(removepath):
1290 self.overlays.remove(overlay)
1297 """!Reverse list of layers"""
1298 return self.layers.reverse()
1301 """!Render overlays only (for nviz)"""
1303 if force
or layer.force_render:
1306 if __name__ ==
"__main__":
1308 gettext.install(
'grasswxpy', os.path.join(os.getenv(
"GISBASE"),
'locale'), unicode =
True)
1311 Map.GetRegion(update =
True)
1313 Map.AddLayer(type =
"raster",
1315 command = [
"d.rast",
"map=elevation@PERMANENT"],
1318 Map.AddLayer(type =
"vector",
1319 name =
"roadsmajor",
1320 command = [
"d.vect",
"map=roadsmajor@PERMANENT",
"color=red",
"width=3",
"type=line"])
1322 image = Map.Render(force =
True)
1325 grass.call([
"display", image])
def AlignResolution
Sets display extents to even multiple of current resolution defined in WIND file from SW corner...
def CmdToTuple
Convert command list to tuple for gcmd.RunCommand()
def GetElement
Get map element type.
Virtual class which stores information about layers (map layers and overlays) of the map composition...
def GetCurrentRegion
Get current display region settings.
def ChangeLayerActive
Enable or disable map layer.
def GetProjInfo
Get projection info.
def _initGisEnv
Stores GRASS variables (g.gisenv) to self.env variable.
def SetHidden
Hide or show map layer in Layer Manager.
def Render
Render layer to image.
def DeleteLayer
Removes layer from list of layers.
def RenderOverlays
Render overlays only (for nviz)
def AdjustRegion
Adjusts display resolution to match monitor size in pixels.
def ReverseListOfLayers
Reverse list of layers.
def GetOverlay
Return overlay(s) with 'id'.
def AddLayer
Adds generic map layer to list of layers.
def ChangeLayer
Change map layer properties.
def ChangeLayerName
Change name of the layer.
def GetName
Get map layer name.
def _projInfo
Return region projection and map units information.
def DeleteOverlay
Delete overlay.
def AddOverlay
Adds overlay (grid, barscale, legend, etc.) to list of overlays.
def Clean
Clean layer stack - go trough all layers and remove them from layer list.
def _runCommand
Run command in environment defined by self.gisrc if defined.
def GetWindow
Read WIND file and set up self.wind dictionary.
def split
Platform spefic shlex.split.
def Render
Creates final image composite.
def GetCmd
Get GRASS command as list of string.
def ReorderLayers
Reorder list to match layer tree.
def IsActive
Check if layer is activated for rendering.
def ChangeMapSize
Change size of rendered map.
def AlignExtentFromDisplay
Align region extent based on display size from center point.
def GetType
Get map layer type.
def __init__
Represents overlay displayed in map canvas.
def GetMapset
Get mapset of map layer.
def SetCmd
Set new command for layer.
def SetName
Set layer name.
def GetLayerIndex
Get index of layer in layer list.
Map composition (stack of map layers and overlays)
def ChangeOverlay
Change overlay properities.
def ChangeOpacity
Changes opacity value of map layer.
def RemoveLayer
Removes layer from layer list.
def SetType
Set layer type.
def SetActive
Active or deactive layer.
def GetRegion
Get region settings (g.region -upgc)
def SetRegion
Render string for GRASS_REGION env.
def __init__
Represents map layer in the map canvas.
def GetListOfLayers
Returns list of layers of selected properties or list of all layers.
def RunCommand
Run GRASS command.
def SetOpacity
Set opacity value.