Example #1
0
    def __init__(self,
                 ltype,
                 cmd,
                 Map,
                 name=None,
                 active=True,
                 hidden=False,
                 opacity=1.0):
        """!Create new instance

        @todo pass cmd as tuple instead of list

        @param ltype layer type ('raster', 'vector', 'overlay', 'command', etc.)
        @param cmd GRASS command to render layer,
        given as list, e.g. ['d.rast', 'map=elevation@PERMANENT']
        @param Map render.Map instance
        @param name layer name, e.g. 'elevation@PERMANENT' (for layer tree)
        @param active layer is active, will be rendered only if True
        @param hidden layer is hidden, won't be listed in Layer Manager if True
        @param opacity layer opacity <0;1>
        """

        # generated file for each layer
        if USE_GPNMCOMP or ltype == 'overlay':
            tmpfile = tempfile.mkstemp()[1]
            self.maskfile = tmpfile + '.pgm'
            if ltype == 'overlay':
                self.mapfile = tmpfile + '.png'
            else:
                self.mapfile = tmpfile + '.ppm'
            grass.try_remove(tmpfile)
        else:
            self.mapfile = self.maskfile = None

        # stores class which manages rendering instead of simple command - e. g. wms
        self.renderMgr = None

        self.Map = Map
        self.type = None
        self.SetType(ltype)
        self.name = name

        if self.type == 'command':
            self.cmd = list()
            for c in cmd:
                self.cmd.append(utils.CmdToTuple(c))
        else:
            self.cmd = utils.CmdToTuple(cmd)

        self.active = active
        self.hidden = hidden
        self.opacity = opacity

        self.forceRender = True

        Debug.msg(
            3, "Layer.__init__(): type=%s, cmd='%s', name=%s, "
            "active=%d, opacity=%d, hidden=%d" %
            (self.type, self.GetCmd(string=True), self.name, self.active,
             self.opacity, self.hidden))
Example #2
0
    def __init__(self, ltype, cmd, Map, name=None,
                 active=True, hidden=False, opacity=1.0):
        """Create new instance

        .. todo::

            pass cmd as tuple instead of list

        :param ltype: layer type ('raster', 'vector', 'overlay', 'command', etc.)
        :param cmd: GRASS command to render layer, given as list,
                    e.g. ['d.rast', 'map=elevation@PERMANENT']
        :param map: render.Map instance
        :param name: layer name, e.g. 'elevation@PERMANENT' (for layer tree)
        :param active: layer is active, will be rendered only if True
        :param hidden: layer is hidden, won't be listed in Layer Manager if True
        :param float opacity: layer opacity <0;1>
        """

        # generated file for each layer
        if USE_GPNMCOMP or ltype == 'overlay':
            if ltype == 'overlay':
                tempfile_sfx = ".png"
            else:
                tempfile_sfx = ".ppm"

            mapfile = tempfile.NamedTemporaryFile(suffix=tempfile_sfx, delete=False)
            # we don't want it open, we just need the name
            self.mapfile = mapfile.name
            mapfile.close()
            self.maskfile = self.mapfile.rsplit(".",1)[0] + ".pgm"
        else:
            self.mapfile = self.maskfile = None

        # stores class which manages rendering instead of simple command - e.g. WMS
        self.renderMgr = None

        self.Map = Map
        self.type = None
        self.SetType(ltype)
        self.name = name
        self.environ = os.environ.copy()

        if self.type == 'command':
            self.cmd = list()
            for c in cmd:
                self.cmd.append(utils.CmdToTuple(c))
        else:
            self.cmd = utils.CmdToTuple(cmd)

        self.active  = active
        self.hidden  = hidden
        self.opacity = opacity

        self.forceRender = True

        Debug.msg (3, "Layer.__init__(): type=%s, cmd='%s', name=%s, " \
                       "active=%d, opacity=%d, hidden=%d" % \
                       (self.type, self.GetCmd(string=True), self.name,
                        self.active, self.opacity, self.hidden))
Example #3
0
    def SetCmd(self, cmd):
        """!Set new command for layer"""
        if self.type == 'command':
            self.cmd = []
            for c in cmd:
                self.cmd.append(utils.CmdToTuple(c))
        else:
            self.cmd = utils.CmdToTuple(cmd)
        Debug.msg(3, "Layer.SetCmd(): cmd='%s'" % self.GetCmd(string=True))

        # for re-rendering
        self.force_render = True
