I have a polygon layer and I want to know the altitude of the centroids. I guess I have to find on the internet (how?) a layer that contains data about the territory's height (in this case Italy in particular Toscana and Liguria) and to find a way to correlate it with my layer (using Python is better). Does anyone have a suggestion?
vlayer = QgsProject.instance().mapLayersByName('Centroids')[0]
rlayer = QgsProject.instance().mapLayersByName('Elevation')[0]
params = {'INPUT_VECTOR': QgsProcessingFeatureSourceDefinition(vlayer.id(), True),
'INPUT_RASTER': QgsProcessingFeatureSourceDefinition(rlayer.id(), True),
'COLUMN_PREFIX' : 'Altitude',
'OUTPUT': 'memory:'}
newLayer = processing.run("qgis:rastersampling", params)
layerOutput = newLayer['OUTPUT']
QgsProject.instance().addMapLayer(layerOutput)
I tried in this way, but there's something wrong. This is the error message: Could not load source layer for INPUT: no value specified for parameter