2

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. http://hub.qgis.org/wiki/17/List_of_Field_Calculator_Functions

2
  • 2
    Did you use xat(0) and xat(-1)?
    – underdark
    Commented Mar 23, 2012 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
    Commented Apr 26, 2012 at 9:12

1 Answer 1

2

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.

2
  • 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
    Commented Mar 25, 2012 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
    Commented Mar 25, 2012 at 14:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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