0

I would like to connect my input and output directories, as well as my input file 'boundary layer' within my processing plugin. My plugin appears like this:

enter image description here

My plugin.py file is depicted below:

import os
import sys
import inspect
from qgis.PyQt.QtWidgets import QAction, QFileDialog
from qgis.PyQt.QtGui import QIcon
from qgis.core import QgsProcessingAlgorithm, QgsApplication, Qgis, QgsProject
import processing
from .GET_provider import GETProvider
from PyQt5.QtCore import QSettings, QTranslator, qVersion, QCoreApplication
cmd_folder = os.path.split(inspect.getfile(inspect.currentframe()))[0]
if cmd_folder not in sys.path:
 sys.path.insert(0, cmd_folder)
class GETPlugin(object):
 
 def __init__(self, iface):
 self.provider = None
 self.iface = iface
 #self.dlg =GETDialog()
 #self.dlg.pushbutton.clicked.connect(self.reproject)
 def initProcessing(self):
 """Init Processing provider for QGIS >= 3.8."""
 self.provider = GETProvider()
 QgsApplication.processingRegistry().addProvider(self.provider)
 def initGui(self):
 self.initProcessing()
 
 icon = os.path.join(os.path.join(cmd_folder, 'logo.png'))
 self.action_1 = QAction(
 QIcon(icon),
 u"GE_S", self.iface.mainWindow())
 self.action_1.triggered.connect(self.runAlg_1)
 self.iface.addPluginToMenu(u"&GE", self.action_1)
 self.iface.addToolBarIcon(self.action_1)
 self.action_2 = QAction(
 QIcon(icon),
 u"GE_CD", self.iface.mainWindow())
 self.action_2.triggered.connect(self.runAlg_2)
 self.iface.addPluginToMenu(u"&GE", self.action_2)
 self.iface.addToolBarIcon(self.action_2)
 def unload(self):
 QgsApplication.processingRegistry().removeProvider(self.provider)
 self.iface.removePluginMenu(u"&GE", self.action_1)
 self.iface.removePluginMenu(u"&GE", self.action_2)
 self.iface.removeToolBarIcon(self.action_1)
 self.iface.removeToolBarIcon(self.action_2)
 
 def runAlg_1(self):
 processing.execAlgorithmDialog("GE:GE_S")
 def runAlg_2(self):
 processing.execAlgorithmDialog("GE:GE_CD")
 
 def reproject(self):
 data_dir = "C:/Downloads/Inputs"
 output_dir="C:/Downloads/Outputs"
 filename = "Boundary.shp"
 Boundary = os.path.join(data_dir,filename)
 filename = "RT_LE07_L1TP_194051_20001024_20170209_01_T1_2000年10月24日_B3.tif"
 Landsat_Image1_NIR= os.path.join(data_dir, filename)
 processing.runAndLoadResults("gdal:warpreproject",{'INPUT':Landsat_Image1_NIR,'SOURCE_CRS':None,'TARGET_CRS':QgsCoordinateReferenceSystem('EPSG:32630'),'RESAMPLING':0,'NODATA':None,'TARGET_RESOLUTION':None,'OPTIONS':'','DATA_TYPE':0,'TARGET_EXTENT':None,'TARGET_EXTENT_CRS':None,'MULTITHREADING':False,'EXTRA':'','OUTPUT':os.path.join(output_dir,'Landsat_Image1_NIR_repr.tif')}) 

My script which I want to run is under 'def reproject' (I just want to reproject this file). How do I connect my input and output directories and my boundary layer with the plugin?

asked Sep 16, 2022 at 12:32

1 Answer 1

0

Answer: The easiest way to connect the two aspects, is to first create the interface in Qt designer, name all features and connect them with .clicked.connect()

answered Nov 3, 2022 at 16:15

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.