Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to use the xat(n) and yat(n) in the Field Calculator but can't get them to work. Does anybody have an example how to use them? I need the start and end coordinates for line segments, does anybody know how to get those?

In the below list the xat() and yat() functions are listed.

share|improve this question
Did you use xat(0) and xat(-1)? – underdark Mar 23 '12 at 15:28
I have the same problem like Jonas in Qgis 1.7.3. Do somebody already now how to solve it? thanks for any adivce – Jan Apr 26 '12 at 9:12

You'll need to create a new field for each x/y point, and use the correct index number to return the position along the line. Index 0 is the starting point, and (as far as I can tell) any negative number would return the last point.

xat(0) in the 'expression' box, no '=' sign beforehand, will fill the new field with the x coordinate of the first point along the line, yat(0) likewise for the y coordinate. Use xat(-1) for the last point along the line.

Using a consistent terminology for your columns is a good idea - x_start / y_start, for example.

share|improve this answer
When trying the above I get the Syntax Error with: "Invalid expression syntax. The error message of the parser is: 'syntax error, unexpected '(', expecting $end'" I'm trying with a normal ESRI Shapefile type Line. – jonas Mar 25 '12 at 11:13
@Jonas - you're right - it worked for me then I realised I'm using 1.9; trying it with 1.7.4 gave me the same error (on OSX 10.7)! Does anyone know if xat(n) is somehow available in 1.7.x? – Simbamangu Mar 25 '12 at 14:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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