2

I want to get real line segment dataset to do an experiment. So I searched it, and found the site that includes the real data: http://www.wsdot.wa.gov/mapsdata/geodatacatalog/

From this, I downloaded railroad data and opened it with QGIS. I want to get the end points of each line segment (or feature) in the data. When I click the one feature in vector layer, I can see the firstX, firstY, lastX and lastY in 'Identify Results' window. I think this information is what I needed.

However, I cannot find the way to export this information to .csv-file or text file. I searched, but all of these solutions are not working for me:

How can I export end points of each line segment in such dataset?

2
  • 2
    Welcome to SE.GIS forum. Which GIS software you are using?
    – Sunil
    Commented Jun 12, 2013 at 11:56
  • Hi. I searched the program and Quantum GIS Desktop is opensource project. So I chosen it to handle Geographic Information.
    – NoSyu
    Commented Jun 12, 2013 at 13:18

1 Answer 1

12

A very simple solution is as follows:

  1. Open the attribute table and enable editting (yellow pencil button at the bottom of the dialog box)
  2. Click the calculate fields button (calculator icon at the bottom) and create a new field for firstX (possibly changing the output field type to decimal and setting the width and precision) and select 'xat' from the Geometry function list and change the expression to read: xat(0). This will give you the x location of the first point in your line.
  3. Repeat the above for yat(0)
  4. Repeat the above for xat(-1) to get the last x coordinate
  5. Repeat the above for yat(-1) to get the last y coordinate
  6. Save your edits
  7. Export (save as) your file to CSV

There are other approaches, but this one gives you a column for each x or y coordinate for the first and last points in your line and nothing more - which is what I understand to be your request. It also requires no coding.

2
  • Thanks a lot! It works correctly! But I have other question. When I do it, I see error meesage. 'An error occured while evaluating the calculation string: Index is out of range'. Then do I handle exceptions in 'Expression' field?
    – NoSyu
    Commented Jun 12, 2013 at 13:17
  • I think you'd only get an index out of range error if you had a line with only one vertex. I'd check your geometry for errors first. Commented Jun 12, 2013 at 15:14

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.