[Qgis-user] QgsMeshLayer not visible on Map using python

noshin prachi noshin.prachi at gmail.com
Thu Dec 14 05:11:09 PST 2023


Dear all,
I am trying to create a map in jupyter from qgis with shape files, map
layer and .dfsu file  in qgis. I have succeeded in adding all the layers
except the .dfsu file( Qgsmeshlayer). This layer is visible on qgis but
when I am trying to create a map from qgis using python , I am not getting
this layer. Can anyone please help me in this regard? I have added
necessary attachments.

Regards,
Noshin Saiyara
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20231214/89e56fb4/attachment-0001.htm>
-------------- next part --------------
import os
import sys
from qgis.gui import QgsLayerTreeMapCanvasBridge, QgsMapCanvas
from qgis.core import*
app=QgsApplication([],True)
app.setPrefixPath("C:\Program Files\QGIS 3.30.0", True)
app.initQgis()
fname = r"C:\Users\FloodMap_SERM_V01.qgz"
project = QgsProject.instance()
project.read(fname)
layer = QgsProject.instance().mapLayersByName("V1054_SWRM_SW_2D PS_LR_Dike_Updt_statBaseFlood Map_Day05")[0]

# get access to the QgsLayerTree
layer_tree_root = QgsProject.instance().layerTreeRoot()  
# find the layer tree layer corresponding to the map layer
layer_tree_layer = layer_tree_root.findLayer(layer.id())  
layer_is_visible = layer_tree_layer.isVisible()
print(layer_is_visible)
groupIndex = 5
myRendererSettings = layer.rendererSettings()
myRendererSettings.setActiveScalarDatasetGroup(groupIndex)
myRendererScalarSettings = myRendererSettings.scalarSettings(groupIndex)
myRendererSettings.setScalarSettings(groupIndex, myRendererScalarSettings)
layer.setRendererSettings(myRendererSettings)
projectInstance = QgsProject.instance()
layoutmanager = projectInstance.layoutManager()
layout = layoutmanager.layoutByName("SW_Day_5") #Layout name
exporter = QgsLayoutExporter(layout)
exporter.exportToImage(r"C:\Users\Day-5.png", QgsLayoutExporter.ImageExportSettings() )
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Map_From_Code.png
Type: image/png
Size: 42824 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20231214/89e56fb4/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: QGIS.png
Type: image/png
Size: 99162 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20231214/89e56fb4/attachment-0003.png>


More information about the QGIS-User mailing list