Bug report #14082
area calculation in Field Calculator is depending on Output field type
Status: | Closed | ||
---|---|---|---|
Priority: | Normal | ||
Assignee: | - | ||
Category: | Vectors | ||
Affected QGIS version: | master | Regression?: | No |
Operating System: | Easy fix?: | No | |
Pull Request or Patch supplied: | No | Resolution: | end of life |
Crashes QGIS or corrupts data: | No | Copied to github as #: | 22092 |
Description
Not sure how much this is related to #13209
But when I use the Field calculator to create a virtual field with the area of some polygons, my first try resulted in 80% NULL values.
On further testing the results seem ok. Only difference I did was changing the Output field type from Whole number (integer) to Decimal number (real)
To test, (see screendump for output with both options)
- open attached shp file with the 12 provinces of The Netherlands
- set project crs to epsg:28992 + OTF, and data crs is also epsg:28992 (Amersfoort)
- now open the Field calculator and create a new field / create virtual field and call it 'area'
- as Expression use $area
- click OK: as you can see only 3 polygons have an area value, rest has NULL
- now open the Field calculator again and create a new field / create virtual field and call it 'area2'
- BUT change the default output fieldtype to Decimal !!
- as Expression use $area
- click OK: now all provinces have an area value!
?? what goes wrong here. Or at least how should a normal user find out this behaviour?
Maybe after fixing, also change the default value of output to Real/Float?
Related issues
History
#1 Updated by Richard Duivenvoorde almost 9 years ago
Update: I found out that it is apparently a integer overflow problem. That is, only the 3 smallest provinces have a value...
And if I change the expression to $area/(1000*1000) (so from meters to square km), all give a valid result EVEN when I set the output type to integers. Off course because then the values are smaller.
But I also checked the error messages, but did not see anything.
Proposal:
- give a clear/descent error message when a integer overflow takes place during calculation (popup?)
- make floats the default when you create an expression (or text), so this problem does not occur for innocent users like me :-)
#2 Updated by Giovanni Manghi almost 9 years ago
- Status changed from Open to Feedback
Hi Richard,
related also to #12622 ?
#3 Updated by Giovanni Manghi over 8 years ago
- Status changed from Feedback to Open
- Category changed from Virtual Fields to Vectors
It is still true on the latest master and from what I see is not only related to virtual fields.
#4 Updated by Giovanni Manghi over 7 years ago
- Easy fix? set to No
- Regression? set to No
#5 Updated by Giovanni Manghi almost 6 years ago
- Resolution set to end of life
- Status changed from Open to Closed
End of life notice: QGIS 2.18 LTR
Source:
http://blog.qgis.org/2019/03/09/end-of-life-notice-qgis-2-18-ltr/