Bug report #14082

area calculation in Field Calculator is depending on Output field type

Added by Richard Duivenvoorde almost 9 years ago. Updated over 5 years ago.

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?

area_calculations.png - screendump showing two virtual fields (208 KB) Richard Duivenvoorde, 2016-01-10 10:44 AM

qgisprov.zip - test data epsg:28992 (63.6 KB) Richard Duivenvoorde, 2016-01-10 10:44 AM


Related issues

Related to QGIS Application - Bug report #13209: area not calculated correctly with OTF on Closed 2015-08-11
Related to QGIS Application - Bug report #12622: In virtual fields $area function computes always values u... Closed 2015-04-21

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 over 5 years ago

  • Resolution set to end of life
  • Status changed from Open to Closed

Also available in: Atom PDF