itinero / OpenLR

A C# Implementation of the OpenLR specification using Itinero.
https://www.itinero.tech
Other
18 stars 12 forks source link

Encode a route/referencedLine that spans multiple coordinates #75

Closed emij closed 7 years ago

emij commented 7 years ago

I have been trying to create and encode a line that spans multiple coordinates. My idea was to consider every coordinate along the way as nodes, and build reference-lines between each of them, and in the end combine them (ReferencedLine.Add). This is my method:

private ReferencedLine buildLongLine(Coordinate[] locations) { if (locations.Length > 1) { List lines = new List(); for (int i = 1; i < locations.Length; i++) { var line = coder.BuildLine(locations[i - 1], locations[i]); lines.Add(line); } ReferencedLine first = lines.First(); foreach (ReferencedLine line in lines.Skip(1)) { first.Add(line); } return first; } return null; } The problem is that the line created does not have two coordinates as start and endpoints, rater one coordinate are both and the positive/negative offset value is used, and the add function throws an exception as the two lines do not have any shared vertices.

Do you have any ideas on a better solution for this problem?

I have successfully created a route with a number of coordinates, but I can not see any way to use a route to build a referencedLine so that I can encode it to OpenLR.

xivk commented 7 years ago

I believe this does what you want to do:

https://github.com/itinero/OpenLR/blob/develop/OpenLR/CoderExtensions.cs#L534