I just stumbled across something weird: I had point-data in EPSG:3059 and wanted to add the coordinates to the attribute table using $x resp. $y - which returned NULL. x($geometry) on the other hand worked out.

Which leads me to the question: What exactly is the difference between the two functions?

closed as off-topic by Erik, LaughU, Vince, csk, HDunn Aug 21 at 15:14

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – Erik, LaughU, Vince, csk, HDunn
If this question can be reworded to fit the rules in the help center, please edit the question.

  • it returned NULL – Erik Aug 19 at 12:30
  • 1
    Are you working on non-point features, such as lines? x($geometry) can take centroids, while $x cannot. – Kazuhito Aug 19 at 12:34
  • Nope, it's point data, though styled as ellipsoids. – Erik Aug 19 at 12:35
  • maybe it's multipoint? – vagvaf Aug 19 at 12:42
  • 1
    Okay, following advice by @ahmadhanb I loaded the data into an empty GIS and discovered that the person who created the data actually created ellipsoids instead of points styled as ellipsoids - so no wonder why $x didn't work out. – Erik Aug 20 at 7:54

Since you are dealing with point data, the results of both expressions of $x and x($geometry) are identical. Same applied to $y and y($geometry). I tested the behavior of both expressions on my point grid data and I found that both them produced the same results as you can see below:

enter image description here

In the table above the coordinates in X and Y fields were calculated using the expressions $x and $y, respectively, whereas x($geometry) and y($geometry) were used to calculate the coordinates in X1 and Y1 fields, respectively.

As you can see, both produced the same results. For your reference I used QGIS 3.4.11-Madeira, and the CRS of the data is WGS 84 / UTM zone 54N (EPSG:32654).

I am not sure why you got NULL results when you used $x and $y but successful results with x($geometry) and y($geometry), maybe something wrong happened in the QGIS project. My advice is to try loading the point data into a new QGIS project and try again.

  • Thanks a lot for your help - the issue was that my colleague created polygons without me knowing about it - so $x naturally couldn't work out. – Erik Aug 20 at 8:00
  • @Erik That makes sense of why $x didn’t work. – ahmadhanb Aug 20 at 8:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.