public void EncodedReferencedPointAlongLineLocation() { // build a graph to encode from. var tags = new TagsTableCollectionIndex(); var graphDataSource = new DynamicGraphRouterDataSource <LiveEdge>(tags); uint vertex1 = graphDataSource.AddVertex(49.60597f, 6.12829f); uint vertex2 = graphDataSource.AddVertex(49.60521f, 6.12779f); graphDataSource.AddEdge(vertex1, vertex2, new LiveEdge() { Distance = 10, Forward = true, Tags = tags.Add(new TagsCollection( Tag.Create("BAANSUBSRT", "VBD"), Tag.Create("WEGBEHSRT", "R"), Tag.Create("WEGNUMMER", string.Empty), Tag.Create("RIJRICHTNG", "N"))) }, null); graphDataSource.AddEdge(vertex2, vertex1, new LiveEdge() { Distance = 10, Forward = false, Tags = tags.Add(new TagsCollection( Tag.Create("BAANSUBSRT", "VBD"), Tag.Create("WEGBEHSRT", "R"), Tag.Create("WEGNUMMER", string.Empty), Tag.Create("RIJRICHTNG", "N"), Tag.Create("HECTOLTTR", string.Empty))) }, null); // create a referenced location and encode it. var graph = new BasicRouterDataSource <LiveEdge>(graphDataSource); var referencedPointAlongLineLocation = new ReferencedPointAlongLine(); referencedPointAlongLineLocation.Route = new ReferencedLine(graph); referencedPointAlongLineLocation.Route.Edges = new LiveEdge[1]; referencedPointAlongLineLocation.Route.Edges[0] = new LiveEdge() { Distance = 10, Forward = true, Tags = tags.Add(new TagsCollection( Tag.Create("BAANSUBSRT", "VBD"), Tag.Create("WEGBEHSRT", "R"), Tag.Create("WEGNUMMER", string.Empty), Tag.Create("RIJRICHTNG", "N"), Tag.Create("HECTOLTTR", string.Empty))) }; referencedPointAlongLineLocation.Route.EdgeShapes = new GeoCoordinateSimple[1][]; referencedPointAlongLineLocation.Route.EdgeShapes[0] = new GeoCoordinateSimple[0]; referencedPointAlongLineLocation.Route.Vertices = new long[2]; referencedPointAlongLineLocation.Route.Vertices[0] = vertex1; referencedPointAlongLineLocation.Route.Vertices[1] = vertex2; referencedPointAlongLineLocation.Latitude = (49.60597f + 49.60521f) / 2f; referencedPointAlongLineLocation.Longitude = (6.12829f + 6.12779f) / 2f; // encode location. var encoder = new PointAlongLineEncoder(); var mainEncoder = new ReferencedNWBEncoder(graph, null); var referencedEncoder = new ReferencedPointAlongLineEncoder(mainEncoder, encoder); var location = referencedEncoder.EncodeReferenced(referencedPointAlongLineLocation); // test result. Assert.IsNotNull(location); Assert.AreEqual(SideOfRoad.OnOrAbove, location.SideOfRoad); Assert.AreEqual(Orientation.NoOrientation, location.Orientation); Assert.AreEqual(50, location.PositiveOffsetPercentage.Value, 0.5f); Assert.AreEqual(49.60597f, location.First.Coordinate.Latitude); Assert.AreEqual(6.12829f, location.First.Coordinate.Longitude); Assert.AreEqual(91, location.First.DistanceToNext); Assert.AreEqual(FormOfWay.SlipRoad, location.First.FormOfWay); Assert.AreEqual(FunctionalRoadClass.Frc0, location.First.FuntionalRoadClass); Assert.AreEqual(FunctionalRoadClass.Frc0, location.First.LowestFunctionalRoadClassToNext); Assert.AreEqual(49.60521f, location.Last.Coordinate.Latitude); Assert.AreEqual(6.12779f, location.Last.Coordinate.Longitude); // TODO: encode location with a point on or at the first and last points. }
public void EncodeReferencedPointAlongLineLocation() { // build a graph to encode from. var tags = new TagsTableCollectionIndex(); var graphDataSource = new DynamicGraphRouterDataSource <LiveEdge>(tags); uint vertex1 = graphDataSource.AddVertex(49.60597f, 6.12829f); uint vertex2 = graphDataSource.AddVertex(49.60521f, 6.12779f); graphDataSource.AddEdge(vertex1, vertex2, new LiveEdge() { Distance = 10, Forward = true, Tags = tags.Add(new TagsCollection(Tag.Create("highway", "tertiary"))) }, null); graphDataSource.AddEdge(vertex2, vertex1, new LiveEdge() { Distance = 10, Forward = false, Tags = tags.Add(new TagsCollection(Tag.Create("highway", "tertiary"))) }, null); // create a referenced location and encode it. var graph = new BasicRouterDataSource <LiveEdge>(graphDataSource); var referencedPointAlongLineLocation = new ReferencedPointAlongLine(); referencedPointAlongLineLocation.Route = new ReferencedLine(graph); referencedPointAlongLineLocation.Route.Edges = new LiveEdge[1]; referencedPointAlongLineLocation.Route.Edges[0] = new LiveEdge() { Distance = 10, Forward = true, Tags = tags.Add(new TagsCollection(Tag.Create("highway", "tertiary"))) }; referencedPointAlongLineLocation.Route.EdgeShapes = new GeoCoordinateSimple[1][]; referencedPointAlongLineLocation.Route.EdgeShapes[0] = new GeoCoordinateSimple[0]; referencedPointAlongLineLocation.Route.Vertices = new long[2]; referencedPointAlongLineLocation.Route.Vertices[0] = vertex1; referencedPointAlongLineLocation.Route.Vertices[1] = vertex2; referencedPointAlongLineLocation.Latitude = (49.60597f + 49.60521f) / 2f; referencedPointAlongLineLocation.Longitude = (6.12829f + 6.12779f) / 2f; // encode location. var encoder = new PointAlongLineEncoder(); var router = new Dykstra(); var mainEncoder = new ReferencedOsmEncoder(graph, null); var referencedEncoder = new ReferencedPointAlongLineEncoder(mainEncoder, encoder); var location = referencedEncoder.EncodeReferenced(referencedPointAlongLineLocation); // test result. Assert.IsNotNull(location); Assert.AreEqual(SideOfRoad.OnOrAbove, location.SideOfRoad); Assert.AreEqual(Orientation.NoOrientation, location.Orientation); Assert.AreEqual(50, location.PositiveOffsetPercentage.Value, 0.5f); Assert.AreEqual(49.60597f, location.First.Coordinate.Latitude); Assert.AreEqual(6.12829f, location.First.Coordinate.Longitude); Assert.AreEqual(91, location.First.DistanceToNext); Assert.AreEqual(203, location.First.Bearing); Assert.AreEqual(FormOfWay.SingleCarriageWay, location.First.FormOfWay); Assert.AreEqual(FunctionalRoadClass.Frc3, location.First.FuntionalRoadClass); Assert.AreEqual(FunctionalRoadClass.Frc3, location.First.LowestFunctionalRoadClassToNext); Assert.AreEqual(49.60521f, location.Last.Coordinate.Latitude); Assert.AreEqual(6.12779f, location.Last.Coordinate.Longitude); Assert.AreEqual(23, location.Last.Bearing); // encode location with a point on the first point. referencedPointAlongLineLocation = new ReferencedPointAlongLine(); referencedPointAlongLineLocation.Route = new ReferencedLine(graph); referencedPointAlongLineLocation.Route.Edges = new LiveEdge[1]; referencedPointAlongLineLocation.Route.Edges[0] = new LiveEdge() { Distance = 10, Forward = true, Tags = tags.Add(new TagsCollection(Tag.Create("highway", "tertiary"))) }; referencedPointAlongLineLocation.Route.EdgeShapes = new GeoCoordinateSimple[1][]; referencedPointAlongLineLocation.Route.EdgeShapes[0] = new GeoCoordinateSimple[0]; referencedPointAlongLineLocation.Route.Vertices = new long[2]; referencedPointAlongLineLocation.Route.Vertices[0] = vertex1; referencedPointAlongLineLocation.Route.Vertices[1] = vertex2; referencedPointAlongLineLocation.Latitude = 49.60597f; referencedPointAlongLineLocation.Longitude = 6.12829f; // encode location. location = referencedEncoder.EncodeReferenced(referencedPointAlongLineLocation); // test result. Assert.IsNotNull(location); Assert.AreEqual(SideOfRoad.OnOrAbove, location.SideOfRoad); Assert.AreEqual(Orientation.NoOrientation, location.Orientation); Assert.AreEqual(0, location.PositiveOffsetPercentage); Assert.AreEqual(49.60597f, location.First.Coordinate.Latitude); Assert.AreEqual(6.12829f, location.First.Coordinate.Longitude); Assert.AreEqual(91, location.First.DistanceToNext); Assert.AreEqual(FormOfWay.SingleCarriageWay, location.First.FormOfWay); Assert.AreEqual(FunctionalRoadClass.Frc3, location.First.FuntionalRoadClass); Assert.AreEqual(FunctionalRoadClass.Frc3, location.First.LowestFunctionalRoadClassToNext); Assert.AreEqual(49.60521f, location.Last.Coordinate.Latitude); Assert.AreEqual(6.12779f, location.Last.Coordinate.Longitude); // encode location with a point on the last point. referencedPointAlongLineLocation = new ReferencedPointAlongLine(); referencedPointAlongLineLocation.Route = new ReferencedLine(graph); referencedPointAlongLineLocation.Route.Edges = new LiveEdge[1]; referencedPointAlongLineLocation.Route.Edges[0] = new LiveEdge() { Distance = 10, Forward = true, Tags = tags.Add(new TagsCollection(Tag.Create("highway", "tertiary"))) }; referencedPointAlongLineLocation.Route.EdgeShapes = new GeoCoordinateSimple[1][]; referencedPointAlongLineLocation.Route.EdgeShapes[0] = new GeoCoordinateSimple[0]; referencedPointAlongLineLocation.Route.Vertices = new long[2]; referencedPointAlongLineLocation.Route.Vertices[0] = vertex1; referencedPointAlongLineLocation.Route.Vertices[1] = vertex2; referencedPointAlongLineLocation.Latitude = 49.60521f; referencedPointAlongLineLocation.Longitude = 6.12779f; // encode location. location = referencedEncoder.EncodeReferenced(referencedPointAlongLineLocation); // test result. Assert.IsNotNull(location); Assert.AreEqual(SideOfRoad.OnOrAbove, location.SideOfRoad); Assert.AreEqual(Orientation.NoOrientation, location.Orientation); Assert.AreEqual(99, location.PositiveOffsetPercentage.Value); Assert.AreEqual(49.60597f, location.First.Coordinate.Latitude); Assert.AreEqual(6.12829f, location.First.Coordinate.Longitude); Assert.AreEqual(91, location.First.DistanceToNext); Assert.AreEqual(FormOfWay.SingleCarriageWay, location.First.FormOfWay); Assert.AreEqual(FunctionalRoadClass.Frc3, location.First.FuntionalRoadClass); Assert.AreEqual(FunctionalRoadClass.Frc3, location.First.LowestFunctionalRoadClassToNext); Assert.AreEqual(49.60521f, location.Last.Coordinate.Latitude); Assert.AreEqual(6.12779f, location.Last.Coordinate.Longitude); }