Exemple #1
0
        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 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.
        }