Error with TrainImageClassifier in QGIS

Hi,

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:

{ ‘io.il’ : [’/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, ‘sample.mt’ : 1000, ‘sample.mv’ : 1000, ‘sample.bm’ : 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

Résultats:

{‘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é

Hello,

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 (https://gdal.org/drivers/vector/vrt.html) to extract the layer without having to copy the datasource. According to your input, you should create the classes.vrt file as :

<OGRVRTDataSource>
    <OGRVRTLayer name="classes">
        <SrcDataSource>/home/obstetar/Documents/dzetsaka/classes.gpkg</SrcDataSource>
            <SrcLayer>classes</SrcLayer>
    </OGRVRTLayer>
</OGRVRTDataSource>

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

Does that work for you ?

Cédric

Yes it works thanks

I am having same issue of trainvectorClassifier it says it cannnot support {‘io.il’

SO DO YOU MEAN I HAVE TO CONVERT ALL SHAPEFILE THAT I AM USING TO GDAL FILE FORMAT?

and if so can i convet that online as in shp to gdal format