[GIS] Drawing lines from two points in CSV using QGIS

csvlinepointqgis

I have a CSV file where one line looks like this:

Duration, user, lat-start, long-start, lat-end, long-end
298, Casual,38.9101,-77.0444,38.91554,-77.03818

Each row in the CSV has two points and I need to draw a line between those two points for each row.

How can I do this using QGIS 1.8.0?

I have tried using the delimited text file plug-in, but it just draws points and has no line option from what I can see.

Best Answer

With a bit of text processing (maybe in Excel), you can bring your data into this form:

Duration;user;wkt
298;Casual;LINESTRING(-77.0444 38.9101,-77.03818 38.91554)

which can be interpreted by QGIS as well known text (WKT) using Add delimited text layer.

Note that you need blanks and comma as delimiters for lon&lat values and linestring members, and lon values have to be first. In the dialogue, only check semicolon as column delimiter.

Applying EPSG:4326 as CRS , you end up at New Hampshire Avenue Nordwest in Washington DC.


EDIT

this one works from your second example:

seconds-total;Subscription-Type;gis-data
298;Casual;LINESTRING(-77.0444 38.9101,-77.03818 38.91554)
27926;Casual;LINESTRING(-77.0444 38.9101,-77.03818 38.91554)
214;Casual;LINESTRING(-77.0511 38.8573,-77.051516 38.848441)
960;Subscriber;LINESTRING(-77.024649 38.936043,-77.012289 38.915417)
378;Subscriber;LINESTRING(-77.04062 38.917761,-77.0471 38.9054)
2085;Subscriber;LINESTRING(-77.041606 38.904742,-76.9862 38.8803)
441;Subscriber;LINESTRING(-77.094875 38.88786,-77.10108 38.884616)
456;Subscriber;LINESTRING(-77.023086 38.8997,-77.022155 38.912719)