Exemple #1
0
def update_cmd_file(cmd_file, cmd, mapfile):
    if cmd[0] in (
            "d.colorlist",
            "d.font",
            "d.fontlist",
            "d.frame",
            "d.info",
            "d.mon",
            "d.out.file",
            "d.redraw",
            "d.to.rast",
            "d.what.rast",
            "d.what.vect",
            "d.where",
    ):
        return

    mode = "w" if cmd[0] == "d.erase" else "a"
    # update cmd file
    fd = open(cmd_file, mode)
    if fd is None:
        grass.fatal("Unable to open file '{0}'".format(cmd_file))
    if mode == "a":
        frame = os.getenv("GRASS_RENDER_FRAME", None)
        if frame:
            fd.write("# GRASS_RENDER_FRAME={0}\n".format(frame))
        if mapfile:
            fd.write("# GRASS_RENDER_FILE={0}\n".format(mapfile))
        fd.write(" ".join(gtask.cmdtuple_to_list(cmd)))
        fd.write("\n")
    else:
        fd.write("")
    fd.close()
Exemple #2
0
def GetCmdString(cmd):
    """Get GRASS command as string.

    :param cmd: GRASS command given as tuple

    :return: command string
    """
    return ' '.join(gtask.cmdtuple_to_list(cmd))
Exemple #3
0
def GetCmdString(cmd):
    """Get GRASS command as string.
    
    :param cmd: GRASS command given as tuple
    
    :return: command string
    """
    return ' '.join(gtask.cmdtuple_to_list(cmd))
Exemple #4
0
 def __getattr__(self, name):
     if name == 'cmd':
         return cmdtuple_to_list(self._maplayer.GetCmd())
     elif hasattr(self._maplayer, name):
         return getattr(self._maplayer, name)
     elif name == 'maplayer':
         return self._maplayer
     elif name == 'type':
         return self._maplayer.GetType()
         # elif name == 'ctrl':
     elif name == 'label':
         return self._maplayer.GetName()
Exemple #5
0
 def __getattr__(self, name):
     if name == "cmd":
         return cmdtuple_to_list(self._maplayer.GetCmd())
     elif hasattr(self._maplayer, name):
         return getattr(self._maplayer, name)
     elif name == "maplayer":
         return self._maplayer
     elif name == "type":
         return self._maplayer.GetType()
         # elif name == 'ctrl':
     elif name == "label":
         return self._maplayer.GetName()
Exemple #6
0
 def __getattr__(self, name):
     if name == 'cmd':
         return cmdtuple_to_list(self._maplayer.GetCmd())
     elif hasattr(self._maplayer, name):
         return getattr(self._maplayer, name)
     elif name == 'maplayer':
         return self._maplayer
     elif name == 'type':
         return self._maplayer.GetType()
         # elif name == 'ctrl':
     elif name == 'label':
         return self._maplayer.GetName()
Exemple #7
0
def update_cmd_file(cmd_file, cmd, mapfile):
    if cmd[0] in ('d.colorlist', 'd.font', 'd.fontlist', 'd.frame', 'd.info',
                  'd.mon', 'd.out.file', 'd.redraw', 'd.to.rast',
                  'd.what.rast', 'd.what.vect', 'd.where'):
        return

    mode = 'w' if cmd[0] == 'd.erase' else 'a'
    # update cmd file
    fd = open(cmd_file, mode)
    if fd is None:
        grass.fatal("Unable to open file '{0}'".format(cmd_file))
    if mode == 'a':
        frame = os.getenv('GRASS_RENDER_FRAME', None)
        if frame:
            fd.write('# GRASS_RENDER_FRAME={0}\n'.format(frame))
        if mapfile:
            fd.write('# GRASS_RENDER_FILE={0}\n'.format(mapfile))
        fd.write(' '.join(gtask.cmdtuple_to_list(cmd)))
        fd.write('\n')
    else:
        fd.write('')
    fd.close()
def update_cmd_file(cmd_file, cmd, mapfile):
    if cmd[0] in ('d.colorlist', 'd.font', 'd.fontlist',
                  'd.frame', 'd.info', 'd.mon', 'd.out.file',
                  'd.redraw', 'd.to.rast', 'd.what.rast',
                  'd.what.vect', 'd.where'):
        return
    
    mode = 'w' if cmd[0] == 'd.erase' else 'a'
    # update cmd file
    fd = open(cmd_file, mode)
    if fd is None:
        grass.fatal("Unable to open file '{}'".format(cmd_file))
    if mode == 'a':
        frame = os.getenv('GRASS_RENDER_FRAME', None)
        if frame:
            fd.write('# GRASS_RENDER_FRAME={}\n'.format(frame))
        if mapfile:
            fd.write('# GRASS_RENDER_FILE={}\n'.format(mapfile))
        fd.write(' '.join(gtask.cmdtuple_to_list(cmd)))
        fd.write('\n')
    else:
         fd.write('')
    fd.close()
