1

in QGIS atlas I use a custom function to find the first file containing texts :

import os, fnmatch
from PyQt5.QtCore import QFileInfo
from qgis.core import *
from qgis.gui import *

@qgsfunction(args='auto', group='Custom')
def findphoto(nb, src1,src2,feature, parent):
    lnb=0
    val='NA'
    filen = QFileInfo(QgsProject.instance().fileName())
    Dir_report=filen.absolutePath()
    for root, directories, filenames in os.walk(Dir_report):
        for filename in filenames: 
            if fnmatch.fnmatch(filename, '*' +str(src1) + '*' + str(src2) + '*.jpg' ):
                lnb=lnb+1
                if lnb==nb:
                    val=os.path.join(root,filename)
                    break
    return val

In QGIS 2.18 it works fine (just change PyQt5 by PyQt4), in QGIS 3.2 it return "NA" value.

In QGIS 3.2 if I try in python mode, it works fine:

import os, fnmatch
from PyQt5.QtCore import QFileInfo
from qgis.core import *
from qgis.gui import *

def findphoto(nb, src1,src2):
    lnb=0
    val='NA'
    filen = QFileInfo(QgsProject.instance().fileName())
    Dir_report=filen.absolutePath()
    for root, directories, filenames in os.walk(Dir_report):
        for filename in filenames: 
            if fnmatch.fnmatch(filename, '*' +str(src1) + '*' + str(src2) + '*.jpg' ):
                lnb=lnb+1
                if lnb==nb:
                    val=os.path.join(root,filename)
                    break
    return val

why?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.