[QGIS-Developer] Selecting active mesh layer dataset
Vincent Cloarec
vcloarec at gmail.com
Mon Jan 24 11:39:27 PST 2022
Hi,
if you want to change the rendering settings use :
https://qgis.org/api/classQgsMeshRendererSettings.html#details
and
https://qgis.org/api/classQgsMeshLayer.html#ada9c8d32c90c0a7030f1a20de6435066
Use this QgsMeshRendererSettings class to set your active dataset group.
Regards.
Le lun. 24 janv. 2022 à 15:18, Brian Haynes <bhaynes at herricktechlabs.com> a
écrit :
> Good afternoon,
>
> 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:
>
> QString layerName = "Temperature";
> QgsLayerTree *tree = project->instance()->layerTreeRoot(); //project is QgsProject object
> for ( QgsMapLayer *layer: qmc->layers() ) // qmc is QgsMapCanvas object
>
> QgsLayerTreeNode *node = tree->findLayer(layer->id());
>
> if ( layer->name() == layerName )
> {
> node->setItemVisibilityChecked(true);
>
> } else
> {
> node->setItemVisibilityChecked(false);
> }
>
> }
>
> but its parallel for Mesh Layer subsets doesn't work:
>
> QgsMeshLayer *mesh = new QgsMeshLayer("/path/to/file.nc","MyData","mdal");
> QString dataName = "Temperature";
> for ( int &i: mesh->datasetGroupsIndexes() )
> {
> QgsMeshDatasetIndex did = i;
> QgsMeshDatasetGroupTreeItem *child = tree->childFromDatasetGroupIndex(i);
>
> if ( child->name() == dataName )
> {
> child->setIsEnabled(true);
>
> } else
> {
> child->setIsEnabled(false);
> }
> }
>
> 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.
>
> Brian
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20220124/b80357b7/attachment-0001.html>
More information about the QGIS-Developer
mailing list