[QGIS-Developer] Can't get values from QgsMeshLayer

Enrico Ferreguti enricofer at gmail.com
Wed Feb 3 06:59:36 PST 2021


I miss the attachement

Il giorno mer 3 feb 2021 alle ore 15:58 Enrico Ferreguti <
enricofer at gmail.com> ha scritto:

> I'm trying to write a simple function for retrieving wind speed and
> direction at a specified moment from a given grib file readable as mesh
> layer the prototype script is the following:
>
> mesh = QgsMeshLayer("[path to the attached
> grib]/20210202_211414_ICON_EU_P06_.grb2","test","mdal")
> #mesh = iface.activeLayer()
> p1 = QgsPointXY(1.60301, 38.38453)
>
> ds_group_index = 1
>
> for g in mesh.datasetGroupsIndexes():
>     print ("MESH GROUP:", g,
> mesh.datasetGroupMetadata(mesh.datasetIndexAtRelativeTime(h0,g)).name())
>
> for i in range(mesh.dataProvider().datasetCount(ds_group_index)):
>     meta =
> mesh.dataProvider().datasetMetadata(QgsMeshDatasetIndex(ds_group_index, i))
>     t = meta.time()
>     dataset = QgsMeshDatasetIndex(ds_group_index, i)
>     value = mesh.datasetValue(dataset, p1)
>     print ("VALUES P1",t,value.scalar(),value.x(),value.y())
>
> When I run the script I can get dataset names from metadata but I'getting
> Nan as values
> I verified that the grib is loadable in mapcanvas and the sample point is
> within grib extent.
> I read the note in api (
> https://qgis.org/api/classQgsMeshLayer.html#a76a7ec072b4acaf45c1a10f5872c4948)
> "It uses previously cached and indexed triangular mesh and so if the layer
> has not been rendered previously (e.g. when used in a script) it returns
> NaN value" so I tried to process an already loaded mesh (decomment line 2)
> without luck.
>
> Is there anybody who can help me finding what I'm doing wrong? Thanks.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20210203/d84bdcc9/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 20210202_211414_ICON_EU_P06_.grb2
Type: application/octet-stream
Size: 842284 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20210203/d84bdcc9/attachment-0001.obj>


More information about the QGIS-Developer mailing list