Exemple #1
0
    def AddLayers(self, returncode, cmd=None, userData=None):
        """Add imported/linked layers into layer tree"""
        if not self.add.IsChecked() or returncode != 0:
            return

        # TODO: if importing map creates more map the following does not work
        # * do nothing if map does not exist or
        # * try to determine names using regexp or
        # * persuade import tools to report map names
        self.commandId += 1
        layer, output = self.list.GetLayers()[self.commandId][:2]

        if "@" not in output:
            name = output + "@" + grass.gisenv()["MAPSET"]
        else:
            name = output

        # add imported layers into layer tree
        # an alternative would be emit signal (mapCreated) and (optionally)
        # connect to this signal
        llist = self._giface.GetLayerList()
        if self.importType == "gdal":
            if userData:
                nBands = int(userData.get("nbands", 1))
            else:
                nBands = 1

            if UserSettings.Get(group="rasterLayer",
                                key="opaque",
                                subkey="enabled"):
                nFlag = True
            else:
                nFlag = False

            for i in range(1, nBands + 1):
                nameOrig = name
                if nBands > 1:
                    mapName, mapsetName = name.split("@")
                    mapName += ".%d" % i
                    name = mapName + "@" + mapsetName

                cmd = ["d.rast", "map=%s" % name]
                if nFlag:
                    cmd.append("-n")

                llist.AddLayer(ltype="raster",
                               name=name,
                               checked=True,
                               cmd=cmd)
                name = nameOrig
        else:
            llist.AddLayer(
                ltype="vector",
                name=name,
                checked=True,
                cmd=["d.vect", "map=%s" % name] + GetDisplayVectSettings(),
            )

        self._giface.GetMapWindow().ZoomToMap()
Exemple #2
0
    def AddLayers(self, returncode, cmd=None, userData=None):
        """Add imported/linked layers into layer tree"""
        if not self.add.IsChecked() or returncode != 0:
            return

        # TODO: if importing map creates more map the following does not work
        # * do nothing if map does not exist or
        # * try to determine names using regexp or
        # * persuade import tools to report map names
        self.commandId += 1
        layer, output = self.list.GetLayers()[self.commandId][:2]

        if '@' not in output:
            name = output + '@' + grass.gisenv()['MAPSET']
        else:
            name = output

        # add imported layers into layer tree
        # an alternative would be emit signal (mapCreated) and (optionally)
        # connect to this signal
        llist = self._giface.GetLayerList()
        if self.importType == 'gdal':
            if userData:
                nBands = int(userData.get('nbands', 1))
            else:
                nBands = 1

            if UserSettings.Get(group='rasterLayer',
                                key='opaque',
                                subkey='enabled'):
                nFlag = True
            else:
                nFlag = False

            for i in range(1, nBands + 1):
                nameOrig = name
                if nBands > 1:
                    mapName, mapsetName = name.split('@')
                    mapName += '.%d' % i
                    name = mapName + '@' + mapsetName

                cmd = ['d.rast', 'map=%s' % name]
                if nFlag:
                    cmd.append('-n')

                llist.AddLayer(ltype='raster',
                               name=name,
                               checked=True,
                               cmd=cmd)
                name = nameOrig
        else:
            llist.AddLayer(ltype='vector',
                           name=name,
                           checked=True,
                           cmd=['d.vect', 'map=%s' % name] +
                           GetDisplayVectSettings())

        self._giface.GetMapWindow().ZoomToMap()