qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.37k stars 2.98k forks source link

The native:meshexporttimeseries algorithm breaks when run in a standalone script #57986

Open kylefelipe opened 2 months ago

kylefelipe commented 2 months ago

What is the bug or the crash?

Traceback (most recent call last): File "/home/kylefelipe/terraq_repo/tarefa_qgis_netcdf/script_luiz.py", line 119, in processing.run("native:meshexporttimeseries", configs) File "/usr/share/qgis/python/plugins/processing/tools/general.py", line 109, in run return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback, context) File "/usr/share/qgis/python/plugins/processing/core/Processing.py", line 215, in runAlgorithm raise QgsProcessingException(msg) _core.QgsProcessingException: There were errors executing the algorithm.

Steps to reproduce the issue

Download this script.py from gist click here Download the example files in the same folder as the script Google Drive Run the script from the terminal, or OSGEO Shell. Linux example:

python3 script.py

Versions

QGIS version 3.34.8-Prizren QGIS code revision 91642333b10
Qt version 5.15.3
Python version 3.10.12
GDAL/OGR version 3.4.1
PROJ version 8.2.1
EPSG Registry database version v10.041 (2021-12-03)
GEOS version 3.10.2-CAPI-1.16.0
SQLite version 3.37.2
PDAL version 2.3.0
PostgreSQL client version 14.12 (Ubuntu 14.12-0ubuntu0.22.04.1)
SpatiaLite version 5.0.1
QWT version 6.1.4
QScintilla2 version 2.11.6
OS version Ubuntu 22.04.4 LTS
       

Active Python plugins quick_map_services | 0.19.34 MetaSearch | 0.3.6 processing | 2.12.99 grassprovider | 2.12.99 db_manager | 0.1.20

QGIS version 3.34.8-Prizren QGIS code revision 91642333b10 Qt version 5.15.3 Python version 3.10.12 GDAL/OGR version 3.4.1 PROJ version 8.2.1 EPSG Registry database version v10.041 (2021-12-03) GEOS version 3.10.2-CAPI-1.16.0 SQLite version 3.37.2 PDAL version 2.3.0 PostgreSQL client version 14.12 (Ubuntu 14.12-0ubuntu0.22.04.1) SpatiaLite version 5.0.1 QWT version 6.1.4 QScintilla2 version 2.11.6 OS version Ubuntu 22.04.4 LTS

Active Python plugins quick_map_services 0.19.34 MetaSearch 0.3.6 processing 2.12.99 grassprovider 2.12.99 db_manager 0.1.20

Supported QGIS version

New profile

Additional context

Runing meshexporttimeseries from GUI works like a charm. STEPS:

Add the .nc file as Mesh layer to project Set mesh projection to ESPG:4326 Add the gpkg as vector layer to project Go to Toolbox> Double click on Export time series values from points of a mesh dataset Input mesh layere > Choose mesh layer above Data set groups > Click on ... then Select in available dataset groups then select all > ok Ending time > choose the last one (press end on keyboard) Points for data export > Choose pont layer Digits count for coordinates > 8 Digits count for dataset value > 8 exported data csv file > choose path and file name click run...

agiudiceandrea commented 2 months ago

@kylefelipe, thanks for reporting. Does the output of the commands

from qgis.core import QgsProviderRegistry
print(QgsProviderRegistry.instance().providerList())

added just before the mesh_layer = QgsMeshLayer(mesh_path, "mesh", "mdal") contain the mdal provider name? Does the output of print(mesh_layer) added just after mesh_layer = QgsMeshLayer(mesh_path, "mesh", "mdal") states that it is a valid layer?

In order to avoid the error

  File "C:\OSGeo4W_V2_8/apps/qgis/python/plugins\processing\core\Processing.py", line 231, in runAlgorithm
    raise QgsProcessingException(msg)
_core.QgsProcessingException: There were errors executing the algorithm.

you need to put the QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms()) after the Processing.initialize() line, not before. Anyway, QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms()) is not needed.

kylefelipe commented 2 months ago

Hi @agiudiceandrea, thx for helping me!

print(QgsProviderRegistry.instance().providerList()) added just before the mesh_layer = QgsMeshLayer(mesh_path, "mesh", "mdal") contain the mdal provider name?

R: No, just show these names ['arcgisvectortileservice', 'cesiumtiles', 'copc', 'ept', 'gdal', 'mbtilesvectortiles', 'memory', 'mesh_memory', 'ogr', 'tiledscene', 'vectortile', 'vpc', 'vtpkvectortiles', 'xyzvectortiles']

Does the output of print(mesh_layer) added just after mesh_layer = QgsMeshLayer(mesh_path, "mesh", "mdal") states that it is a valid layer?

R) No, it shows that is an invalid layer

you need to put the QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms()) after the Processing.initialize() line, not before. Anyway, QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms()) is not needed.

R) Thx.

I am updating the gist with new code... And its still issuing (...) There where errors executing the algorithm

github-actions[bot] commented 1 month ago

The QGIS project highly values your report and would love to see it addressed. However, this issue has been left in feedback mode for the last 14 days and is being automatically marked as "stale". If you would like to continue with this issue, please provide any missing information or answer any open questions. If you could resolve the issue yourself meanwhile, please leave a note for future readers with the same problem and close the issue. In case you should have any uncertainty, please leave a comment and we will be happy to help you proceed with this issue. If there is no further activity on this issue, it will be closed in a week.

agiudiceandrea commented 1 month ago

I am updating the gist with new code...

Does the new code make QgsProviderRegistry.instance().providerList() contain the mdal provider name and mesh_layer be a valid mesh layer? What is the full error message?

kylefelipe commented 1 month ago

@agiudiceandrea

I am updating the gist with new code...

Does the new code make QgsProviderRegistry.instance().providerList() contain the mdal provider name and mesh_layer be a valid mesh layer? What is the full error message?

No...

Full error:

Provider list ['arcgisvectortileservice', 'cesiumtiles', 'copc', 'ept', 'gdal', 'mbtilesvectortiles', 'memory', 'mesh_memory', 'ogr', 'tiledscene', 'vectortile', 'vpc', 'vtpkvectortiles', 'xyzvectortiles']
Layer is valid: False
<QgsMeshLayer: 'mesh' (Invalid)>
Traceback (most recent call last):
  File "/home/kylefelipe/terraq_repo/tarefa_qgis_netcdf/using_pyqgis.py", line 72, in <module>
    processing.run("native:meshexporttimeseries", configs)
  File "/usr/share/qgis/python/plugins/processing/tools/general.py", line 109, in run
    return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback, context)
  File "/usr/share/qgis/python/plugins/processing/core/Processing.py", line 215, in runAlgorithm
    raise QgsProcessingException(msg)
_core.QgsProcessingException: There were errors executing the algorithm.
abreufilho commented 2 weeks ago

Any updates on that? Im running into the same issue.