[QGIS-Developer] RES: Mesh layer

Jorge Almerio jorgealmerio at yahoo.com.br
Sun Apr 26 08:50:01 PDT 2020


Many thanks!

 

You saved me!!

 

De: Vincent Cloarec [mailto:vcloarec at gmail.com] 
Enviada em: Sunday, April 26, 2020 11:35 AM
Para: Jorge Almerio <jorgealmerio at yahoo.com.br>
Cc: qgis-developer <qgis-developer at lists.osgeo.org>; qgis-developer-bounces at lists.osgeo.org
Assunto: Re: [QGIS-Developer] Mesh layer

 

Hi,

 

With QGIS master you can use  <https://qgis.org/pyqgis/master/core/QgsMeshLayer.html#qgis.core.QgsMeshLayer.updateTriangularMesh> updateTriangularMesh.

Before, there is a workaround that consists to just call  <https://qgis.org/pyqgis/3.12/core/QgsMeshLayer.html#qgis.core.QgsMeshLayer.createMapRenderer> createMapRenderer without using the renderer.

 

Vincent

 

Le sam. 25 avr. 2020 à 11:32, Jorge Almerio <jorgealmerio at yahoo.com.br <mailto:jorgealmerio at yahoo.com.br> > a écrit :

Hi everyone,

Sometimes I got "NaN" return when trying to get scalar value to a point from a Mesh layer. I guess the reason is that it was not rendered previously as said in the documentation.

< <https://qgis.org/api/classQgsMeshLayer.html#a07cb62f04b64979500d3873afb580216> https://qgis.org/api/classQgsMeshLayer.html#a07cb62f04b64979500d3873afb580216>
QgsMeshDatasetValue:
"Note:
    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"

When I turn ON and OFF the loaded mesh layer in the active project it Works!

I would like to know if there is a proper way to render the mesh layer, before get values.

Below is my code:

proj = QgsProject.instance()
layerPto = iface.activeLayer() # a Point layer
layer = proj.mapLayersByName("mesh01")[0] # a Mesh layer
dataset = QgsMeshDatasetIndex(0,0)
for feat in layerPto.getSelectedFeatures():
    ptoGeo = feat.geometry()
    pt = ptoGeo.asPoint()
    value = layer.datasetValue(dataset, pt).scalar()
    print('elevation={}'.format(value))



_______________________________________________
QGIS-Developer mailing list
 <mailto:QGIS-Developer at lists.osgeo.org> QGIS-Developer at lists.osgeo.org
List info:  <https://lists.osgeo.org/mailman/listinfo/qgis-developer> https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe:  <https://lists.osgeo.org/mailman/listinfo/qgis-developer> https://lists.osgeo.org/mailman/listinfo/qgis-developer

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20200426/7e753d0e/attachment-0002.html>


More information about the QGIS-Developer mailing list