0

I am trying to create a Meshlayer in memory and tried this simple test in QGIS 3.6:

from qgis.core import QgsProject,QgsMeshLayer proj = QgsProject.instance() uri="1.0, 2.0 \n2.0, 2.0 \n3.0, 2.0 \n2.0, 3.0 \n1.0, 3.0 \n---0, 1, 3, 4 \n1, 2, 3 \n" outLayer = QgsMeshLayer( uri, 'test', "memory_mesh") proj.addMapLayer(outLayer) Apparently dataprovider has no attribute name and QGIS crashes. Is there something that I am doing wrong? What shoulb be the format of URI, a simple string?

1
  • correct provider name is mesh_memory
    – Peter
    Aug 20, 2021 at 6:32

1 Answer 1

2

This is a mistake in the documentation. It needs to be mesh_memory and not memory_mesh. Also the documentation is missing one \.

So in QGIS 3.12 it works perfectly:

uri="1.0, 2.0 \n" \
    "2.0, 2.0 \n" \
    "3.0, 2.0 \n" \
    "2.0, 3.0 \n" \
    "1.0, 3.0 \n" \
    "---" \
    "0, 1, 3, 4 \n" \
    "1, 2, 3 \n"
scratchLayer = QgsMeshLayer(uri, "My Scratch layer", "mesh_memory")
QgsProject.instance().addMapLayers([scratchLayer])
3
  • The documentation qgis.org/pyqgis/3.16/core/… is correct and the critical code snipped haven't changed for the last 3 years. In which doc you found the mistake?
    – Peter
    Aug 20, 2021 at 6:32
  • Hi @Peter a bit of a long shot, after over a year, but I fixed that back in the days myself: github.com/qgis/QGIS/pull/35218/commits/… since it got accepted, I believe it was wrong before.
    – mistapink
    Aug 20, 2021 at 7:42
  • very good approach to fix it! thanks for that
    – Peter
    Aug 20, 2021 at 7:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.