public void RoutingRegressionTest9ResolvingReverse() { // build a graph to encode from. var tags = new TagsTableCollectionIndex(); var graphDataSource = new DynamicGraphRouterDataSource<LiveEdge>(tags); var vertex1 = graphDataSource.AddVertex(51.05849821468899f, 3.7240000000000000f); var vertex2 = graphDataSource.AddVertex(51.05849821468899f, 3.7254400000000000f); var vertex3 = graphDataSource.AddVertex(51.05849821468899f, 3.7225627899169926f); var edge = new LiveEdge() // all edges are identical. { Distance = 100, Forward = true, Tags = tags.Add(new TagsCollection( Tag.Create("highway", "tertiary"), Tag.Create("oneway", "yes"))) }; graphDataSource.AddEdge(vertex1, vertex2, edge, null); graphDataSource.AddEdge(vertex3, vertex1, edge, null); // {RectF:[(3,71326552867889,51,048498214689),(3,73326552867889,51,068498214689)]} var edges = graphDataSource.GetEdges(new GeoCoordinateBox( new GeoCoordinate(51.068498214689, 3.73326552867889), new GeoCoordinate(51.048498214689, 3.71326552867889))); while(edges.MoveNext()) { if(edges.Vertex1 == 1 && edges.Vertex2 == 2) { Assert.IsTrue(edges.EdgeData.Forward); } else if(edges.Vertex1 == 2 && edges.Vertex2 == 1) { Assert.IsFalse(edges.EdgeData.Forward); } if (edges.Vertex1 == 1 && edges.Vertex2 == 3) { Assert.IsFalse(edges.EdgeData.Forward); } else if (edges.Vertex1 == 3 && edges.Vertex2 == 1) { Assert.IsTrue(edges.EdgeData.Forward); } } }
public void RoutingRegressionTest10ResolvingReverse() { // build a graph to encode from. var tags = new TagsTableCollectionIndex(); var graphDataSource = new DynamicGraphRouterDataSource<LiveEdge>(tags); var vertex1 = graphDataSource.AddVertex(51.05849821468899f, 3.7240000000000000f); var vertex2 = graphDataSource.AddVertex(51.05849821468899f, 3.7254400000000000f); var vertex3 = graphDataSource.AddVertex(51.05849821468899f, 3.7225627899169926f); var edge = new LiveEdge() // all edges are identical. { Distance = 100, Forward = true, Tags = tags.Add(new TagsCollection( Tag.Create("highway", "tertiary"), Tag.Create("oneway", "yes"))) }; var shape1 = new CoordinateArrayCollection<OsmSharp.Math.Geo.Simple.GeoCoordinateSimple>( new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple[] { new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 1, Longitude = 1 }, new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 2, Longitude = 2 } }); var shape2 = new CoordinateArrayCollection<OsmSharp.Math.Geo.Simple.GeoCoordinateSimple>( new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple[] { new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 3, Longitude = 3 }, new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 4, Longitude = 4 } }); graphDataSource.AddEdge(vertex1, vertex2, edge, shape1); graphDataSource.AddEdge(vertex3, vertex1, edge, shape2); // {RectF:[(3,71326552867889,51,048498214689),(3,73326552867889,51,068498214689)]} var edges = graphDataSource.GetEdges(new GeoCoordinateBox( new GeoCoordinate(51.068498214689, 3.73326552867889), new GeoCoordinate(51.048498214689, 3.71326552867889))); while (edges.MoveNext()) { if (edges.Vertex1 == 1 && edges.Vertex2 == 2) { Assert.IsTrue(edges.EdgeData.Forward); var shapes = edges.Intermediates.ToSimpleArray(); Assert.AreEqual(2, shapes.Length); Assert.AreEqual(1, shapes[0].Latitude); Assert.AreEqual(1, shapes[0].Longitude); Assert.AreEqual(2, shapes[1].Latitude); Assert.AreEqual(2, shapes[1].Longitude); } else if (edges.Vertex1 == 2 && edges.Vertex2 == 1) { Assert.IsFalse(edges.EdgeData.Forward); var shapes = edges.Intermediates.ToSimpleArray(); Assert.AreEqual(2, shapes.Length); Assert.AreEqual(2, shapes[0].Latitude); Assert.AreEqual(2, shapes[0].Longitude); Assert.AreEqual(1, shapes[1].Latitude); Assert.AreEqual(1, shapes[1].Longitude); } if (edges.Vertex1 == 1 && edges.Vertex2 == 3) { Assert.IsFalse(edges.EdgeData.Forward); var shapes = edges.Intermediates.ToSimpleArray(); Assert.AreEqual(2, shapes.Length); Assert.AreEqual(4, shapes[0].Latitude); Assert.AreEqual(4, shapes[0].Longitude); Assert.AreEqual(3, shapes[1].Latitude); Assert.AreEqual(3, shapes[1].Longitude); } else if (edges.Vertex1 == 3 && edges.Vertex2 == 1) { Assert.IsTrue(edges.EdgeData.Forward); var shapes = edges.Intermediates.ToSimpleArray(); Assert.AreEqual(2, shapes.Length); Assert.AreEqual(3, shapes[0].Latitude); Assert.AreEqual(3, shapes[0].Longitude); Assert.AreEqual(4, shapes[1].Latitude); Assert.AreEqual(4, shapes[1].Longitude); } } }
/// <summary> /// Tests the edge matcher in combination with dykstra routing. /// </summary> /// <param name="name"></param> /// <param name="highway"></param> /// <param name="vehicle"></param> /// <param name="matcher"></param> /// <param name="pointName"></param> /// <param name="notFound"></param> private void TestResolveOnEdgeSingle(string name, string highway, Vehicle vehicle, IEdgeMatcher matcher, string pointName, bool notFound) { var fromName = new GeoCoordinate(51.0003, 4.0007); var toName = new GeoCoordinate(51.0003, 4.0008); var fromNoname = new GeoCoordinate(51.0, 4.0007); var toNoname = new GeoCoordinate(51.0, 4.0008); TagsCollection pointTags = new SimpleTagsCollection(); pointTags["name"] = pointName; TagsCollection tags = new SimpleTagsCollection(); tags["highway"] = highway; //tags["name"] = name; var tagsIndex = new SimpleTagsIndex(); // do the data processing. var data = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex); uint vertexNoname1 = data.AddVertex((float)fromNoname.Latitude, (float)fromNoname.Longitude); uint vertexNoname2 = data.AddVertex((float)toNoname.Latitude, (float)toNoname.Longitude); data.AddArc(vertexNoname1, vertexNoname2, new LiveEdge() { Forward = true, Tags = tagsIndex.Add(tags) }, null); tags = new SimpleTagsCollection(); tags["highway"] = highway; tags["name"] = name; uint vertexName1 = data.AddVertex((float)fromName.Latitude, (float)fromName.Longitude); uint vertexName2 = data.AddVertex((float)toName.Latitude, (float)toName.Longitude); data.AddArc(vertexName1, vertexName2, new LiveEdge() { Forward = true, Tags = tagsIndex.Add(tags) }, null); IRoutingInterpreter interpreter = new OsmRoutingInterpreter(); // creates the data. IBasicRouter<LiveEdge> router = new DykstraRoutingLive(); var nonameLocation = new GeoCoordinate( (fromNoname.Latitude + toNoname.Latitude) / 2.0, (fromNoname.Longitude + toNoname.Longitude) / 2.0); // var nameLocation = new GeoCoordinate( // (fromName.Latitude + toName.Latitude) / 2.0, // (fromName.Longitude + toName.Longitude) / 2.0); const float delta = 0.01f; SearchClosestResult result = router.SearchClosest(data, interpreter, vehicle, nonameLocation, delta, matcher, pointTags); if (result.Distance < double.MaxValue) { // there is a result. Assert.IsFalse(notFound, "A result was found but was supposed not to be found!"); if (name == pointName) { // the name location was supposed to be found! Assert.IsTrue(result.Vertex1 == vertexName1 || result.Vertex1 == vertexName2); Assert.IsTrue(result.Vertex2 == vertexName1 || result.Vertex2 == vertexName2); } else { // the noname location was supposed to be found! Assert.IsTrue(result.Vertex1 == vertexNoname1 || result.Vertex1 == vertexNoname2); Assert.IsTrue(result.Vertex2 == vertexNoname1 || result.Vertex2 == vertexNoname2); } return; } Assert.IsTrue(notFound, "A result was not found but was supposed to be found!"); }
public void RoutingRegressionTest11ResolvingReverse() { // build a graph to encode from. var tags = new TagsTableCollectionIndex(); var graphDataSource = new DynamicGraphRouterDataSource<LiveEdge>(tags); var vertex1 = graphDataSource.AddVertex(51.05849821468899f, 3.7240000000000000f); var vertex2 = graphDataSource.AddVertex(51.05849821468899f, 3.7254400000000000f); var vertex3 = graphDataSource.AddVertex(51.05849821468899f, 3.7225627899169926f); var edgeData = new LiveEdge() // all edges are identical. { Distance = 100, Forward = true, Tags = tags.Add(new TagsCollection( Tag.Create("highway", "tertiary"), Tag.Create("oneway", "yes"))) }; var shape1 = new CoordinateArrayCollection<OsmSharp.Math.Geo.Simple.GeoCoordinateSimple>( new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple[] { new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 1, Longitude = 1 }, new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 2, Longitude = 2 } }); var shape2 = new CoordinateArrayCollection<OsmSharp.Math.Geo.Simple.GeoCoordinateSimple>( new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple[] { new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 3, Longitude = 3 }, new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 4, Longitude = 4 } }); graphDataSource.AddEdge(vertex1, vertex2, edgeData, shape1); graphDataSource.AddEdge(vertex3, vertex1, edgeData, shape2); var edges = new List<Edge<LiveEdge>>(graphDataSource.GetEdges(1)); Assert.AreEqual(2, edges.Count); foreach(var edge in edges) { if (edge.Neighbour == 2) { Assert.AreEqual(true, edge.EdgeData.Forward); } else if(edge.Neighbour == 3) { Assert.AreEqual(false, edge.EdgeData.Forward); } } edges = new List<Edge<LiveEdge>>(graphDataSource.GetEdges(2)); Assert.AreEqual(1, edges.Count); Assert.AreEqual(false, edges[0].EdgeData.Forward); edges = new List<Edge<LiveEdge>>(graphDataSource.GetEdges(3)); Assert.AreEqual(1, edges.Count); Assert.AreEqual(true, edges[0].EdgeData.Forward); }
/// <summary> /// Tests the edge matcher in combination with dykstra routing. /// </summary> /// <param name="name"></param> /// <param name="highway"></param> /// <param name="vehicle"></param> /// <param name="matcher"></param> /// <param name="point_name"></param> /// <param name="not_found"></param> private void TestResolveOnEdgeSingle(string name, string highway, VehicleEnum vehicle, IEdgeMatcher matcher, string point_name, bool not_found) { GeoCoordinate from_name = new GeoCoordinate(51.0003, 4.0007); GeoCoordinate to_name = new GeoCoordinate(51.0003, 4.0008); GeoCoordinate from_noname = new GeoCoordinate(51.0, 4.0007); GeoCoordinate to_noname = new GeoCoordinate(51.0, 4.0008); Dictionary<string, string> point_tags = new Dictionary<string, string>(); point_tags["name"] = point_name; Dictionary<string, string> tags = new Dictionary<string, string>(); tags["highway"] = highway; //tags["name"] = name; OsmTagsIndex tags_index = new OsmTagsIndex(); // do the data processing. DynamicGraphRouterDataSource<SimpleWeighedEdge> data = new DynamicGraphRouterDataSource<SimpleWeighedEdge>(tags_index); uint vertex_noname1 = data.AddVertex((float)from_noname.Latitude, (float)from_noname.Longitude); uint vertex_noname2 = data.AddVertex((float)to_noname.Latitude, (float)to_noname.Longitude); data.AddArc(vertex_noname1, vertex_noname2, new SimpleWeighedEdge() { IsForward = true, Tags = tags_index.Add(tags), Weight = 100 }, null); tags = new Dictionary<string, string>(); tags["highway"] = highway; tags["name"] = name; uint vertex_name1 = data.AddVertex((float)from_name.Latitude, (float)from_name.Longitude); uint vertex_name2 = data.AddVertex((float)to_name.Latitude, (float)to_name.Longitude); data.AddArc(vertex_name1, vertex_name2, new SimpleWeighedEdge() { IsForward = true, Tags = tags_index.Add(tags), Weight = 100 }, null); IRoutingInterpreter interpreter = new OsmRoutingInterpreter(); // creates the data. IBasicRouter<SimpleWeighedEdge> router = new DykstraRoutingLive( data.TagsIndex); GeoCoordinate noname_location = new GeoCoordinate( (from_noname.Latitude + to_noname.Latitude) / 2.0, (from_noname.Longitude + to_noname.Longitude) / 2.0); GeoCoordinate name_location = new GeoCoordinate( (from_name.Latitude + to_name.Latitude) / 2.0, (from_name.Longitude + to_name.Longitude) / 2.0); float delta = 0.01f; SearchClosestResult result = router.SearchClosest(data, interpreter, vehicle, noname_location, delta, matcher, point_tags); if (result.Distance < double.MaxValue) { // there is a result. Assert.IsFalse(not_found, "A result was found but was supposed not to be found!"); if (name == point_name) { // the name location was supposed to be found! Assert.IsTrue(result.Vertex1 == vertex_name1 || result.Vertex1 == vertex_name2); Assert.IsTrue(result.Vertex2 == vertex_name1 || result.Vertex2 == vertex_name2); } else { // the noname location was supposed to be found! Assert.IsTrue(result.Vertex1 == vertex_noname1 || result.Vertex1 == vertex_noname2); Assert.IsTrue(result.Vertex2 == vertex_noname1 || result.Vertex2 == vertex_noname2); } return; } Assert.IsTrue(not_found, "A result was not found but was supposed to be found!"); }
public void RoutingRegressionTest10ResolvingReverse() { // build a graph to encode from. var tags = new TagsTableCollectionIndex(); var graphDataSource = new DynamicGraphRouterDataSource <LiveEdge>(tags); var vertex1 = graphDataSource.AddVertex(51.05849821468899f, 3.7240000000000000f); var vertex2 = graphDataSource.AddVertex(51.05849821468899f, 3.7254400000000000f); var vertex3 = graphDataSource.AddVertex(51.05849821468899f, 3.7225627899169926f); var edge = new LiveEdge() // all edges are identical. { Distance = 100, Forward = true, Tags = tags.Add(new TagsCollection( Tag.Create("highway", "tertiary"), Tag.Create("oneway", "yes"))) }; var shape1 = new CoordinateArrayCollection <OsmSharp.Math.Geo.Simple.GeoCoordinateSimple>( new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple[] { new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 1, Longitude = 1 }, new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 2, Longitude = 2 } }); var shape2 = new CoordinateArrayCollection <OsmSharp.Math.Geo.Simple.GeoCoordinateSimple>( new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple[] { new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 3, Longitude = 3 }, new OsmSharp.Math.Geo.Simple.GeoCoordinateSimple() { Latitude = 4, Longitude = 4 } }); graphDataSource.AddEdge(vertex1, vertex2, edge, shape1); graphDataSource.AddEdge(vertex3, vertex1, edge, shape2); // {RectF:[(3,71326552867889,51,048498214689),(3,73326552867889,51,068498214689)]} var edges = graphDataSource.GetEdges(new GeoCoordinateBox( new GeoCoordinate(51.068498214689, 3.73326552867889), new GeoCoordinate(51.048498214689, 3.71326552867889))); while (edges.MoveNext()) { if (edges.Vertex1 == 1 && edges.Vertex2 == 2) { Assert.IsTrue(edges.EdgeData.Forward); var shapes = edges.Intermediates.ToSimpleArray(); Assert.AreEqual(2, shapes.Length); Assert.AreEqual(1, shapes[0].Latitude); Assert.AreEqual(1, shapes[0].Longitude); Assert.AreEqual(2, shapes[1].Latitude); Assert.AreEqual(2, shapes[1].Longitude); } else if (edges.Vertex1 == 2 && edges.Vertex2 == 1) { Assert.IsFalse(edges.EdgeData.Forward); var shapes = edges.Intermediates.ToSimpleArray(); Assert.AreEqual(2, shapes.Length); Assert.AreEqual(2, shapes[0].Latitude); Assert.AreEqual(2, shapes[0].Longitude); Assert.AreEqual(1, shapes[1].Latitude); Assert.AreEqual(1, shapes[1].Longitude); } if (edges.Vertex1 == 1 && edges.Vertex2 == 3) { Assert.IsFalse(edges.EdgeData.Forward); var shapes = edges.Intermediates.ToSimpleArray(); Assert.AreEqual(2, shapes.Length); Assert.AreEqual(4, shapes[0].Latitude); Assert.AreEqual(4, shapes[0].Longitude); Assert.AreEqual(3, shapes[1].Latitude); Assert.AreEqual(3, shapes[1].Longitude); } else if (edges.Vertex1 == 3 && edges.Vertex2 == 1) { Assert.IsTrue(edges.EdgeData.Forward); var shapes = edges.Intermediates.ToSimpleArray(); Assert.AreEqual(2, shapes.Length); Assert.AreEqual(3, shapes[0].Latitude); Assert.AreEqual(3, shapes[0].Longitude); Assert.AreEqual(4, shapes[1].Latitude); Assert.AreEqual(4, shapes[1].Longitude); } } }
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); }
/// <summary> /// Tests the edge matcher in combination with dykstra routing. /// </summary> /// <param name="name"></param> /// <param name="highway"></param> /// <param name="vehicle"></param> /// <param name="matcher"></param> /// <param name="pointName"></param> /// <param name="notFound"></param> private void TestResolveOnEdgeSingle(string name, string highway, Vehicle vehicle, IEdgeMatcher matcher, string pointName, bool notFound) { var fromName = new GeoCoordinate(51.0003, 4.0007); var toName = new GeoCoordinate(51.0003, 4.0008); var fromNoname = new GeoCoordinate(51.0, 4.0007); var toNoname = new GeoCoordinate(51.0, 4.0008); TagsCollectionBase pointTags = new TagsCollection(); pointTags["name"] = pointName; TagsCollectionBase tags = new TagsCollection(); tags["highway"] = highway; //tags["name"] = name; var tagsIndex = new TagsTableCollectionIndex(); // do the data processing. var data = new DynamicGraphRouterDataSource <LiveEdge>(tagsIndex); uint vertexNoname1 = data.AddVertex((float)fromNoname.Latitude, (float)fromNoname.Longitude); uint vertexNoname2 = data.AddVertex((float)toNoname.Latitude, (float)toNoname.Longitude); data.AddEdge(vertexNoname1, vertexNoname2, new LiveEdge() { Forward = true, Tags = tagsIndex.Add(tags) }, null); tags = new TagsCollection(); tags["highway"] = highway; tags["name"] = name; uint vertexName1 = data.AddVertex((float)fromName.Latitude, (float)fromName.Longitude); uint vertexName2 = data.AddVertex((float)toName.Latitude, (float)toName.Longitude); data.AddEdge(vertexName1, vertexName2, new LiveEdge() { Forward = true, Tags = tagsIndex.Add(tags) }, null); IRoutingInterpreter interpreter = new OsmRoutingInterpreter(); // creates the data. IBasicRouter <LiveEdge> router = new DykstraRoutingLive(); var nonameLocation = new GeoCoordinate( (fromNoname.Latitude + toNoname.Latitude) / 2.0, (fromNoname.Longitude + toNoname.Longitude) / 2.0); // var nameLocation = new GeoCoordinate( // (fromName.Latitude + toName.Latitude) / 2.0, // (fromName.Longitude + toName.Longitude) / 2.0); const float delta = 0.01f; var result = router.SearchClosest(data, interpreter, vehicle, nonameLocation, delta, matcher, pointTags, null); if (result.Distance < double.MaxValue) { // there is a result. Assert.IsFalse(notFound, "A result was found but was supposed not to be found!"); if (name == pointName) { // the name location was supposed to be found! Assert.IsTrue(result.Vertex1 == vertexName1 || result.Vertex1 == vertexName2); Assert.IsTrue(result.Vertex2 == vertexName1 || result.Vertex2 == vertexName2); } else { // the noname location was supposed to be found! Assert.IsTrue(result.Vertex1 == vertexNoname1 || result.Vertex1 == vertexNoname2); Assert.IsTrue(result.Vertex2 == vertexNoname1 || result.Vertex2 == vertexNoname2); } return; } Assert.IsTrue(notFound, "A result was not found but was supposed to be found!"); }
public void DecodeReferencedPointAlongLineLocation() { var delta = 0.0001; // build the location to decode. var location = new PointAlongLineLocation(); location.First = new LocationReferencePoint(); location.First.Coordinate = new Coordinate() { Latitude = 49.60597, Longitude = 6.12829 }; location.First.DistanceToNext = 92; location.First.FuntionalRoadClass = FunctionalRoadClass.Frc2; location.First.FormOfWay = FormOfWay.SingleCarriageWay; location.First.LowestFunctionalRoadClassToNext = FunctionalRoadClass.Frc2; location.First.Bearing = 203; location.Last = new LocationReferencePoint(); location.Last.Coordinate = new Coordinate() { Latitude = 49.60521, Longitude = 6.12779 }; location.Last.DistanceToNext = 10; location.Last.FuntionalRoadClass = FunctionalRoadClass.Frc2; location.Last.FormOfWay = FormOfWay.SingleCarriageWay; location.Last.Bearing = 23; location.PositiveOffsetPercentage = (float)((28.0 / 92.0) * 100.0); location.Orientation = Orientation.NoOrientation; location.SideOfRoad = SideOfRoad.Left; // build a graph to decode onto. var tags = new TagsTableCollectionIndex(); var graphDataSource = new DynamicGraphRouterDataSource <LiveEdge>(tags); var vertex1 = graphDataSource.AddVertex(49.60597f, 6.12829f); var vertex2 = graphDataSource.AddVertex(49.60521f, 6.12779f); graphDataSource.AddEdge(vertex1, vertex2, new LiveEdge() { Distance = 10, Forward = true, Tags = tags.Add(new TagsCollection( Tag.Create("FRC", "2"), Tag.Create("FOW", "3"))) }, null); graphDataSource.AddEdge(vertex2, vertex1, new LiveEdge() { Distance = 10, Forward = true, Tags = tags.Add(new TagsCollection( Tag.Create("FRC", "2"), Tag.Create("FOW", "3"))) }, null); // decode the location var graph = new BasicRouterDataSource <LiveEdge>(graphDataSource); var decoder = new PointAlongLineDecoder(); var router = new BasicRouter(); var mainDecoder = new ReferencedMultiNetDecoder(graph, new BinaryDecoder()); var referencedDecoder = new ReferencedPointAlongLineDecoder(mainDecoder, decoder); var referencedLocation = referencedDecoder.Decode(location); // confirm result. Assert.IsNotNull(referencedLocation); Assert.IsNotNull(referencedLocation.Route); Assert.IsNotNull(referencedLocation.Route.Edges); Assert.AreEqual(vertex1, referencedLocation.Route.Vertices[0]); Assert.AreEqual(vertex2, referencedLocation.Route.Vertices[1]); var longitudeReference = (location.Last.Coordinate.Longitude - location.First.Coordinate.Longitude) * (location.PositiveOffsetPercentage.Value / 100.0) + location.First.Coordinate.Longitude; var latitudeReference = (location.Last.Coordinate.Latitude - location.First.Coordinate.Latitude) * (location.PositiveOffsetPercentage.Value / 100.0) + location.First.Coordinate.Latitude; Assert.AreEqual(longitudeReference, referencedLocation.Longitude, delta); Assert.AreEqual(latitudeReference, referencedLocation.Latitude, delta); }