semiautomaticgit / SemiAutomaticClassificationPlugin

https://fromgistors.blogspot.com/p/semi-automatic-classification-plugin.html
Other
136 stars 50 forks source link

Python warning & python error with Random Forest Classification #203

Closed tangerine-maps closed 9 months ago

tangerine-maps commented 2 years ago

Hi, I am using QGIS 3.16.14, and newly uninstalled/reinstalled the SCP plugin today. I am trying to use Random Forest Classification, with a 4-band bandset (added as single bands), 4 MC, and when the Random Forest command is run it reaches 90% and then the QGIS log says " WARNING Python error : An error has occurred while executing Python code: See message log (Python Error) for more details."

A Python warning and Python error appear: Warning: WARNING warning:C:\Users/abc/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\SemiAutomaticClassificationPlugin\core\utils.py:7280: DeprecationWarning: QgsVectorFileWriter constructor is deprecated cfg.qgisCoreSCP.QgsVectorFileWriter(shpF, 'CP1250', f, cfg.qgisCoreSCP.QgsWkbTypes.MultiPolygon , crs, 'ESRI Shapefile')

         traceback: File "C:\Users/abc/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\SemiAutomaticClassificationPlugin\maininterface\randomForestTab.py", line 224, in performRandomForest
          self.randomForestClassification(bandSetNumber = bs, classPath = cfg.classRF)
          File "C:\Users/abc/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\SemiAutomaticClassificationPlugin\maininterface\randomForestTab.py", line 322, in randomForestClassification
          vectorList, trainingVect, reclassList = self.createShapefileFromTraining(macroclass)
          File "C:\Users/abc/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\SemiAutomaticClassificationPlugin\maininterface\randomForestTab.py", line 241, in createShapefileFromTraining
          path = cfg.utls.featuresToShapefile(v)
          File "C:\Users/abc/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\SemiAutomaticClassificationPlugin\core\utils.py", line 7280, in featuresToShapefile
          cfg.qgisCoreSCP.QgsVectorFileWriter(shpF, 'CP1250', f, cfg.qgisCoreSCP.QgsWkbTypes.MultiPolygon , crs, 'ESRI Shapefile')

Python error: WARNING Traceback (most recent call last): File "C:\Users/abc/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\SemiAutomaticClassificationPlugin\maininterface\randomForestTab.py", line 224, in performRandomForest self.randomForestClassification(bandSetNumber = bs, classPath = cfg.classRF) File "C:\Users/abc/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\SemiAutomaticClassificationPlugin\maininterface\randomForestTab.py", line 421, in randomForestClassification cfg.classTab.applyClassSymbology(r, macroclass, cfg.qmlFl, sL) File "C:\Users/abc/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\SemiAutomaticClassificationPlugin\maininterface\classificationTab.py", line 282, in applyClassSymbology cfg.utls.rasterSymbol(classificationRaster, signatureList, macroclassCheck) File "C:\Users/abc/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\SemiAutomaticClassificationPlugin\core\utils.py", line 657, in rasterSymbol lR = cfg.qgisCoreSCP.QgsPalettedRasterRenderer(classLayer.dataProvider(), cLB, cL) AttributeError: 'str' object has no attribute 'dataProvider'

Thanks for any suggestions as to what might be going wrong here!

tangerine-maps commented 2 years ago

As additional details, I believe SNAP is correctly installed and I only used manually drawn polygons (ROIs) for the training dataset.

semiautomaticgit commented 2 years ago

Hello @tangerine-maps , please copy the log file following these steps https://semiautomaticclassificationmanual.readthedocs.io/en/latest/faq.html#how-can-i-report-an-error

Could you please try this sample dataset https://docs.google.com/uc?id=1cph9rCQ1oiWgRGusgRkjUWwLW3JEwqUK

semiautomaticgit commented 9 months ago

I'm closing this because of the new version 8 of SCP. Please reopen it if it is still relevant in the new version. Thank you!