Error "Random points from classification"

Issue #874 resolved
Eike Lie created an issue

moin,

bekomme beim obigen Tool folgenden Fehler im log, verstehe ihn aber nicht. (Nebenbei: das TIFF wurde nicht in der Enmapbox gerechnet)

2021-12-10T14:48:44     CRITICAL    Traceback (most recent call last):
              File "C:/Users//AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\enmapboxgeoalgorithms\provider.py", line 155, in processAlgorithm
              result = self.processAlgorithm_()
              File "C://AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\enmapboxgeoalgorithms\algorithms.py", line 2085, in processAlgorithm_
              progressBar=self._progressBar)
              File "C://AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\hubflow\core.py", line 3026, in fromRandomPointsFromClassification
              filename=filename)
              File "C://AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\hubflow\core.py", line 55, in apply
              overwrite=self.kwargs.get('overwrite', True), *ufuncArgs, **ufuncKwargs)
              File "C://AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\hubdc\applier.py", line 979, in apply
              results = self._runProcessSubgrids()
              File "C://AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\hubdc\applier.py", line 1048, in _runProcessSubgrids
              result = self.operatorType.aggregate(blockResults=blockResults, grid=self.grid(), *self.ufuncArgs, **self.ufuncKwargs)
              File "C://AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\hubflow\core.py", line 3197, in aggregate
              indicisi = indicis[id == i + 1]
             IndexError: boolean index did not match indexed array along dimension 0; dimension is 292979342 but corresponding boolean dimension is 564240495

             During handling of the above exception, another exception occurred:

             Traceback (most recent call last):
              File "C:/Users//AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\enmapboxgeoalgorithms\provider.py", line 169, in processAlgorithm
              raise Exception('unexpected error')
             Exception: unexpected error

