Exemple #1
0
    def UpdateLocations(self, dbase):
        """Update list of locations"""
        try:
            self.listOfLocations = GetListOfLocations(dbase)
        except (UnicodeEncodeError, UnicodeDecodeError) as e:
            GError(parent=self,
                   message=_(
                       "Unicode error detected. "
                       "Check your locale settings. Details: {0}").format(e),
                   showTraceback=False)

        self.lblocations.Clear()
        self.lblocations.InsertItems(self.listOfLocations, 0)

        if len(self.listOfLocations) > 0:
            self._hideMessage()
            self.lblocations.SetSelection(0)
        else:
            self.lblocations.SetSelection(wx.NOT_FOUND)
            self._showWarning(
                _("No GRASS Location found in '%s'."
                  " Create a new Location or choose different"
                  " GRASS database directory.") % self.gisdbase)

        return self.listOfLocations
Exemple #2
0
    def _initTreeItems(self, locations=[], mapsets=[]):
        """Add locations, mapsets and layers to the tree."""
        if not locations:
            locations = GetListOfLocations(self.gisdbase)
        if not mapsets:
            mapsets = ['*']

        first = True
        for loc in locations:
            location = loc
            if first:
                self.ChangeEnvironment(location, 'PERMANENT')
                first = False
            else:
                self.ChangeEnvironment(location)
            varloc = self.AppendItem(self.root, loc)
            #get list of all maps in location
            maplist = RunCommand('g.list',
                                 flags='mt',
                                 type='rast,rast3d,vect',
                                 mapset=','.join(mapsets),
                                 quiet=True,
                                 read=True)
            maplist = maplist.splitlines()
            for ml in maplist:
                # parse
                parts1 = ml.split('/')
                parts2 = parts1[1].split('@')
                mapset = parts2[1]
                mlayer = parts2[0]
                ltype = parts1[0]
                if self.itemExists(mapset, varloc) == False:
                    varmapset = self.AppendItem(varloc, mapset)
                if (self.GetItemText(varmapset) == mapset):
                    if (self.itemExists(ltype, varmapset) == False):
                        vartype = self.AppendItem(varmapset, ltype)
                else:
                    varmapset = self.getItemByName(mapset, varloc)
                    if (self.itemExists(ltype, varmapset) == False):
                        vartype = self.AppendItem(varmapset, ltype)
                self.AppendItem(vartype, mlayer)
        self.RestoreBackup()
        Debug.msg(1, "Tree filled")
Exemple #3
0
    def UpdateLocations(self, dbase):
        """Update list of locations"""
        try:
            self.listOfLocations = GetListOfLocations(dbase)
        except UnicodeEncodeError:
            GError(parent=self,
                   message=_("Unable to set GRASS database. "
                             "Check your locale settings."))

        self.lblocations.Clear()
        self.lblocations.InsertItems(self.listOfLocations, 0)

        if len(self.listOfLocations) > 0:
            self._hideMessage()
            self.lblocations.SetSelection(0)
        else:
            self.lblocations.SetSelection(wx.NOT_FOUND)
            self._showWarning(
                _("No GRASS location found in '%s'.") % self.gisdbase)

        return self.listOfLocations
Exemple #4
0
    def _initTreeItems(self, locations=None, mapsets=None):
        """Add locations, mapsets and layers to the tree.
        Runs in multiple processes. Saves resulting data and error."""
        # mapsets param currently unused
        genv = gisenv()
        if not locations:
            locations = GetListOfLocations(genv['GISDBASE'])

        loc_count = proc_count = 0
        queue_list = []
        proc_list = []
        loc_list = []
        nprocs = 4
        try:
            nprocs = cpu_count()
        except NotImplementedError:
            nprocs = 4

        results = dict()
        errors = []
        location_nodes = []
        nlocations = len(locations)
        grassdata_node = self._model.AppendNode(
            parent=self._model.root,
            label=_('GRASS locations in {0}').format(genv['GISDBASE']),
            data=dict(type='grassdata'))
        for location in locations:
            results[location] = dict()
            varloc = self._model.AppendNode(parent=grassdata_node,
                                            label=location,
                                            data=dict(type='location',
                                                      name=location))
            location_nodes.append(varloc)
            loc_count += 1

            Debug.msg(
                3, "Scanning location <{0}> ({1}/{2})".format(
                    location, loc_count, nlocations))

            q = Queue()
            p = Process(target=getLocationTree,
                        args=(genv['GISDBASE'], location, q))
            p.start()

            queue_list.append(q)
            proc_list.append(p)
            loc_list.append(location)

            proc_count += 1
            # Wait for all running processes
            if proc_count == nprocs or loc_count == nlocations:
                Debug.msg(4, "Process subresults")
                for i in range(len(loc_list)):
                    maps, error = queue_list[i].get()
                    proc_list[i].join()
                    if error:
                        errors.append(error)

                    for key in sorted(maps.keys()):
                        mapset_node = self._model.AppendNode(
                            parent=location_nodes[i],
                            label=key,
                            data=dict(type='mapset', name=key))
                        self._populateMapsetItem(mapset_node, maps[key])

                proc_count = 0
                proc_list = []
                queue_list = []
                loc_list = []
                location_nodes = []

        if errors:
            wx.CallAfter(GWarning, '\n'.join(errors))
        Debug.msg(1, "Tree filled")
        self.RefreshItems()