Thursday, 23 April 2015

qgis - get lat/lon values of every start and end point of polyline


I have a polyline shapefile with 166 different line features. How would one populate the attribute table with x and y values of the start and end points of each line?


enter image description here



Answer



You have your four columns: X-start; Y-start; X-end; Y-end. Using the field calculator for each column update using:


$x_at(0)
$x_at(-1)

$y_at(0)
$y_at(-1)

This asks for the coordinate at the start of the line (the zero) and the end of the line (the negative one). This will provide you with a decimal latitude and longitude, so ensure the columns are floats.


EDIT: Thanks to the_darkside's comments please note this won't work on multi lines, due to the multiple beginnings and ends.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...