Error with TrainImageClassifier in QGIS


I run the TrainImageClassifier in QGIS in ubuntu 20.04. I have this error :
Version de QGIS : 3.12.3-București

Révision du code : 8234261527

Version de Qt : 5.12.8

Version de GDAL : 3.0.4

Version de GEOS : 3.8.0-CAPI-1.13.1

Version de Proj : Rel. 6.3.1, February 10th, 2020

Traitement de l’algorithme…

Démarrage de l’algorithme ‘TrainImagesClassifier’…

Paramètres en entrée:

{ ‘’ : [’/home/obstetar/Documents/dzetsaka/v_sen2.tif’], ‘io.vd’ : [’/home/obstetar/Documents/dzetsaka/classes.gpkg|layername=classes’], ‘io.valid’ : ‘’, ‘io.imstat’ : ‘/home/obstetar/Documents/dzetsaka/cis.xml’, ‘io.out’ : ‘TEMPORARY_OUTPUT’, ‘io.confmatout’ : ‘TEMPORARY_OUTPUT’, ‘cleanup’ : True, ‘’ : 1000, ‘’ : 1000, ‘’ : 1, ‘sample.vtr’ : 0.5, ‘sample.vfn’ : ‘classe’, ‘elev.dem’ : ‘/home/obstetar/sen2agri/srtm’, ‘elev.geoid’ : ‘’, ‘elev.default’ : 0, ‘classifier’ : ‘knn’, ‘classifier.knn.k’ : 32, ‘rand’ : 0 }

2020-06-03 16:36:38 (FATAL): itk::ERROR: Failed to open GDALDataset file /home/obstetar/Documents/dzetsaka/classes.gpkg|layername=classes :

Exécution terminée en 0.31 secondes


{‘io.confmatout’: ‘/tmp/processing_wlodQt/b0659d84d0fd49a9b370014a5840992f/io_confmatout.file’,
‘io.out’: ‘/tmp/processing_wlodQt/93be2142492a47449ad3217da452c2f9/io_out.file’}

Chargement des couches de résultat

Algorithme ‘TrainImagesClassifier’ terminé


The input vector filename /home/obstetar/Documents/dzetsaka/classes.gpkg|layername=classes is not correct. OTB is not able to understand the layername=classes part. Where does this syntax come from ? Is it specific to geopackage files ?

If I understand correctly, you are trying to open the layer names classes in classes.gpkg. OTB will open the first layer of the vector datasource. So if there is only one layer in the datasource you can directly provide the .gpkg file.

If there are several layers in the gpkg, a workaround would be to use a virtual datasource instead ( to extract the layer without having to copy the datasource. According to your input, you should create the classes.vrt file as :

    <OGRVRTLayer name="classes">

You can then use this file as vector input of TrainImagesClassifier,

Does that work for you ?


Yes it works thanks