# How to make a polyline using distance and direction? [closed]

QGIS newbie here. Given a table of values for distance (km) and direction (degrees), I want to create a polyline starting from a coordinate (lon, lat). I am going to use this to backtrack the origin of a particle in the ocean. My question is very similar to this:

The problem is that I do not know how to use PyQGIS.

## closed as off-topic by Vince, Andre Silva, Mapperz♦Jan 4 '17 at 14:48

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – Vince, Andre Silva, Mapperz
If this question can be reworded to fit the rules in the help center, please edit the question.

• Which is the format of your data (.xls, .csv, etc.) and where are they placed (in terms of UTM zone)? – mgri Jan 4 '17 at 10:28
• Do you have a starting coordinate to work from? – Knightshound Jan 4 '17 at 10:38
• Check out the CAD tools plugin, now part of the core plugins set as advanced digitze toolbox: youtube.com/watch?v=QsjmLa16obs – HeikkiVesanto Jan 4 '17 at 15:36

With the limited info of the question I have assumed that the data is in a csv table with the start_X and start_Y in separate columns. This should work then if you are using OSGB36 or any coordinate systems that are in meters and is not a pyqgis answer.

In theory this is simple vector movement. In my image below you have your starting point. All you need to work out is which direction the line is going and then add/subtract the distance from either X or Y which will give you your end point.

EG: If the direction is between 90 and 180 degrees then the distance needs to be added to the X coordinate and subtracted from the Y coordinate I'm not sure how to do this in excel but I think a nice easy way to populate that table (if you have a lot of data), is to add it to QGIS (save the table as a shapefile first), create 2 new columns (end_X, end_Y) and using the field calculator on end_X column write something like:

``````CASE
WHEN degrees >= 0 and degrees < 90 THEN start_X + distance
WHEN degrees >= 90 and degrees < 180 THEN start_X + distance
WHEN degrees >= 180 and degrees < 270 THEN start_X - distance
WHEN degrees >= 270 and degrees <= 359 THEN start_X - distance
END
``````

And likewise with the end_Y column:

``````CASE
WHEN degrees >= 0 and degrees < 90 THEN start_Y + distance
WHEN degrees >= 90 and degrees < 180 THEN start_Y - distance
WHEN degrees >= 180 and degrees < 270 THEN start_Y - distance
WHEN degrees >= 270 and degrees <= 359 THEN start_Y + distance
END
``````

Then open up the toolbox (under Processing) and search for Points layer from table to create a new point layers of your end points.

You can stop here as you've found your end point, but if you really need the lines then create another new column in the table and concatenate the four columns start_X, start_y, end_x, end_y with the text below to create a new column with the geometry in WKT format:

`````` concat('LINESTRING(',start_x, start_y, ',', end_x, end_y,')')
``````

save the shapefile as csv then add the table again to QGIS, this time using this new column as the geometry (remember to set geometry definition to Well known text(WKT))

This is definitely a long winded version which python could make a lot easier but sadly don't know that. Remember that if you are working backwards to find the origin then the adding and subtracting of the X Y coordinates will need to be reversed.

• Thank you very much. This is exactly what I was looking for! – John Jan 11 '17 at 9:38