problem with Reclassify tool

Issue #389 resolved
Andreas Janz created an issue

(reported by Sebastian van der Linden via email)

I rasterized the level_3_id attribute of the landcover_berlin_polygon vector source, resulting in a single band raster with values between 0 and 6:

Now I want to assign class colors and names, but the OK button is disabled:

Comments (22)

  1. Benjamin Jakimow

    Where do these errors come from @Andreas Janz ? And why is hubflow.core using a warping?

    To replicate please run enmapboxtesting/coreapps/test_reclassifyapp.py` test_hubflow_reclassify`

    Error
    Traceback (most recent call last):
      File "D:\miniconda3\envs\qgis_stable\lib\unittest\case.py", line 60, in testPartExecutor
        yield
      File "D:\miniconda3\envs\qgis_stable\lib\unittest\case.py", line 676, in run
        self._callTestMethod(testMethod)
      File "D:\miniconda3\envs\qgis_stable\lib\unittest\case.py", line 633, in _callTestMethod
        method()
      File "D:\Repositories\enmap-box\enmapboxtesting\coreapps\test_reclassifyapp.py", line 172, in test_dialog
        dsDst = reclassify(drvDst='ENVI', **settings)
      File "D:\Repositories\enmap-box\enmapbox\coreapps\reclassifyapp\reclassify.py", line 90, in reclassify
        classification.reclassify(filename=pathDst,
      File "D:\Repositories\enmap-box\hubflow\core.py", line 4058, in reclassify
        applier.apply(operatorType=_ClassificationReclassify, classification=self, classDefinition=classDefinition,
      File "D:\Repositories\enmap-box\hubflow\core.py", line 51, in apply
        results = hubdc.applier.Applier.apply(self, operatorType=operatorType, description=description,
      File "D:\Repositories\enmap-box\hubdc\applier.py", line 975, in apply
        results = self._runProcessSubgrids()
      File "D:\Repositories\enmap-box\hubdc\applier.py", line 1039, in _runProcessSubgrids
        blockResults.append(_Worker.processSubgrid(**kwargs))
      File "D:\Repositories\enmap-box\hubdc\applier.py", line 1121, in processSubgrid
        return cls.operator._apply(workingGrid=workingGrid, iblock=i, nblock=n, yblock=iy, xblock=ix, nyblock=ny,
      File "D:\Repositories\enmap-box\hubdc\applier.py", line 1268, in _apply
        blockResult = self.ufunc(*self._ufuncArgs, **self._ufuncKwargs)
      File "D:\Repositories\enmap-box\hubflow\core.py", line 4133, in ufunc
        inclassification = self.flowClassificationArray('inclassification', classification=classification)
      File "D:\Repositories\enmap-box\hubflow\core.py", line 242, in flowClassificationArray
        array = self.inputRaster.raster(key=name).array(overlap=overlap)
      File "D:\Repositories\enmap-box\hubdc\applier.py", line 136, in array
        array = self.dataset().array(indices=indices, grid=grid, resampleAlg=resampleAlg, noDataValue=noDataValue,
      File "D:\Repositories\enmap-box\hubdc\core.py", line 1686, in array
        datasetResampled = self.warp(grid=grid, filename='', driver=MemDriver(), resampleAlg=resampleAlg,
      File "D:\Repositories\enmap-box\hubdc\core.py", line 1555, in warp
        gdalDataset = gdal.Warp(destNameOrDestDS=filename, srcDSOrSrcDSTab=self._gdalDataset, options=warpOptions)
      File "D:\miniconda3\envs\qgis_stable\lib\site-packages\osgeo\gdal.py", line 625, in Warp
        return wrapper_GDALWarpDestName(destNameOrDestDS, srcDSTab, opts, callback, callback_data)
      File "D:\miniconda3\envs\qgis_stable\lib\site-packages\osgeo\gdal.py", line 3410, in wrapper_GDALWarpDestName
        return _gdal.wrapper_GDALWarpDestName(*args)
    RuntimeError: The transformation is already "north up" or a transformation between pixel/line and georeferenced coordinates cannot be computed for /vsimem/testClassification.f4c92a1d-5622-4899-8a0a-8e71bd44d2d3.tif. There is no affine transformation and no GCPs. Specify transformation option SRC_METHOD=NO_GEOTRANSFORM to bypass this check.
    

  2. Andreas Janz reporter

    @Benjamin Jakimow this has nothing to do with the reclassify algo. The raster dataset created by TestObjects.createRasterDataset is problematic. A simple gdal.Warp, that does nothing but copying the raster, also fails:

    from osgeo import gdal
    from enmapbox.testing import TestObjects
    
    dsSrc = TestObjects.createRasterDataset(10, 20, nc=5)
    gdalDataset = gdal.Warp(destNameOrDestDS='', srcDSOrSrcDSTab=dsSrc, format='MEM')
    

  3. Andreas Janz reporter
    • changed status to open

    I still don't get it!? After defining my 6 classes the OK button remains disabled. What do you mean with "just reselect the source image"?

  4. Andreas Janz reporter

    Ok, I missed the last updates, but now I get an error, when starting the Reclassify tool.

    An error has occurred while executing Python code: 
    
    TypeError: object of type 'NoneType' has no len() 
    Traceback (most recent call last):
      File "C:\source\QGISPlugIns\enmap-box\enmapbox\coreapps\reclassifyapp\enmapboxintegration.py", line 56, in startGUI
        uiDialog = ui.ReclassifyDialog(self.enmapbox.ui)
      File "C:\source\QGISPlugIns\enmap-box\enmapbox\coreapps\reclassifyapp\reclassifydialog.py", line 45, in __init__
        self.updateExceptedLayerList()
      File "C:\source\QGISPlugIns\enmap-box\enmapbox\coreapps\reclassifyapp\reclassifydialog.py", line 101, in updateExceptedLayerList
        if len(cs) == 0:
    TypeError: object of type 'NoneType' has no len()
    
    
    Python version: 3.6.10 (default, Mar  5 2020, 10:17:47) [MSC v.1900 64 bit (AMD64)] 
    QGIS version: 3.12.1-București București, exported 
    
    Python Path:
    C:\source\QGISPlugIns\enmap-box\enmapbox\apps\ensomap
    C:/miniconda/envs/py36/Library/./python
    C:/Users/janzandr/AppData/Roaming/QGIS/QGIS3\profiles\default/python
    C:\source\QGISPlugIns
    C:/Users/janzandr/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins
    C:/miniconda/envs/py36/Library/./python/plugins
    C:\miniconda\envs\py36\Library\python
    C:\miniconda\envs\py36\Library\python\plugins
    C:\Users\janzandr
    C:\miniconda\envs\py36\python36.zip
    C:\miniconda\envs\py36\DLLs
    C:\miniconda\envs\py36\lib
    C:\miniconda\envs\py36\Library\bin
    C:\Users\janzandr\AppData\Roaming\Python\Python36\site-packages
    C:\miniconda\envs\py36
    C:\miniconda\envs\py36\lib\site-packages
    C:/Users/janzandr/AppData/Roaming/QGIS/QGIS3\profiles\default/python
    C:\source\QGISPlugIns\enmap-box
    C:\source\QGISPlugIns\enmap-box\site-packages
    C:\source\QGISPlugIns\enmap-box\enmapbox\externals\qps\externals
    C:\source\QGISPlugIns\enmap-box\enmapbox
    .
    C:\source\QGISPlugIns\enmap-box\enmapbox\coreapps
    C:\source\QGISPlugIns\enmap-box\enmapbox\apps
    

  5. Andreas Janz reporter
    • changed status to open

    The error is gone, but now I do not see the layer for which I want to set the class names and color.

  6. Benjamin Jakimow

    You can “Re-classify” only layers which already have a classification scheme, either set as as GDAL style classification scheme or categorical raster/vector renderer.

  7. Andreas Janz reporter
    • changed status to open

    Hmm, still not working. I can now select the raster and see all the names and colors from the renderer. But after renaming and recoloring my classes, the OK remains disabled.

  8. Andreas Janz reporter
    • changed status to open

    I think there is still the problem, that the classes defined by the Categorized Renderer are not recognized by the Class Mapping widget, right?

  9. Andreas Janz reporter

    Thanks!

    @Sebastian van der Linden setting class names and color to a single grey band raster should work now.

  10. Log in to comment