[QGIS-Developer] Iterate over layer features in a model - get_feature_by_id

Pedro VenĂ¢ncio pedrongvenancio at gmail.com
Mon May 11 18:07:24 PDT 2020


Hi all,

I'm creating a Model to use with r.viewshed from GRASS, just to avoid the
manual introduction of the coordinates parameter.

https://grass.osgeo.org/grass78/manuals/r.viewshed.html

So, to get the coordinates from a points layer with just one point
(viewpoint), I can get the coordinates with this expression (input layer
has already etrs89_x and etrs89_y as coordinates fields):

concat(attributes( get_feature_by_id(@viewpoints, 0))['etrs89_x'], ',',
attributes( get_feature_by_id(@viewpoints, 0))['etrs89_y'])

This works good:
r.viewshed input=rast_5eb9d9fb8f9a633 *coordinates=88260.003,118942.526*
observer_elevation=1.6 target_elevation=10 max_distance=5000
refraction_coeff=0.14286 memory=1000 -c -r -b
output=output8e7ee6e47dcb4d4fb287eb65c9698cad --overwrite


However, I was trying to give a more generic use to the model, and so I
added the 'Add geometry attributes' algorithm to it. With this, I cannot
get the coordinates anymore with the expression:

concat(attributes( get_feature_by_id(@Add_geometry_attributes_OUTPUT,
0))['xcoord'], ',', attributes(
get_feature_by_id(@Add_geometry_attributes_OUTPUT, 0))['ycoord'])

r.viewshed input=rast_5eb9dac74eca034 *coordinates=0.0,0.0*
observer_elevation=1.6 target_elevation=10 max_distance=5000
refraction_coeff=0.14286 memory=1000 -c -r -b
output=outputfb2e779533a541c4bbcf2bd6f7773eb1 --overwrite

They always pass as 0.0,0.0.

This can be due to the fact that the intermediate result of 'Add geometry
attributes' is a memory layer? Is there any possibility of doing this in
another way?


Another issue is when I have a points layer with several points
(viewpoints). In this case, I tried to use the 'Iterate over this layer'
option, but it always get 0.0,0.0 as coordinates. Of course I need some
incremental operator get_feature_by_id (I also do not know how yet), but it
should work at least to feature id 0, but it does not work. Running it
without the Iterate option, it work for the feature id 0.

Any hints about this?

Here is some sample dataset and the models (the one that is working and the
other that has the 'Add geometry attributes' algorithm and doest not work):

https://cld.pt/dl/download/a2a1a9e0-97d1-4e4d-a0e7-717d5cfcc120/sample_dataset.zip

https://cld.pt/dl/download/5ba46ec3-3084-45d7-8c3b-6cfe6bac6598/models.zip

Thank you very much!

Best regards,
Pedro VenĂ¢ncio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20200512/aec816bf/attachment.html>


More information about the QGIS-Developer mailing list