1

I am a novice about Geographic Information Systems. Now 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 Quantum GIS. 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:

Getting list of coordinates for points in layer using QGIS?

How to get X and Y coordinate values of the map?

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

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

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.

  • 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 Jun 12 '13 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. – MappaGnosis Jun 12 '13 at 15:14

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.