I have used the graphical modeller on QGIS to build a simple model performing some processing on my input layer which would be a vector.
What I want to do is to have the name of the input layer, and then by having that, to look through my file to return some of the numbers in there.
So how do I get the name of my input layer in QGIS please?
Edit:
This is my script:
from qgis.core import QgsProcessing
from qgis.core import QgsProcessingAlgorithm
from qgis.core import QgsProcessingMultiStepFeedback
from qgis.core import QgsProcessingParameterExtent
from qgis.core import QgsProcessingParameterVectorLayer
from qgis.core import QgsProcessingParameterRasterDestination
import processing
import pandas as pd
df=pd.read_csv("....csv")
def score_list(namee):
global a,b,c
for i in range(0, df.shape[0]):
if namee == df.iloc[i][1]:
a = df.iloc[i][5]
b = df.iloc[i][6]
c = df.iloc[i][7]
else:
pass
class SiteSearchModel(QgsProcessingAlgorithm):
def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterExtent('extent', 'extent', defaultValue=None))
self.addParameter(QgsProcessingParameterVectorLayer('input', 'Input', types=[QgsProcessing.TypeVectorAnyGeometry], defaultValue=None))
self.addParameter(QgsProcessingParameterRasterDestination('ReclassifiedRaster', 'Reclassified raster', createByDefault=True, defaultValue=None))
def processAlgorithm(self, parameters, context, feedback):
source = self.parameterAsVectorLayer(parameters, 'input', context)
source_name = source.name()
score_list(source_name)
def processAlgorithm(self, parameters, context, model_feedback):
# Use a multi-step feedback, so that individual child algorithm progress reports are adjusted for the
# overall progress through the model
feedback = QgsProcessingMultiStepFeedback(3, model_feedback)
results = {}
outputs = {}
# Rasterize (vector to raster)
alg_params = {
'BURN': 1,
'DATA_TYPE': 5, # Float32
'EXTENT': parameters['extent'],
'EXTRA': '',
'FIELD': '',
'HEIGHT': 50,
'INIT': None,
'INPUT': parameters['input'],
'INVERT': False,
'NODATA': 0,
'OPTIONS': '',
'UNITS': 1, # Georeferenced units
'USE_Z': False,
'WIDTH': 50,
'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
}
outputs['RasterizeVectorToRaster'] = processing.run('gdal:rasterize', alg_params, context=context, feedback=feedback, is_child_algorithm=True)
feedback.setCurrentStep(1)
if feedback.isCanceled():
return {}
# PM
alg_params = {
'BAND': 1,
'DATA_TYPE': 5, # Float32
'EXTRA': '',
'INPUT': outputs['RasterizeVectorToRaster']['OUTPUT'],
'MAX_DISTANCE': None,
'NODATA': 0,
'OPTIONS': '',
'REPLACE': None,
'UNITS': 0, # Georeferenced coordinates
'VALUES': '1',
'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
}
outputs['Pm'] = processing.run('gdal:proximity', alg_params, context=context, feedback=feedback, is_child_algorithm=True)
feedback.setCurrentStep(2)
if feedback.isCanceled():
return {}
# Reclassify by table
alg_params = {
'DATA_TYPE': 5, # Float32
'INPUT_RASTER': outputs['Pm']['OUTPUT'],
'NODATA_FOR_MISSING': False,
'NO_DATA': -9999,
'RANGE_BOUNDARIES': 0, # min < value <= max
'RASTER_BAND': 1,
'TABLE': ['0','0', a ,'0','10000', b ,'10000','', c],
'OUTPUT': parameters['ReclassifiedRaster']
}
outputs['ReclassifyByTable'] = processing.run('native:reclassifybytable', alg_params, context=context, feedback=feedback, is_child_algorithm=True)
results['ReclassifiedRaster'] = outputs['ReclassifyByTable']['OUTPUT']
return results
def name(self):
return 'Site search model'
def displayName(self):
return 'Site search model'
def group(self):
return 'Site search'
def groupId(self):
return 'Site search'
def createInstance(self):
return SiteSearchModel()