Timeline for How to get the feature ID of the first feature using PyQGIS?
Current License: CC BY-SA 4.0
8 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jan 16, 2023 at 0:18 | vote | accept | Joel | ||
Jan 10, 2023 at 22:40 | comment | added | Joel | @Mayo: Yes, that's exactly it. As I said, I haven't used Python before, so when I'm faced with all commands I'm not always sure what belongs to QGIS and what belongs elsewhere, and where I should look in that case. | |
Jan 10, 2023 at 21:34 | comment | added | Mayo |
The getFeature() returns a feature iterator, (here what's a python iterator) so you can use the next() function to get each item at a time.
|
|
Jan 10, 2023 at 21:27 | comment | added | Mayo |
Thank you @Joel and MrXsquared!! Joel are you talking about where to find info about commands like next() ?
|
|
Jan 10, 2023 at 18:19 | comment | added | Joel | Thank you! It works, and with @Mayo's suggestion even more elegantly so! My first thought was also to use .getFeatures(), but I didn't know how to index that. I couldn't find it in the PyQGIS documentation. Where should I look for documentation on these commands? | |
Jan 10, 2023 at 18:09 | comment | added | MrXsquared | @Mayo worth posting it as the more elegant answer ;) | |
Jan 10, 2023 at 18:07 | comment | added | Mayo |
Or just first_id = next(source.getFeatures()).id() .
|
|
Jan 10, 2023 at 17:35 | history | answered | MrXsquared | CC BY-SA 4.0 |