當前位置: 首頁>>代碼示例>>Python>>正文


Python Algorithm.run方法代碼示例

本文整理匯總了Python中algorithm.Algorithm.run方法的典型用法代碼示例。如果您正苦於以下問題:Python Algorithm.run方法的具體用法?Python Algorithm.run怎麽用?Python Algorithm.run使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在algorithm.Algorithm的用法示例。


在下文中一共展示了Algorithm.run方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: calculate

# 需要導入模塊: from algorithm import Algorithm [as 別名]
# 或者: from algorithm.Algorithm import run [as 別名]
    def calculate(self):
        ''' Prepare environment to run the alg and run it. After run, merge produced 
        data basing on plugin configuration
        '''
        alg = Algorithm()
        roadLayer = self.gui.getRoadLayer()
        
        # prepare layer where to add result
        addToInputLayer = self.gui.addToOriginaLayer_RButton.isChecked()
        newOutputLayer = self.gui.outFile_LEdit.text()

        self.outLayer = roadLayer
        if not addToInputLayer:
            if not newOutputLayer:
                message = self.tr('No output vector specified')
                QgsMessageLog.logMessage(message, 'QTraffic', QgsMessageLog.CRITICAL)
                iface.messageBar().pushCritical('QTraffic', message)
                return
            
            # copy input layer to the new one
            writeError = QgsVectorFileWriter.writeAsVectorFormat(roadLayer, newOutputLayer, 'utf-8',  roadLayer.crs())
            if writeError != QgsVectorFileWriter.NoError:
                message = self.tr('Error writing vector file {}'.format(newOutputLayer))
                QgsMessageLog.logMessage(message, 'QTraffic', QgsMessageLog.CRITICAL)
                iface.messageBar().pushCritical('QTraffic', message)
                return
            
            # load the layer
            newLayerName =os.path.splitext(os.path.basename(  newOutputLayer ))[0]
            self.outLayer = QgsVectorLayer(newOutputLayer, newLayerName, 'ogr')
            if not self.outLayer.isValid():
                message = self.tr('Error loading vector file {}'.format(newOutputLayer))
                QgsMessageLog.logMessage(message, 'QTraffic', QgsMessageLog.CRITICAL)
                iface.messageBar().pushCritical('QTraffic', message)
                return
        
        # prepare environment
        try:
            alg.setProject(self.project)
            alg.setLayer( roadLayer )
            alg.init()
            alg.prepareRun()
        except:
            traceback.print_exc()
            message = self.tr('Error preparing context for the algoritm')
            QgsMessageLog.logMessage(message, 'QTraffic', QgsMessageLog.CRITICAL)
            iface.messageBar().pushCritical('QTraffic', message)
            return
        
        # run the alg
        success = alg.run()
        if not success:
            return
        
        # prepare result
        try:
            alg.addResultToLayer(self.outLayer)
        except:
            return
        
        # add or refresh rsult vector layer
        if not addToInputLayer:
            QgsMapLayerRegistry.instance().addMapLayer(self.outLayer)
        iface.mapCanvas().refresh()
開發者ID:enricofer,項目名稱:QTraffic,代碼行數:66,代碼來源:output_tab_manager.py

示例2: qualia

# 需要導入模塊: from algorithm import Algorithm [as 別名]
# 或者: from algorithm.Algorithm import run [as 別名]
from algorithm import Algorithm
import time
 
def qualia():
	return {'qualia': input("Number from 0 to 100: ")}
 
def t():
	return {'t': time.asctime()}
 
moraltemp = Algorithm(t, qualia)
 
card = moraltemp.run()
# Number from 0 to 100: 49
card['t']
# 'Sat Feb 15 01:37:30 2014'
card['qualia']
# 49
開發者ID:Historiomics,項目名稱:Quickcards,代碼行數:19,代碼來源:moraltempcards_v2.py

示例3: GUI

# 需要導入模塊: from algorithm import Algorithm [as 別名]
# 或者: from algorithm.Algorithm import run [as 別名]

#.........這裏部分代碼省略.........
		hbox.pack_start(self.second_seq_file_entry, True, True, 0)
		choose_file_button.connect('clicked', self.choose_file_callback, self.second_seq_file_entry)

		# online input with accession number
		
		self.second_seq_online_entry = gtk.Entry()
		self.second_seq_online_entry.set_placeholder_text("ID Number")
		self.main_box.pack_start(self.second_seq_online_entry, False, False, 0)


	def add_controls_buttons(self):
		
		hbox = gtk.Box(spacing=5)
		self.main_box.pack_start(hbox, False, False, 0)

		exit_button = gtk.Button("Exit")
		exit_button.connect('clicked', gtk.main_quit)
		hbox.pack_start(exit_button, True, True, 0)

		calculate_button = gtk.Button('Calculate')
		calculate_button.connect('clicked', self.calculate)
		hbox.pack_start(calculate_button, True, True, 0)


	def choose_file_callback(self, button, seq_file_entry):
		
		dialog = gtk.FileChooserDialog("Please choose a file", self,
        	gtk.FileChooserAction.OPEN,
        	(("_Cancel"), gtk.ResponseType.CANCEL,
        		("_Open"), gtk.ResponseType.OK))

		self.add_filters(dialog)

		response = dialog.run()
		if response == gtk.ResponseType.OK:
			seq_file_entry.set_text(dialog.get_filename())
		elif response == gtk.ResponseType.CANCEL:
			pass

		dialog.destroy()


	def add_filters(self, dialog):
		
		filter_text = gtk.FileFilter()
		filter_text.set_name("Text files")
		filter_text.add_mime_type("text/plain")
		dialog.add_filter(filter_text)

		filter_any = gtk.FileFilter()
		filter_any.set_name("Any files")
		filter_any.add_pattern("*")
		dialog.add_filter(filter_any)


	def file_type_toggled(self, button, name):
		
		if button.get_active():
			self.file_type = name


	def calculate(self, button):
	
		self.get_first_seq()
		self.get_second_seq()
開發者ID:muhammedeltabakh,項目名稱:SEQUENCE-X-SEQUENCE,代碼行數:69,代碼來源:gui.py


注:本文中的algorithm.Algorithm.run方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。