I have this code to download and create a mesh data for wind velocities from a weather model. However, I am having issues with the wind barbs. I have to manually activate and click on the meshvectors Vectors icon on the right side of the general Datasets tab in the layer properties to enable the vector symbology and create the wind barbs.
Is there a way to automate it with code?
At the moment, I am using QGIS-LTR.
import os import ssl import urllib.request import bz2 from qgis.core import ( QgsProject, QgsMeshLayer, QgsMeshRendererSettings, QgsMeshRendererVectorSettings, QgsMeshRendererVectorWindBarbSettings ) from qgis.PyQt.QtGui import QColor # Bypass SSL verification ssl._create_default_https_context = ssl._create_unverified_context # === FILE URLS === u_url = "https://opendata.dwd.de/weather/nwp/icon-eu/grib/00/u_10m/icon-eu_europe_regular-lat-lon_single-level_2025061200_000_U_10M.grib2.bz2" v_url = "https://opendata.dwd.de/weather/nwp/icon-eu/grib/00/v_10m/icon-eu_europe_regular-lat-lon_single-level_2025061200_000_V_10M.grib2.bz2" # === FILE PATHS === temp_dir = "/tmp" u_bz2 = os.path.join(temp_dir, "icon_u10m.bz2") v_bz2 = os.path.join(temp_dir, "icon_v10m.bz2") u_grib = os.path.join(temp_dir, "icon_u10m.grib2") v_grib = os.path.join(temp_dir, "icon_v10m.grib2") uv_grib = os.path.join(temp_dir, "icon_uv_combined.grib2") # === DOWNLOAD & DECOMPRESS === urllib.request.urlretrieve(u_url, u_bz2) urllib.request.urlretrieve(v_url, v_bz2) with bz2.open(u_bz2, 'rb') as src, open(u_grib, 'wb') as dst: dst.write(src.read()) with bz2.open(v_bz2, 'rb') as src, open(v_grib, 'wb') as dst: dst.write(src.read()) # === COMBINE INTO ONE GRIB2 FILE === with open(uv_grib, 'wb') as f_out: for f in [u_grib, v_grib]: with open(f, 'rb') as f_in: f_out.write(f_in.read()) # === LOAD MESH LAYER === mesh_layer = QgsMeshLayer(uv_grib, "10m Wind Mesh", "mdal") if not mesh_layer.isValid(): raise Exception("Mesh layer failed to load") # === ADD TO "Weather data" GROUP === root = QgsProject.instance().layerTreeRoot() group = root.findGroup("Weather data") QgsProject.instance().addMapLayer(mesh_layer, addToLegend=False) if group: group.addLayer(mesh_layer) print("Added wind mesh to 'Weather data' group.") else: root.insertLayer(0, mesh_layer) print("'Weather data' group not found. Added to root.") # === ACTIVATE VECTOR DATASET GROUP & ENABLE WIND BARBS === provider = mesh_layer.dataProvider() group_count = provider.datasetGroupCount() vector_group_index = None # Find first vector dataset group for i in range(group_count): meta = provider.datasetGroupMetadata(i) if meta.isVector(): print(f"Found vector group {i}: {meta.name()}") vector_group_index = i break if vector_group_index is None: raise Exception("No vector dataset group found.") 
u_urlandv_urlgetting 404 Not Found