static void Main(string[] args) { // make sure the output is logged to console. OsmSharp.Logging.Log.Enable(); OsmSharp.Logging.Log.RegisterListener(new OsmSharp.WinForms.UI.Logging.ConsoleTraceListener()); var nwbDump = @"C:\work\via\data\NWB\nwb.dump"; // load data. OsmSharp.Logging.Log.TraceEvent("Nederlands.Test", OsmSharp.Logging.TraceEventType.Information, string.Format("Loading {0}...", nwbDump)); var serializer = new LiveEdgeFlatfileSerializer(); IBasicRouterDataSource <LiveEdge> nwbGraph = null; using (var stream = new FileInfo(nwbDump).OpenRead()) { nwbGraph = serializer.Deserialize(stream); } NWBMapping.BAANSUBSRT = "BST_CODE"; BasicRouter.MaxSettles = 65536; // create test case. var testCase = new GeoCoordinate[] { new GeoCoordinate(51.95833631000295f, 4.946079254150391f), new GeoCoordinate(51.94288923910573f, 4.954748153686523f) }; // create encoder. var encoder = ReferencedNWBEncoder.CreateBinary(nwbGraph); // build line location from shortest path. OsmSharp.Routing.Route route; var line = encoder.BuildLineLocationFromShortestPath(testCase[0], testCase[1], out route); var lineJson = line.ToFeatures().ToGeoJson(); // create geojson to view output. // encode the line location. var encoded = encoder.Encode(line); // create decoder. var decoder = ReferencedNWBDecoder.CreateBinary(nwbGraph); // decode line location. var decodedLine = decoder.Decode(encoded); var decodedLineJson = line.ToFeatures().ToGeoJson(); // create geojson to view output. }
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.MultipleCarriageWay; 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.MultipleCarriageWay; 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(NWBMapping.BAANSUBSRT, "VBD"), Tag.Create(NWBMapping.WEGBEHSRT, "R"), Tag.Create(NWBMapping.WEGNUMMER, string.Empty), Tag.Create(NWBMapping.RIJRICHTNG, string.Empty), Tag.Create(NWBMapping.HECTOLTTR, string.Empty))) }, null); graphDataSource.AddEdge(vertex2, vertex1, new LiveEdge() { Distance = 10, Forward = true, Tags = tags.Add(new TagsCollection( Tag.Create(NWBMapping.BAANSUBSRT, "VBD"), Tag.Create(NWBMapping.WEGBEHSRT, "R"), Tag.Create(NWBMapping.WEGNUMMER, string.Empty), Tag.Create(NWBMapping.RIJRICHTNG, string.Empty), Tag.Create(NWBMapping.HECTOLTTR, string.Empty))) }, null); // decode the location var graph = new BasicRouterDataSource <LiveEdge>(graphDataSource); var decoder = new PointAlongLineDecoder(); var router = new BasicRouter(); var mainDecoder = new ReferencedNWBDecoder(graph, new BinaryDecoder()); var referencedDecoder = new ReferencedPointAlongLineDecoder(mainDecoder, decoder); var referencedLocation = referencedDecoder.Decode(location); // confirm result. Assert.IsNotNull(referencedLocation); Assert.IsNotNull(referencedLocation.Route.Edges); Assert.IsNotNull(referencedLocation.Route.Edges[0]); 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); }