Exemple #9
0
    def OnSave(self, event):
        """Import WMS raster data into GRASS as raster layer."""
        self.thread.abort(abortall=True)
        currmapset = grass.gisenv()["MAPSET"]

        self.output = self.params["output"].GetValue().strip()
        l_spl = self.output.strip().split("@")

        # check output layer
        msg = None
        if not self.output:
            msg = _("Missing output raster.")

        elif len(l_spl) > 1 and l_spl[1] != currmapset:
            msg = _("Output map can be added only to current mapset.")

        elif (not self.overwrite.IsChecked()
              and grass.find_file(self.output, "cell", ".")["fullname"]):
            msg = _("Output map <%s> already exists" % self.output)

        if msg:
            GMessage(parent=self, message=msg)
            return

        self.output = l_spl[0]

        # check region
        region = self.params["region"].GetValue().strip()
        reg_spl = region.strip().split("@")

        reg_mapset = "."
        if len(reg_spl) > 1:
            reg_mapset = reg_spl[1]

        if self.region_types["named"].GetValue():
            if not grass.find_file(reg_spl[0], "windows",
                                   reg_mapset)["fullname"]:
                msg = _("Region <%s> does not exist." %
                        self.params["region"].GetValue())
                GWarning(parent=self, message=msg)
                return

        # create r.in.wms command
        cmd = ("r.in.wms", deepcopy(self.cmd[1]))

        if "map" in cmd[1]:
            del cmd[1]["map"]

        cmd[1]["output"] = self.output

        if self.overwrite.IsChecked():
            cmd[1]["overwrite"] = True

        env = os.environ.copy()
        if self.region_types["named"].GetValue():
            cmd[1]["region"] = region
        elif self.region_types["display"].GetValue():
            region = self._giface.GetMapWindow().GetMap().SetRegion()
            env["GRASS_REGION"] = region

        cmdList = cmdtuple_to_list(cmd)
        self.currentPid = self.thread.GetId()

        self.thread.RunCmd(cmdList, env=env, stderr=self.cmdStdErr)

        self.statusbar.SetStatusText(_("Downloading data..."))
Exemple #10
0
    def OnSave(self, event):
        """Import WMS raster data into GRASS as raster layer.
        """
        self.thread.abort(abortall=True)
        currmapset = grass.gisenv()['MAPSET']

        self.output = self.params['output'].GetValue().strip()
        l_spl = self.output.strip().split("@")

        # check output layer
        msg = None
        if not self.output:
            msg = _('Missing output raster.')

        elif len(l_spl) > 1 and \
                l_spl[1] != currmapset:
            msg = _('Output map can be added only to current mapset.')

        elif not self.overwrite.IsChecked() and\
                grass.find_file(self.output, 'cell', '.')['fullname']:
            msg = _('Output map <%s> already exists' % self.output)

        if msg:
            GMessage(parent=self, message=msg)
            return

        self.output = l_spl[0]

        # check region
        region = self.params['region'].GetValue().strip()
        reg_spl = region.strip().split("@")

        reg_mapset = '.'
        if len(reg_spl) > 1:
            reg_mapset = reg_spl[1]

        if self.region_types['named'].GetValue():
            if not grass.find_file(reg_spl[0], 'windows',
                                   reg_mapset)['fullname']:
                msg = _('Region <%s> does not exist.' %
                        self.params['region'].GetValue())
                GWarning(parent=self, message=msg)
                return

        # create r.in.wms command
        cmd = ('r.in.wms', deepcopy(self.cmd[1]))

        if 'map' in cmd[1]:
            del cmd[1]['map']

        cmd[1]['output'] = self.output

        if self.overwrite.IsChecked():
            cmd[1]['overwrite'] = True

        env = os.environ.copy()
        if self.region_types['named'].GetValue():
            cmd[1]['region'] = region
        elif self.region_types['display'].GetValue():
            region = self._giface.GetMapWindow().GetMap().SetRegion()
            env['GRASS_REGION'] = region

        cmdList = cmdtuple_to_list(cmd)
        self.currentPid = self.thread.GetId()

        self.thread.RunCmd(cmdList, env=env, stderr=self.cmdStdErr)

        self.statusbar.SetStatusText(_("Downloading data..."))
Exemple #11
0
    def OnSave(self, event):
        """Import WMS raster data into GRASS as raster layer.
        """
        self.thread.abort(abortall=True)
        currmapset = grass.gisenv()['MAPSET']

        self.output = self.params['output'].GetValue().strip()
        l_spl = self.output.strip().split("@")

        # check output layer
        msg = None
        if not self.output:
            msg = _('Missing output raster.')

        elif len(l_spl) > 1 and \
                l_spl[1] != currmapset:
            msg = _('Output map can be added only to current mapset.')

        elif not self.overwrite.IsChecked() and\
                grass.find_file(self.output, 'cell', '.')['fullname']:
            msg = _('Output map <%s> already exists' % self.output)

        if msg:
            GMessage(parent=self,
                     message=msg)
            return

        self.output = l_spl[0]

        # check region
        region = self.params['region'].GetValue().strip()
        reg_spl = region.strip().split("@")

        reg_mapset = '.'
        if len(reg_spl) > 1:
            reg_mapset = reg_spl[1]

        if self.region_types['named'].GetValue():
            if not grass.find_file(reg_spl[0], 'windows', reg_mapset)[
                    'fullname']:
                msg = _(
                    'Region <%s> does not exist.' %
                    self.params['region'].GetValue())
                GWarning(parent=self,
                         message=msg)
                return

        # create r.in.wms command
        cmd = ('r.in.wms', deepcopy(self.cmd[1]))

        if 'map' in cmd[1]:
            del cmd[1]['map']

        cmd[1]['output'] = self.output

        if self.overwrite.IsChecked():
            cmd[1]['overwrite'] = True

        env = os.environ.copy()
        if self.region_types['named'].GetValue():
            cmd[1]['region'] = region
        elif self.region_types['display'].GetValue():
            region = self._giface.GetMapWindow().GetMap().SetRegion()
            env['GRASS_REGION'] = region

        cmdList = cmdtuple_to_list(cmd)
        self.currentPid = self.thread.GetId()

        self.thread.RunCmd(cmdList, env=env, stderr=self.cmdStdErr)

        self.statusbar.SetStatusText(_("Downloading data..."))