Bug report #8457

$length fails silently for polygons

Added by Jonathan Moules about 7 years ago. Updated about 7 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:duplicate
Crashes QGIS or corrupts data:No Copied to github as #:17225

Description

I have a polygon. If I label it with the following it works fine.
'polygon' || $area

However, if I change it to the below, using $length, I get absolutely no output, not even the string.
'polygon' || $length

Yes, I know I should use $perimeter. The bug is that QGIS isn't telling me as the user that. Worse, it's not rendering anything that is still valid (the string).
Both the "Output preview" and the on-map labels are completely empty.

windows 7 x64 - QGIS a13cdf8


Related issues

Duplicates QGIS Application - Bug report #8369: Null propagation of fields in expression based labelling Closed 2013-07-27

History

#1 Updated by Nathan Woodrow about 7 years ago

$legnth is returning NULL. String + NULL = NULL.

#2 Updated by Jonathan Moules about 7 years ago

Also field calculator does the exact same thing, so it's not labelling specific.

Nathan Woodrow wrote:

$legnth is returning NULL. String + NULL = NULL.

Maybe it should be converted to:
String + NULL = String.

After all, 1 + 0 = 1, and String + '' = String. I'm aware that NULL != 0 or '' but I think the premise holds :-)

#3 Updated by Nathan Woodrow about 7 years ago

We have had this talk before. It sounds great but like you said NULL != 0 or '' so we are not going to treat NULL as such. It's not going to change at the moment, not for 2.0 anyway.

#4 Updated by Nathan Woodrow about 7 years ago

  • Category deleted (Labelling)

#5 Updated by Jonathan Moules about 7 years ago

Ah, Ok.
I think outside of the Operator functions, the user likely isn't going to care about the difference between NULL, 0 and '' and they can be treated as the same. But then I come from a PHP background so... heh.

#6 Updated by Giovanni Manghi about 7 years ago

  • Category set to Vectors
  • Status changed from Open to Feedback

Can we change this to something like "add a warning when using the $length function with polygons"?

#7 Updated by Jonathan Moules about 7 years ago

I'm not sure it should be renamed to that as it's not unique to length.

If I try "$x" and "$y" with a polygon they also fail (though I'd argue that's a problem with the calculator - I expected it to return the centroid, but that's neither here nor there for this). $geometry is also blank (no help so not sure what it's supposed to do).
I imagine that area\\length\\perimeter all become blank when used against a POINT feature.

So the issue is more generic than a single function.

#8 Updated by Giovanni Manghi about 7 years ago

we can rename/rephrase the ticket anyway as a feature request like "make the FC handle better some cases"

#9 Updated by Nathan Woodrow about 7 years ago

  • Resolution set to duplicate
  • Status changed from Feedback to Closed

In that case it's the same as #8369

Also available in: Atom PDF