<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Good afternoon,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I am developing a QGIS application in C++ and am looking to overlay weather data stored in NetCDF files as mesh layers.  Each file has several variables that can be displayed; however it only displays one variable or dataset (always the first one in alphabetical
 order) and I'm not sure how to make it so I can choose which variable I want displayed.  For an entire layer I know I can call the layer tree node like this:</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<pre class="lang-py s-code-block"><code class="hljs language-python">QString layerName = <span class="hljs-string">"Temperature"</span>;
QgsLayerTree *tree = project->instance()->layerTreeRoot(); //project <span class="hljs-keyword">is</span> QgsProject <span class="hljs-built_in">object</span>

<span class="hljs-keyword">for</span> ( QgsMapLayer *layer: qmc->layers() ) // qmc <span class="hljs-keyword">is</span> QgsMapCanvas <span class="hljs-built_in">object</span>
    
    QgsLayerTreeNode *node = tree->findLayer(layer-><span class="hljs-built_in">id</span>());
    
    <span class="hljs-keyword">if</span> ( layer->name() == layerName )
    {
       node->setItemVisibilityChecked(true);

    } <span class="hljs-keyword">else</span>
    {
       node->setItemVisibilityChecked(false);
    }

}</code></pre>
but its parallel for Mesh Layer subsets doesn't work:</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<pre class="lang-py s-code-block"><code class="hljs language-python">QgsMeshLayer *mesh = new QgsMeshLayer(<span class="hljs-string">"/path/to/file.nc"</span>,<span class="hljs-string">"MyData"</span>,<span class="hljs-string">"mdal"</span>);
QString dataName = <span class="hljs-string">"Temperature"</span>;

<span class="hljs-keyword">for</span> ( <span class="hljs-built_in">int</span> &i: mesh->datasetGroupsIndexes() )
{
   QgsMeshDatasetIndex did = i;
   QgsMeshDatasetGroupTreeItem *child = tree->childFromDatasetGroupIndex(i);
   
   <span class="hljs-keyword">if</span> ( child->name() == dataName )
   {
      child->setIsEnabled(true);

   } <span class="hljs-keyword">else</span>
   {
      child->setIsEnabled(false);
   }
}</code></pre>
I've also tried to set the layer rendering for datasets, but it seems to pertain to the entire file (mesh->datasetGroupCount > mesh->datasetCount; the renderer only pertains to the dataset (count = 1).  This would be helpful to figure out as setting the renderer
 for different types of data (vectors for wind, contours for pressure, etc) is the end goal of this application, and would be an upgrade from having to create multiple shapefiles/rasters for this data.  There doesn't seem to be many examples out there for mesh
 layer use outside of the QGIS console, not even for PyQGIS developers.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Brian</div>
</body>
</html>