Beispiel #1
0
 def execute(self):
     layers = QGisLayers.getAllLayers()
     layersMap = dict([(layer.name(), layer) for layer in layers])
     layerNames = [layer.name() for layer in layers]
     item, ok = QtGui.QInputDialog.getItem(None,
                                           "Select a layer",
                                           "Layer selection",
                                           layerNames,
                                           editable=False)
     if ok:
         layer = layersMap[item]
         SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_XMIN,
                                        layer.extent().xMinimum())
         SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_YMIN,
                                        layer.extent().yMinimum())
         SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_XMAX,
                                        layer.extent().xMaximum())
         SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_YMAX,
                                        layer.extent().yMaximum())
         SextanteConfig.setSettingValue(GrassUtils.GRASS_AUTO_REGION, False)
         s = str(layer.extent().xMinimum()) + "," + str(
             layer.extent().xMaximum()) + "," + str(
                 layer.extent().yMinimum()) + "," + str(
                     layer.extent().yMaximum())
         QtGui.QMessageBox.information(None, "GRASS Region", "GRASS region set to:\n" + s + \
                                   "\nTo set the cellsize or set back the autoregion option,\ngo to the SEXTANTE configuration.")
 def addToLog(msgtype, msg):
     try:  #it seems that this fails sometimes depending on the msg added:
         #To avoid it stopping the normal functioning of the algorithm,
         #we catch all errors, assuming that is better to miss some log info
         #that breaking the algorithm.
         if isinstance(msg, list):
             a = "|".join(m.strip("\n") for m in msg)
             text = a
         else:
             text = msg.replace("\n", "|")
         line = msgtype + "|" + datetime.datetime.now().strftime(
             SextanteLog.DATE_FORMAT).decode("utf-8") + "|" + text + "\n"
         logfile = codecs.open(SextanteLog.logFilename(),
                               "a",
                               encoding="utf-8")
         #logfile = codecs.open(SextanteLog.logFilename(), "a", encoding='utf-8')
         logfile.write(line)
         logfile.close()
         if msgtype == SextanteLog.LOG_ALGORITHM:
             algname = text[len("Sextante.runalg(\""):]
             algname = algname[:algname.index("\"")]
             if algname not in SextanteLog.recentAlgs:
                 SextanteLog.recentAlgs.append(algname)
                 recentAlgsString = ';'.join(SextanteLog.recentAlgs[-6:])
                 SextanteConfig.setSettingValue(
                     SextanteConfig.RECENT_ALGORITHMS, recentAlgsString)
     except:
         pass
Beispiel #3
0
 def setUp(self):
     SextanteConfig.setSettingValue(SextanteConfig.USE_THREADS, self.threaded)
     print
     print bcolors.INFO, self.msg, bcolors.ENDC,
     print "Parameters: ", self.alg.parameters,
     print "Outputs: ", [out for out in self.alg.outputs if not out.hidden],
     self.args = list(self.gen_test_parameters(self.alg, True))
     print ' => ', self.args, bcolors.WARNING,
Beispiel #4
0
 def setUp(self):
     SextanteConfig.setSettingValue(SextanteConfig.USE_THREADS, self.threaded)
     print 
     print bcolors.INFO, self.msg, bcolors.ENDC,
     print "Parameters: ", self.alg.parameters,
     print "Outputs: ", [out for out in self.alg.outputs if not out.hidden],
     self.args = list(self.gen_test_parameters(self.alg, True))
     print ' => ', self.args, bcolors.WARNING,
 def fillCoords(self):
     r = self.tool.rectangle()
     SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_XMIN, r.xMinimum())
     SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_YMIN, r.yMinimum())
     SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_XMAX, r.xMaximum())
     SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_YMAX, r.yMaximum())
     SextanteConfig.setSettingValue(GrassUtils.GRASS_AUTO_REGION, False)
     s = str(r.xMinimum()) + "," + str(r.xMaximum()) + "," + str(r.yMinimum()) + "," + str(r.yMaximum())
     self.tool.reset()
     canvas = QGisLayers.iface.mapCanvas()
     canvas.setMapTool(self.prevMapTool)
     QtGui.QMessageBox.information(None, "GRASS Region", "GRASS region set to:\n" + s + \
                                   "\nTo set the cellsize or set back the autoregion option,\ngo to the SEXTANTE configuration.")
 def execute(self):
     layers = QGisLayers.getAllLayers();
     layersMap = dict([(layer.name(), layer) for layer in layers])
     layerNames = [layer.name() for layer in layers]
     item, ok = QtGui.QInputDialog.getItem(None, "Select a layer", "Layer selection", layerNames, editable=False)
     if ok:
         layer = layersMap[item]
         SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_XMIN, layer.extent().xMinimum())
         SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_YMIN, layer.extent().yMinimum())
         SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_XMAX, layer.extent().xMaximum())
         SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_YMAX, layer.extent().yMaximum())
         SextanteConfig.setSettingValue(GrassUtils.GRASS_AUTO_REGION, False)
         s = str(layer.extent().xMinimum()) + "," + str(layer.extent().xMaximum()) + "," + str(layer.extent().yMinimum()) + "," + str(layer.extent().yMaximum())
         QtGui.QMessageBox.information(None, "GRASS Region", "GRASS region set to:\n" + s + \
                                   "\nTo set the cellsize or set back the autoregion option,\ngo to the SEXTANTE configuration.")
Beispiel #7
0
 def fillCoords(self):
     r = self.tool.rectangle()
     SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_XMIN,
                                    r.xMinimum())
     SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_YMIN,
                                    r.yMinimum())
     SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_XMAX,
                                    r.xMaximum())
     SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_YMAX,
                                    r.yMaximum())
     SextanteConfig.setSettingValue(GrassUtils.GRASS_AUTO_REGION, False)
     s = str(r.xMinimum()) + "," + str(r.xMaximum()) + "," + str(
         r.yMinimum()) + "," + str(r.yMaximum())
     self.tool.reset()
     canvas = QGisLayers.iface.mapCanvas()
     canvas.setMapTool(self.prevMapTool)
     QtGui.QMessageBox.information(None, "GRASS Region", "GRASS region set to:\n" + s + \
                                   "\nTo set the cellsize or set back the autoregion option,\ngo to the SEXTANTE configuration.")
Beispiel #8
0
 def addToLog(msgtype, msg):
     try: #it seems that this fails sometimes depending on the msg added:
         #To avoid it stopping the normal functioning of the algorithm,
         #we catch all errors, assuming that is better to miss some log info
         #that breaking the algorithm.
         if isinstance(msg, list):
             a = "|".join(m.strip("\n")  for m in msg)
             text = a
         else:
             text = msg.replace("\n", "|")
         line = msgtype + "|" + datetime.datetime.now().strftime(SextanteLog.DATE_FORMAT).decode("utf-8") + "|" + text + "\n"
         logfile = codecs.open(SextanteLog.logFilename(), "a", encoding="utf-8")
         #logfile = codecs.open(SextanteLog.logFilename(), "a", encoding='utf-8')
         logfile.write(line)
         logfile.close()
         if msgtype==SextanteLog.LOG_ALGORITHM:
            algname = text[len("Sextante.runalg(\""):]
            algname = algname[:algname.index("\"")]
            if algname not in SextanteLog.recentAlgs:
                SextanteLog.recentAlgs.append(algname)
                recentAlgsString = ';'.join(SextanteLog.recentAlgs[-6:])
                SextanteConfig.setSettingValue(SextanteConfig.RECENT_ALGORITHMS, recentAlgsString)
     except:
         pass