I am trying to include XY coordinates in the attribute tables of several of my vector files; they are line and polygon files. I have tried two methods; first I used $x and $y in the field calculator (which I've used before and worked well). When this returned NULL, I tried saving the file as a .CSV and using the methods described in this post:

Get list of coordinates for points in a layer?
(top answer describes using "GEOMETRY=AS_XY" in the 'save as' window).

Neither of these methods are working; they aren't returning errors, they just aren't returning values. I have tried re-importing my shapefiles, I have changed the CRS they occupy to try and force QGIS to recognize the location with no luck.

I'm using Windows 7, QGIS 1.8.0 Lisboa.

  • QGIS version, OS and a sample file are needed to be provided here if you really want any help. – SS_Rebelious Aug 23 '13 at 20:00
  • Right... sorry. Windows 7, 1.8.0 Lisboa. – HHains Aug 23 '13 at 20:01
  • Please share the problematic file. I've used these functions often and never encountered any such problem. – underdark Aug 25 '13 at 16:15
  • 3
    What kind of geometry do you have? $x and $y only works for point layers. – AndreJ Aug 25 '13 at 19:08
  • 1
    That would explain it. The layers are mostly polygons. I suppose an easy fix would be to make a points layer to represent the polygon layer and determine the coordinates from that. – HHains Aug 26 '13 at 14:33

The $x and $y values only work for point layers.

Create a layer for polygon centroids and then that will give the x and y values using the $x and $y commands.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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