Comments (16)

  1. Eike Lie reporter

    IConsole command:

    >>>qgis_process run enmapbox:RandomPointsFromCategorizedRasterLayer --stratification=/home/eike/Desktop/Segeberg/klassifikationen/reclassified.vrt n=30 distanceGlobal=0 distanceStatum=0 outputPoints=TEMPORARY_OUTPUT

    Traceback (most recent call last):
    File "/home/eike/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/site-packages/typeguard/__init__.py", line 903, in wrapper
    retval = func(*args, **kwargs)
    File "/home/eike/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapboxprocessing/algorithm/randompointsfromcategorizedrasteralgorithm.py", line 158, in processAlgorithm
    writer = driver.createFromArray(arrayStrata, stratification.extent(), stratification.crs())
    File "/home/eike/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/site-packages/typeguard/__init__.py", line 903, in wrapper
    retval = func(*args, **kwargs)
    File "/home/eike/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapboxprocessing/driver.py", line 75, in createFromArray
    dataType = Utils.numpyDataTypeToQgisDataType(array[0].dtype)
    File "/home/eike/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/site-packages/typeguard/__init__.py", line 903, in wrapper
    retval = func(*args, **kwargs)
    File "/home/eike/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapboxprocessing/utils.py", line 128, in numpyDataTypeToQgisDataType
    raise Exception(f'unsupported data type: {dataType}')
    Exception: unsupported data type: int64

    Execution failed after 844.76 seconds (14 minutes 5 seconds)

  2. Andreas Janz

    Looks like the int64 data type causes problems.

    1. You can save your classification as int32, which should solve the problem.
    2. Please share your classification file, so that I can reproduce the error.

  3. Andreas Janz
    1. Your raster has two bands. I took the first band and categorized it (use Layer Property >Symbology).

    2. Now you can draw random points:

    Unfortunately, with your data, it took me 2 minutes to draw 10 points per class. Drawing 1000 points in total takes about 30 minutes. So be prepared to wait a bit.

    I definetly need to investigate, why this is so slow:
    follow-up issue #880

  4. Eike Lie reporter

    as already mentioned, it’s not working for me, even not if I convert the data type.

    QGIS version: 3.22.1-Białowieża

    QGIS code revision: 663dcf8fb9

    Qt version: 5.12.8

    Python version: 3.8.10

    GDAL version: 3.0.4

    GEOS version: 3.8.0-CAPI-1.13.1

    PROJ version: Rel. 6.3.1, February 10th, 2020

    PDAL version: 2.0.1 (git-version: Release)

    Algorithm started at: 2021-12-14T14:33:04

    Algorithm 'Random points from categorized raster layer' starting…

    Input parameters:

    { 'distanceGlobal' : 0, 'distanceStatum' : 0, 'n' : '10', 'outputPoints' : 'TEMPORARY_OUTPUT', 'seed' : None, 'stratification' : '/tmp/processing_kzygtl/d36acbde676b49a6a973c3056f63ff81/outputTranslatedRaster.tif' }

    Python command:

    >>>processing.run('enmapbox:RandomPointsFromCategorizedRasterLayer', dict(stratification='/tmp/processing_kzygtl/d36acbde676b49a6a973c3056f63ff81/outputTranslatedRaster.tif', n='10', distanceGlobal=0, distanceStatum=0, outputPoints='TEMPORARY_OUTPUT'))

    Console command:

    >>>qgis_process run enmapbox:RandomPointsFromCategorizedRasterLayer --stratification=/tmp/processing_kzygtl/d36acbde676b49a6a973c3056f63ff81/outputTranslatedRaster.tif n=10 distanceGlobal=0 distanceStatum=0 outputPoints=TEMPORARY_OUTPUT

    Traceback (most recent call last):
    File "/home/eike/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/site-packages/typeguard/__init__.py", line 903, in wrapper
    retval = func(*args, **kwargs)
    File "/home/eike/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapboxprocessing/algorithm/randompointsfromcategorizedrasteralgorithm.py", line 158, in processAlgorithm
    writer = driver.createFromArray(arrayStrata, stratification.extent(), stratification.crs())
    File "/home/eike/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/site-packages/typeguard/__init__.py", line 903, in wrapper
    retval = func(*args, **kwargs)
    File "/home/eike/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapboxprocessing/driver.py", line 75, in createFromArray
    dataType = Utils.numpyDataTypeToQgisDataType(array[0].dtype)
    File "/home/eike/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/site-packages/typeguard/__init__.py", line 903, in wrapper
    retval = func(*args, **kwargs)
    File "/home/eike/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapboxprocessing/utils.py", line 128, in numpyDataTypeToQgisDataType
    raise Exception(f'unsupported data type: {dataType}')
    Exception: unsupported data type: int64

    Execution failed after 273.12 seconds (4 minutes 33 seconds)

    Loading resulting layers

    Algorithm 'Random points from categorized raster layer' finished

  5. Andreas Janz

    Alright, not sure why this happens on your system, it’s probably Linux related.

    Anyways, here is a workaround that you can try for now:

    Edit this line:

    /home/eike/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapboxprocessing/algorithm/randompointsfromcategorizedrasteralgorithm.py", line 158, in processAlgorithm

    To:

    writer = driver.createFromArray(arrayStrata.astype(np.int32), stratification.extent(), stratification.crs())

    Restart QGIS and try again.

  6. Eike Lie reporter

    Console command:

    >>>qgis_process run enmapbox:RandomPointsFromCategorizedRasterLayer --stratification=/home/eike/Desktop/Segeberg/klassifikationen/all_features_Cnv.tif n=10 distanceGlobal=0 distanceStatum=0 outputPoints=TEMPORARY_OUTPUT

    Traceback (most recent call last):
    File "/home/eike/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/site-packages/typeguard/__init__.py", line 903, in wrapper
    retval = func(*args, **kwargs)
    File "/home/eike/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapboxprocessing/algorithm/randompointsfromcategorizedrasteralgorithm.py", line 158, in processAlgorithm
    writer = driver.createFromArray(arrayStrata.astype(np.int32), stratification.extent(), stratification.crs())
    AttributeError: 'list' object has no attribute 'astype'

    Execution failed after 264.38 seconds (4 minutes 24 seconds)

    😔

  7. Andreas Janz

    Sorry, didn’t testet it, this should work:
    writer = driver.createFromArray(np.array(arrayStrata).astype(np.int32), stratification.extent(), stratification.crs())

  8. Log in to comment