I'd like to calculate the orientation of line segments relative to north direction using open source tools. Which tools or functions would you recommend?
|
|
To get an angle from a line you just need to find the angle of the normalized direction. The Atan2 function is available on every computing platform I have used, even calculators. The basic idea is to get a normalized vector for the direction of that line then get the angle.
For your case since you need it to be north (+y hopefully) relative and possibly clockwise you could reverse the inputs to Atan2 like so:
And if you need counter-clockwise negate the result of Atan2. For degrees just multiply by 180 then divide by
Edited: to correct an error for counter-clockwise. Note: only works if |
|||||
|
|
To muddy the water a bit: what projection are your line segments in? The answer depends! If you're it's a Mercator projection, Dandy's answer works. (In a Mercator, lines are rhumb -- by definition, holding the same compass direction for their length.) In general, however, a line on a map will not correspond to the same compass direction (azimuth) along its entire length -- so your question doesn't always have an answer. It might be acceptable for you to just assume your lines are rhumb, or to calculate two directions -- one at each endpoint, or to compromise and calculate the direction at the midpoint . . . . |
|||||
|
|
GRASS GIS (http://grass.osgeo.org/) offers native directed graphs (i.e. vector lines). See "Vector network" screenshots here. Furthermore, there is the m.cogo tool included. |
|||
|