Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$rownum returns 0 in field calculator #24790

Closed
qgib opened this issue Jul 19, 2017 · 11 comments
Closed

$rownum returns 0 in field calculator #24790

qgib opened this issue Jul 19, 2017 · 11 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Expressions Related to the QGIS expression engine or specific expression functions High Priority Regression Something which used to work, but doesn't anymore

Comments

@qgib
Copy link
Contributor

qgib commented Jul 19, 2017

Author Name: A L (A L)
Original Redmine Issue: 16891
Affected QGIS version: 2.18.11
Redmine category:field_calculator


In QGIS 2.18.10, the $rownum function allways returns 0 in the field calculator.
As per #20365, it should return 0 in the expression field, but not in the field calculator.
Furthermore, the preview shows 1.
Is this some kind of regression ?


@qgib
Copy link
Contributor Author

qgib commented Jul 19, 2017

Author Name: Giovanni Manghi (@gioman)


I just tested and does now happen here on Linux and Win7 with QGIS 2.18.10. Does it happen with any data of yours? tried without 3rd party plugins?


  • status_id was changed from Open to Feedback
  • priority_id was changed from Normal to High

@qgib
Copy link
Contributor Author

qgib commented Jul 19, 2017

Author Name: A L (A L)


I tried on at least two different layers, but both where postgis layers.
The weird part that might give you a clue : the $rownum function is not in the functions list under "record". It's not in the list at all in fact. It is not shown in red though, so it is somehow recognized.
How do you try without third party plug-ins? Is there some kind of safe mode? (sorry, new user here)

@qgib
Copy link
Contributor Author

qgib commented Jul 20, 2017

Author Name: Giovanni Manghi (@gioman)


A L wrote:

I tried on at least two different layers, but both where postgis layers.
The weird part that might give you a clue : the $rownum function is not in the functions list under "record". It's not in the list at all in fact. It is not shown in red though, so it is somehow recognized.
How do you try without third party plug-ins? Is there some kind of safe mode? (sorry, new user here)

just tried with PostGIS layers on both Linxu and Windows and 2.18.10, works as expected (and starts from 1).

To start without plugins

@qgis --noplugins@

@qgib
Copy link
Contributor Author

qgib commented Jul 25, 2017

Author Name: Giovanni Manghi (@gioman)


  • version was changed from 2.18.10 to 2.18.11

@qgib
Copy link
Contributor Author

qgib commented Aug 7, 2017

Author Name: A L (A L)


OK, I tried without plugins and it still doesn't work.
I almost got it to work when I created a "real" field instead of a "virtual field" in the fiels calculator.
Then the layer went into edit mode, and the new field was correctly computed and displayed. Of course, trying to exit edit mode did not work, since QGis tried to save the changes to the PostGIS layer, which it could obiviously not do.
If I do the exact same thing with a virtual field, it does not work at all.

I still find it very weird that I do not have a "$rownum" function in the functions list :
image

@qgib
Copy link
Contributor Author

qgib commented Aug 7, 2017

Author Name: Giovanni Manghi (@gioman)


A L wrote:

OK, I tried without plugins and it still doesn't work.
I almost got it to work when I created a "real" field instead of a "virtual field" in the fiels calculator.
Then the layer went into edit mode, and the new field was correctly computed and displayed. Of course, trying to exit edit mode did not work, since QGis tried to save the changes to the PostGIS layer, which it could obiviously not do.
If I do the exact same thing with a virtual field, it does not work at all.

I still find it very weird that I do not have a "$rownum" function in the functions list :
image

see attached image. The fact you are finding issues with this and not seeing the $row_num function suggests you have local issues. Try do cleanup (remove the .qgis2 folder, remove qgis registry entries) and try again.


  • 11315 was configured as Screenshot_20170807_134950.png

@qgib
Copy link
Contributor Author

qgib commented Aug 7, 2017

Author Name: Nyall Dawson (@nyalldawson)


Rownum is not available in virtual fields - that's why it's not shown in the expression builder when creating a virtual field.

@qgib
Copy link
Contributor Author

qgib commented Aug 7, 2017

Author Name: A L (A L)


The fact you are finding issues with this and not seeing the $row_num function suggests you have local issues. Try do cleanup (remove the .qgis2 folder, remove qgis registry entries) and try again.

I did that and installed the latest 2.18.11. No change.

Rownum is not available in virtual fields - that's why it's not shown in the expression builder when creating a virtual field.

I tried with a regular field and it's not shown either.
I also tried on a shapefile layer and it's still not there.

My PostGIS layer is a view, not a table, so a regular field does not work. That's where my problem is obviously. I need some way to add a unique id field to a read-only layer.

@qgib
Copy link
Contributor Author

qgib commented Aug 8, 2017

Author Name: Nyall Dawson (@nyalldawson)


Try $id instead of rownum. Regardless of the data source, rownum is not available in virtual fields.

@qgib
Copy link
Contributor Author

qgib commented Aug 8, 2017

Author Name: A L (A L)


Yes, I already tried that, but $id does not work very well when you filter the layer (i.e. not starting at 1, and holes in the series).
I'm a bit surprised that there is not such a function in QGis, since it is quite standard to have numbers on the map and the corresponding description in the legend. That is what one can find on any web map that displays retail stores of a specific brand for instance.

@qgib
Copy link
Contributor Author

qgib commented Sep 25, 2017

Author Name: Giovanni Manghi (@gioman)


A L wrote:

Yes, I already tried that, but $id does not work very well when you filter the layer (i.e. not starting at 1, and holes in the series).
I'm a bit surprised that there is not such a function in QGis, since it is quite standard to have numbers on the map and the corresponding description in the legend. That is what one can find on any web map that displays retail stores of a specific brand for instance.

Please file a feature request instead. Cheers!


  • resolution was changed from to invalid
  • status_id was changed from Feedback to Closed

@qgib qgib closed this as completed Sep 25, 2017
@qgib qgib added Bug Either a bug report, or a bug fix. Let's hope for the latter! High Priority Expressions Related to the QGIS expression engine or specific expression functions Regression Something which used to work, but doesn't anymore labels May 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Expressions Related to the QGIS expression engine or specific expression functions High Priority Regression Something which used to work, but doesn't anymore
Projects
None yet
Development

No branches or pull requests

1 participant