Is there a way in QGIS or with pyqgis to populate a new column only when row and column names match (like in the example below)?
It's easy to do that with R but I can't find a solution in QGIS or with PyQGIS.
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
A solution without PyQGIS or Python
Use the following epression
if(array_contains(array('test2', 'test3', 'test8'), "test"), attribute($currentfeature, "test"), NULL) in the "Expression Dialog"
Note: Beforehand you will need to create an array that will contain all the attributes' names, e.g.
array('attribute1', 'attribute2', ...), i.e.
array('Polygon1', 'Polygon2', 'Polygon3', 'Polygon4').
So, your final expression may be looking like
if(array_contains(array('Polygon1', 'Polygon2', 'Polygon3', 'Polygon4'), "ID"), attribute($currentfeature, "ID"), NULL).