Example #4
0
    def __init__(self,
                 type,
                 cmd,
                 name=None,
                 active=True,
                 hidden=False,
                 opacity=1.0):
        """!
        @todo pass cmd as tuple instead of list
        
        @param type layer type ('raster', 'vector', 'overlay', 'command', etc.)
        @param cmd GRASS command to render layer,
        given as list, e.g. ['d.rast', 'map=elevation@PERMANENT']
        @param name layer name, e.g. 'elevation@PERMANENT' (for layer tree)
        @param active layer is active, will be rendered only if True
        @param hidden layer is hidden, won't be listed in Layer Manager if True
        @param opacity layer opacity <0;1>
        """
        self.type = type
        self.name = name

        if self.type == 'command':
            self.cmd = list()
            for c in cmd:
                self.cmd.append(utils.CmdToTuple(c))
        else:
            self.cmd = utils.CmdToTuple(cmd)

        self.active = active
        self.hidden = hidden
        self.opacity = opacity

        self.force_render = True

        Debug.msg (3, "Layer.__init__(): type=%s, cmd='%s', name=%s, " \
                       "active=%d, opacity=%d, hidden=%d" % \
                       (self.type, self.GetCmd(string = True), self.name, self.active,
                        self.opacity, self.hidden))

        # generated file for each layer
        if self.type == 'overlay':
            tempfile_sfx = ".png"
        else:
            tempfile_sfx = ".ppm"
        mapfile = tempfile.NamedTemporaryFile(suffix=tempfile_sfx,
                                              delete=False)
        # we don't want it open, we just need the name
        self.mapfile = mapfile.name
        mapfile.close()
        # do we need to `touch` the maskfile so it exists?
        self.maskfile = self.mapfile.rsplit(".", 1)[0] + ".pgm"
Example #5
0
    def SaveTmpLayer(self, layer_name):
        """Permanently saves temporary map of analysis result"""
        msg = _("Vector map with analysis result does not exist.")

        if not hasattr(self.results["vect_map"], "GetVectMapName"):
            GMessage(parent=self.guiparent, message=msg)
            return

        mapToAdd = self.results["vect_map"].GetVectMapName()
        mapToAddEx = grass.find_file(name=mapToAdd,
                                     element='vector',
                                     mapset=grass.gisenv()['MAPSET'])

        if not mapToAddEx["name"]:
            GMessage(parent=self.guiparent, message=msg)
            return

        addedMap = layer_name
        mapName, mapSet = ParseMapStr(addedMap)
        if mapSet != grass.gisenv()['MAPSET']:
            GMessage(
                parent=self.guiparent,
                message=_("Map can be saved only to currently set mapset"))
            return
        existsMap = grass.find_file(name=mapName,
                                    element='vector',
                                    mapset=grass.gisenv()['MAPSET'])
        if existsMap["name"]:
            dlg = wx.MessageDialog(parent=self.guiparent,
                                   message=_("Vector map %s already exists. " +
                                             "Do you want to overwrite it?") %
                                   (existsMap["fullname"]),
                                   caption=_("Overwrite vector map"),
                                   style=wx.YES_NO | wx.NO_DEFAULT
                                   | wx.ICON_QUESTION | wx.CENTRE)
            ret = dlg.ShowModal()
            if ret == wx.ID_NO:
                dlg.Destroy()
                return
            dlg.Destroy()

        RunCommand("g.copy",
                   overwrite=True,
                   vect=[self.results["vect_map"].GetVectMapName(), mapName])

        if len(self.giface.GetLayerList().GetLayersByName(mapName)) == 0:
            # TODO: get rid of insert
            cmd, cmd_colors = self.vnet_data.GetLayerStyle()
            cmd.insert(0, 'd.vect')
            cmd.append('map=%s' % mapName)

            self.giface.GetLayerList().AddLayer(ltype="vector",
                                                name=mapName,
                                                cmd=cmd,
                                                checked=True)
            if cmd_colors:
                layerStyleVnetColors = utils.CmdToTuple(cmd_colors)

                RunCommand(layerStyleVnetColors[0], **layerStyleVnetColors[1])
        else:
            self.giface.updateMap.emit(render=True, renderVector=True)