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?

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])

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.