/// <summary>
        /// Creates a router.
        /// </summary>
        /// <param name="interpreter"></param>
        /// <param name="manifestResourceName"></param>
        /// <returns></returns>
        protected override Router CreateRouter(IOsmRoutingInterpreter interpreter, string manifestResourceName)
        {
            var tagsIndex = new TagsTableCollectionIndex();

            // do the data processing.
            var source = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(manifestResourceName));
            var data = CHEdgeGraphOsmStreamTarget.Preprocess(
                source, new OsmRoutingInterpreter(), Vehicle.Car);

            // serialize.
            var memoryStream            = new MemoryStream();
            TagsCollectionBase metaData = new TagsCollection();

            metaData.Add("some_key", "some_value");
            var routingSerializer = new CHEdgeDataDataSourceSerializer();

            routingSerializer.Serialize(memoryStream, data, metaData);

            memoryStream.Seek(0, SeekOrigin.Begin);

            var deserialized = routingSerializer.Deserialize(memoryStream);

            return(Router.CreateCHFrom(deserialized, new CHRouter(), new OsmRoutingInterpreter()));
        }
Пример #2
0
        public static void Initialize()
        {
            var routingSerializer = new CHEdgeDataDataSourceSerializer();

            _graph = routingSerializer.Deserialize(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Android.Routing.Offline.kempen-big.osm.pbf.contracted.mobile.routing"));
        }
        /// <summary>
        /// Tests preprocessing data from a PBF file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pbfFile"></param>
        public static void TestSerialization(string name, string pbfFile)
        {
            FileInfo testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfFile));
            Stream stream = testFile.OpenRead();
            PBFOsmStreamSource source = new PBFOsmStreamSource(stream);

            FileInfo testOutputFile = new FileInfo(@"test.routing");
            testOutputFile.Delete();
            Stream writeStream = testOutputFile.OpenWrite();

            CHEdgeGraphFileStreamTarget target = new CHEdgeGraphFileStreamTarget(writeStream,
                Vehicle.Car);
            target.RegisterSource(source);

            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("CHSerializer");
            performanceInfo.Start();
            performanceInfo.Report("Pulling from {0}...", testFile.Name);

            var data = CHEdgeGraphOsmStreamTarget.Preprocess(
                source, new OsmRoutingInterpreter(), Vehicle.Car);

            TagsCollectionBase metaData = new TagsCollection();
            metaData.Add("some_key", "some_value");
            var routingSerializer = new CHEdgeDataDataSourceSerializer(true);
            routingSerializer.Serialize(writeStream, data, metaData);

            stream.Dispose();
            writeStream.Dispose();

            OsmSharp.Logging.Log.TraceEvent("CHSerializer", OsmSharp.Logging.TraceEventType.Information,
                string.Format("Serialized file: {0}KB", testOutputFile.Length / 1024));

            performanceInfo.Stop();
        }
        public static Stream TestSerialization(string name, string pbfFile, DynamicGraphRouterDataSource <CHEdgeData> data)
        {
            var testOutputFile = new FileInfo(@"test.routing");

            testOutputFile.Delete();
            var writeStream = testOutputFile.OpenWrite();

            var performanceInfo = new PerformanceInfoConsumer("CHSerializer");

            performanceInfo.Start();
            performanceInfo.Report("Writing to {0}...", testOutputFile.Name);

            TagsCollectionBase metaData = new TagsCollection();

            metaData.Add("some_key", "some_value");
            var routingSerializer = new CHEdgeDataDataSourceSerializer();

            routingSerializer.Serialize(writeStream, data, metaData);

            writeStream.Dispose();

            OsmSharp.Logging.Log.TraceEvent("CHSerializer", OsmSharp.Logging.TraceEventType.Information,
                                            string.Format("Serialized file: {0}KB", testOutputFile.Length / 1024));

            performanceInfo.Stop();

            return(testOutputFile.OpenRead());
        }
Пример #5
0
        /// <summary>
        /// Tests routing from a serialized routing file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="stream"></param>
        /// <param name="box"></param>
        /// <param name="testCount"></param>
        public static void TestSerializedRouting(string name, Stream stream,
                                                 GeoCoordinateBox box, int testCount)
        {
            TagsCollectionBase metaData = null;
            var routingSerializer       = new CHEdgeDataDataSourceSerializer();
            var graphDeserialized       = routingSerializer.Deserialize(
                stream, out metaData, true);

            var router = Router.CreateCHFrom(
                graphDeserialized, new CHRouter(),
                new OsmRoutingInterpreter());

            CHSerializedRoutingTest.TestRouting(router, box, testCount);
        }
Пример #6
0
        /// <summary>
        /// Tests routing between two points and the associated instructions.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="stream"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        public static void TestSerializeRoutingInstrictions(string name, Stream stream,
                                                            GeoCoordinate from, GeoCoordinate to)
        {
            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("CHSerializedRouting");

            performanceInfo.Start();
            performanceInfo.Report("Routing & generating instructions...");

            TagsCollectionBase metaData = null;
            var routingSerializer       = new CHEdgeDataDataSourceSerializer();
            var graphDeserialized       = routingSerializer.Deserialize(
                stream, out metaData, true);

            var interpreter = new OsmRoutingInterpreter();
            var router      = Router.CreateCHFrom(
                graphDeserialized, new CHRouter(),
                interpreter);

            RouterPoint fromPoint = router.Resolve(Vehicle.Car, from);
            RouterPoint toPoint   = router.Resolve(Vehicle.Car, to);

            List <Instruction> instructions = new List <Instruction>();

            if (fromPoint != null && toPoint != null)
            {
                Route route = router.Calculate(Vehicle.Car, fromPoint, toPoint);
                if (route != null)
                {
                    instructions = InstructionGenerator.Generate(route, interpreter);
                }
            }

            performanceInfo.Stop();

            if (instructions.Count == 0)
            {
                OsmSharp.Logging.Log.TraceEvent("CHSerializedRouting", OsmSharp.Logging.TraceEventType.Information,
                                                "Routing unsuccesfull!");
            }
            else
            {
                foreach (Instruction instruction in instructions)
                {
                    OsmSharp.Logging.Log.TraceEvent("CHSerializedRouting", OsmSharp.Logging.TraceEventType.Information,
                                                    instruction.Text);
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Tests routing from a serialized routing file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="stream"></param>
        /// <param name="box"></param>
        /// <param name="testCount"></param>
        public static void TestSerializedRouting(string name, Stream stream,
                                                 GeoCoordinateBox box, int testCount)
        {
            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("CHSerializedRouting");

            performanceInfo.Start();
            performanceInfo.Report("Routing {0} routes...", testCount);

            TagsCollectionBase metaData = null;
            var routingSerializer       = new CHEdgeDataDataSourceSerializer();
            var graphDeserialized       = routingSerializer.Deserialize(
                stream, out metaData, true);

            var router = Router.CreateCHFrom(
                graphDeserialized, new CHRouter(),
                new OsmRoutingInterpreter());

            int successCount = 0;
            int totalCount   = testCount;

            while (testCount > 0)
            {
                GeoCoordinate from = box.GenerateRandomIn();
                GeoCoordinate to   = box.GenerateRandomIn();

                RouterPoint fromPoint = router.Resolve(Vehicle.Car, from);
                RouterPoint toPoint   = router.Resolve(Vehicle.Car, to);

                if (fromPoint != null && toPoint != null)
                {
                    Route route = router.Calculate(Vehicle.Car, fromPoint, toPoint, float.MaxValue, true);
                    if (route != null)
                    {
                        successCount++;
                    }
                }

                testCount--;
            }

            performanceInfo.Stop();

            OsmSharp.Logging.Log.TraceEvent("CHSerializedRouting", OsmSharp.Logging.TraceEventType.Information,
                                            string.Format("{0}/{1} routes successfull!", successCount, totalCount));
        }
Пример #8
0
        /// <summary>
        /// Tests preprocessing data from a PBF file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pbfFile"></param>
        public static Stream TestSerialization(string name, string pbfFile)
        {
            FileInfo           testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfFile));
            Stream             stream   = testFile.OpenRead();
            PBFOsmStreamSource source   = new PBFOsmStreamSource(stream);

            FileInfo testOutputFile = new FileInfo(@"test.routing");

            testOutputFile.Delete();
            Stream writeStream = testOutputFile.OpenWrite();

            var tagsIndex   = new TagsTableCollectionIndex();
            var interpreter = new OsmRoutingInterpreter();
            var graph       = new DynamicGraphRouterDataSource <CHEdgeData>(tagsIndex);
            CHEdgeGraphFileStreamTarget target = new CHEdgeGraphFileStreamTarget(writeStream, graph, interpreter, tagsIndex,
                                                                                 Vehicle.Car);

            target.RegisterSource(source);

            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("CHSerializer");

            performanceInfo.Start();
            performanceInfo.Report("Pulling from {0}...", testFile.Name);

            var data = CHEdgeGraphOsmStreamTarget.Preprocess(
                source, new OsmRoutingInterpreter(), Vehicle.Car);

            TagsCollectionBase metaData = new TagsCollection();

            metaData.Add("some_key", "some_value");
            var routingSerializer = new CHEdgeDataDataSourceSerializer();

            routingSerializer.Serialize(writeStream, data, metaData);

            stream.Dispose();
            writeStream.Dispose();

            OsmSharp.Logging.Log.TraceEvent("CHSerializer", OsmSharp.Logging.TraceEventType.Information,
                                            string.Format("Serialized file: {0}KB", testOutputFile.Length / 1024));

            performanceInfo.Stop();

            return(testOutputFile.OpenRead());
        }
Пример #9
0
        /// <summary>
        /// Flushes all data.
        /// </summary>
        public override void Flush()
        {
            base.Flush();

            // compress the graph.
            INodeWitnessCalculator witnessCalculator = new DykstraWitnessCalculator();
            var edgeDifference = new EdgeDifference(
                _graph, witnessCalculator);
            var preProcessor = new CHPreProcessor(
                _graph, edgeDifference, witnessCalculator);

            preProcessor.Start();

            // create serializer.
            var routingSerializer = new CHEdgeDataDataSourceSerializer(true);

            routingSerializer.Serialize(_graphStream, _graph);
            _graphStream.Flush();
        }
        /// <summary>
        /// Tests preprocessing data from a PBF file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pbfFile"></param>
        public static Stream TestSerialization(string name, string pbfFile)
        {
            var testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfFile));
            var stream = testFile.OpenRead();
            var source = new OsmSharp.Osm.Streams.Filters.OsmStreamFilterProgress();
            source.RegisterSource(new PBFOsmStreamSource(stream));

            var testOutputFile = new FileInfo(@"test.routing");
            testOutputFile.Delete();
            var writeStream = testOutputFile.OpenWrite();

            var tagsIndex = new TagsTableCollectionIndex();
            var interpreter = new OsmRoutingInterpreter();
            var graph = new DynamicGraphRouterDataSource<CHEdgeData>(tagsIndex);
            //CHEdgeGraphFileStreamTarget target = new CHEdgeGraphFileStreamTarget(writeStream, graph, interpreter, tagsIndex,
            //    Vehicle.Car);
            //target.RegisterSource(source);

            var performanceInfo = new PerformanceInfoConsumer("CHSerializer");
            performanceInfo.Start();
            performanceInfo.Report("Pulling from {0}...", testFile.Name);

            var data = CHEdgeGraphOsmStreamTarget.Preprocess(
                source, new OsmRoutingInterpreter(), Vehicle.Car);

            TagsCollectionBase metaData = new TagsCollection();
            metaData.Add("some_key", "some_value");
            var routingSerializer = new CHEdgeDataDataSourceSerializer();
            routingSerializer.Serialize(writeStream, data, metaData);

            stream.Dispose();
            writeStream.Dispose();

            OsmSharp.Logging.Log.TraceEvent("CHSerializer", OsmSharp.Logging.TraceEventType.Information,
                string.Format("Serialized file: {0}KB", testOutputFile.Length / 1024));

            performanceInfo.Stop();

            return testOutputFile.OpenRead();
        }
Пример #11
0
        /// <summary>
        /// Flushes all data.
        /// </summary>
        public override void Flush()
        {
            base.Flush();

            // compress the graph.
            INodeWitnessCalculator witnessCalculator = new DykstraWitnessCalculator();
            var edgeDifference = new EdgeDifferenceContractedSearchSpace(
                _graph, witnessCalculator);
            var preProcessor = new CHPreProcessor(
                _graph, edgeDifference, witnessCalculator);

            preProcessor.Start();

            // create tags.
            TagsCollectionBase metaTags = new TagsCollection();

            // create serializer.
            var routingSerializer = new CHEdgeDataDataSourceSerializer();

            routingSerializer.Serialize(_graphStream, _graph, metaTags);
            _graphStream.Flush();
        }
Пример #12
0
        /// <summary>
        /// Tests routing from a serialized routing file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="stream"></param>
        /// <param name="box"></param>
        /// <param name="testCount"></param>
        public static void TestSerializedRouting(string name, Stream stream,
            GeoCoordinateBox box, int testCount)
        {
            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("CHSerializedRouting");
            performanceInfo.Start();
            performanceInfo.Report("Routing {0} routes...", testCount);

            TagsCollectionBase metaData = null;
            var routingSerializer = new CHEdgeDataDataSourceSerializer(true);
            var graphDeserialized = routingSerializer.Deserialize(
                stream, out metaData, true);

            var router = Router.CreateCHFrom(
                graphDeserialized, new CHRouter(),
                new OsmRoutingInterpreter());

            int successCount = 0;
            int totalCount = testCount;
            while (testCount > 0)
            {
                GeoCoordinate from = box.GenerateRandomIn();
                GeoCoordinate to = box.GenerateRandomIn();

                RouterPoint fromPoint = router.Resolve(Vehicle.Car, from);
                RouterPoint toPoint = router.Resolve(Vehicle.Car, to);

                if (fromPoint != null && toPoint != null)
                {
                    Route route = router.Calculate(Vehicle.Car, fromPoint, toPoint);
                    if (route != null)
                    {
                        successCount++;
                    }
                }

                testCount--;
            }

            performanceInfo.Stop();

            OsmSharp.Logging.Log.TraceEvent("CHSerializedRouting", OsmSharp.Logging.TraceEventType.Information,
                string.Format("{0}/{1} routes successfull!", successCount, totalCount));
        }
Пример #13
0
        /// <summary>
        /// Tests routing from a serialized routing file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="stream"></param>
        /// <param name="box"></param>
        /// <param name="testCount"></param>
        public static void TestSerializedRouting(string name, Stream stream,
            GeoCoordinateBox box, int testCount)
        {
            TagsCollectionBase metaData = null;
            var routingSerializer = new CHEdgeDataDataSourceSerializer();
            var graphDeserialized = routingSerializer.Deserialize(
                stream, out metaData, true);

            var router = Router.CreateCHFrom(
                graphDeserialized, new CHRouter(),
                new OsmRoutingInterpreter());

            CHSerializedRoutingTest.TestRouting(router, box, testCount);
        }
        public void TestCHDataSourceTopologicalSortTest()
        {
            const string embeddedString = "OsmSharp.Test.Unittests.test_network_real1.osm";

            // creates a new interpreter.
            var interpreter = new OsmRoutingInterpreter();

            // do the data processing.
            var original = CHEdgeGraphOsmStreamTarget.Preprocess(new XmlOsmStreamSource(
                                                                     Assembly.GetExecutingAssembly()
                                                                     .GetManifestResourceStream(embeddedString)),
                                                                 interpreter,
                                                                 Vehicle.Car);
            var sortedGraph = CHEdgeDataDataSourceSerializer.SortGraph(original);

            original = CHEdgeGraphOsmStreamTarget.Preprocess(new XmlOsmStreamSource(
                                                                 Assembly.GetExecutingAssembly()
                                                                 .GetManifestResourceStream(embeddedString)),
                                                             interpreter,
                                                             Vehicle.Car);
            var    basicRouterOriginal = new CHRouter();
            Router referenceRouter     = Router.CreateCHFrom(
                original, basicRouterOriginal, interpreter);

            // try to do some routing on the deserialized version.
            var    basicRouter = new CHRouter();
            Router router      = Router.CreateCHFrom(
                new DynamicGraphRouterDataSource <CHEdgeData>(sortedGraph, original.TagsIndex), basicRouter, interpreter);

            // loop over all nodes and resolve their locations.
            var resolvedReference = new RouterPoint[original.VertexCount];
            var resolved          = new RouterPoint[original.VertexCount];

            for (uint idx = 1; idx < original.VertexCount + 1; idx++)
            { // resolve each vertex.
                float latitude, longitude;
                if (original.GetVertex(idx, out latitude, out longitude))
                {
                    resolvedReference[idx - 1] = referenceRouter.Resolve(Vehicle.Car, new GeoCoordinate(latitude, longitude));
                    resolved[idx - 1]          = router.Resolve(Vehicle.Car, new GeoCoordinate(latitude, longitude));
                }

                Assert.IsNotNull(resolvedReference[idx - 1]);
                Assert.IsNotNull(resolved[idx - 1]);

                //Assert.AreEqual(resolvedReference[idx - 1].Location.Latitude,
                //    resolved[idx - 1].Location.Latitude, 0.0001);
                //Assert.AreEqual(resolvedReference[idx - 1].Location.Longitude,
                //    resolved[idx - 1].Location.Longitude, 0.0001);
            }

            //// check all the routes having the same weight(s).
            //for (int fromIdx = 0; fromIdx < resolved.Length; fromIdx++)
            //{
            //    for (int toIdx = 0; toIdx < resolved.Length; toIdx++)
            //    {
            //        OsmSharpRoute referenceRoute = referenceRouter.Calculate(Vehicle.Car,
            //            resolvedReference[fromIdx], resolvedReference[toIdx]);
            //        OsmSharpRoute route = router.Calculate(Vehicle.Car,
            //            resolved[fromIdx], resolved[toIdx]);

            //        Assert.IsNotNull(referenceRoute);
            //        Assert.IsNotNull(route);
            //        //Assert.AreEqual(referenceRoute.TotalDistance, route.TotalDistance, 0.1);
            //        // TODO: meta data is missing in some CH routing; see issue
            //        //Assert.AreEqual(reference_route.TotalTime, route.TotalTime, 0.0001);
            //    }
            //}
        }
Пример #15
0
        /// <summary>
        /// Raises the create event.
        /// </summary>
        /// <param name="bundle">Bundle.</param>
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // enable the logggin.
            OsmSharp.Logging.Log.Enable();
            OsmSharp.Logging.Log.RegisterListener(new OsmSharp.Android.UI.Log.LogTraceListener());

            // initialize map.
            var map = new Map();
            // add a tile layer.
            //map.AddLayer(new LayerTile(@"http://otile1.mqcdn.com/tiles/1.0.0/osm/{0}/{1}/{2}.png"));
            // add an online osm-data->mapCSS translation layer.
            //map.AddLayer(new OsmLayer(dataSource, mapCSSInterpreter));
            // add a pre-processed vector data file.
            var sceneStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"OsmSharp.Android.UI.Sample.default.map");

            map.AddLayer(new LayerScene(Scene2D.Deserialize(sceneStream, true)));

            // define dummy from and to points.
            var from = new GeoCoordinate(51.261203, 4.780760);
            var to   = new GeoCoordinate(51.267797, 4.801362);

            // deserialize the pre-processed graph.
            var routingSerializer       = new CHEdgeDataDataSourceSerializer(false);
            TagsCollectionBase metaData = null;
            var graphStream             = Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.kempen-big.osm.pbf.routing");
            var graphDeserialized       = routingSerializer.Deserialize(graphStream, out metaData, true);

            // initialize router.
            _router = Router.CreateCHFrom(graphDeserialized, new CHRouter(), new OsmRoutingInterpreter());

            // resolve points.
            RouterPoint routerPoint1 = _router.Resolve(Vehicle.Car, from);
            RouterPoint routerPoint2 = _router.Resolve(Vehicle.Car, to);

            // calculate route.
            Route        route        = _router.Calculate(Vehicle.Car, routerPoint1, routerPoint2);
            RouteTracker routeTracker = new RouteTracker(route, new OsmRoutingInterpreter());

            _enumerator = route.GetRouteEnumerable(10).GetEnumerator();

            // add a router layer.
            _routeLayer = new LayerRoute(map.Projection);
            _routeLayer.AddRoute(route, SimpleColor.FromKnownColor(KnownColor.Blue, 125).Value, 12);
            map.AddLayer(_routeLayer);

            // define the mapview.
            _mapView = new MapView(this, new MapViewSurface(this));
            //_mapView = new MapView(this, new MapViewGLSurface(this));
            //_mapView.MapTapEvent += new MapViewEvents.MapTapEventDelegate(_mapView_MapTapEvent);
            _mapView.Map             = map;
            _mapView.MapMaxZoomLevel = 20;
            _mapView.MapMinZoomLevel = 10;
            _mapView.MapTilt         = 0;
            _mapView.MapCenter       = new GeoCoordinate(51.26371, 4.78601);
            _mapView.MapZoom         = 18;

            // add markers.
            _mapView.AddMarker(from);
            _mapView.AddMarker(to);

            // initialize a text view to display routing instructions.
            _textView = new TextView(this);
            _textView.SetBackgroundColor(global::Android.Graphics.Color.White);
            _textView.SetTextColor(global::Android.Graphics.Color.Black);

            // add the mapview to the linear layout.
            var layout = new LinearLayout(this);

            layout.Orientation = Orientation.Vertical;
            layout.AddView(_textView);
            layout.AddView(_mapView);

            // create the route tracker animator.
            _routeTrackerAnimator = new RouteTrackerAnimator(_mapView, routeTracker, 5, 17);

            // simulate a number of gps-location update along the calculated route.
            Timer timer = new Timer(250);

            timer.Elapsed += new ElapsedEventHandler(TimerHandler);
            timer.Start();

            SetContentView(layout);
        }
Пример #16
0
        /// <summary>
        /// Initializes the View property.
        /// </summary>
        public override void LoadView()
        {
            base.LoadView ();

            // enable the logggin.
            OsmSharp.Logging.Log.Enable();
            OsmSharp.Logging.Log.RegisterListener(new OsmSharp.iOS.UI.Log.ConsoleTraceListener());

            // initialize map.
            var map = new Map();
            // add a tile layer.
            //map.AddLayer(new LayerTile(@"http://otile1.mqcdn.com/tiles/1.0.0/osm/{0}/{1}/{2}.png"));
            // add an online osm-data->mapCSS translation layer.
            //map.AddLayer(new OsmLayer(dataSource, mapCSSInterpreter));
            // add a pre-processed vector data file.
            var sceneStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
                "OsmSharp.iOS.UI.Sample.kempen-big.osm.pbf.scene.layered");
            map.AddLayer(new LayerScene(Scene2D.Deserialize(sceneStream, true)));

            // define dummy from and to points.
            var from = new GeoCoordinate(51.261203, 4.780760);
            var to = new GeoCoordinate(51.267797, 4.801362);

            // deserialize the pre-processed graph.
            var routingSerializer = new CHEdgeDataDataSourceSerializer(false);
            TagsCollectionBase metaData = null;
            var graphStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
                "OsmSharp.iOS.UI.Sample.kempen-big.osm.pbf.routing");
            var graphDeserialized = routingSerializer.Deserialize(graphStream, out metaData, true);

            // initialize router.
            _router = Router.CreateCHFrom(graphDeserialized, new CHRouter(), new OsmRoutingInterpreter());

            // resolve points.
            RouterPoint routerPoint1 = _router.Resolve(Vehicle.Car, from);
            RouterPoint routerPoint2 = _router.Resolve(Vehicle.Car, to);

            // calculate route.
            Route route = _router.Calculate(Vehicle.Car, routerPoint1, routerPoint2);
            RouteTracker routeTracker = new RouteTracker(route, new OsmRoutingInterpreter());
            _enumerator = route.GetRouteEnumerable(10).GetEnumerator();

            // add a router layer.
            _routeLayer = new LayerRoute(map.Projection);
            _routeLayer.AddRoute (route, SimpleColor.FromKnownColor(KnownColor.Blue, 125).Value, 12);
            map.AddLayer(_routeLayer);

            // define the mapview.
            _mapView = new MapView();
            //_mapView.MapTapEvent += new MapViewEvents.MapTapEventDelegate(_mapView_MapTapEvent);
            _mapView.Map = map;
            _mapView.MapMaxZoomLevel = 20;
            _mapView.MapMinZoomLevel = 10;
            _mapView.MapTilt = 0;
            _mapView.MapCenter = new GeoCoordinate(51.26371, 4.78601);
            _mapView.MapZoom = 18;

            // add markers.
            _mapView.AddMarker (from);
            _mapView.AddMarker (to);

            // create the route tracker animator.
            _routeTrackerAnimator = new RouteTrackerAnimator(_mapView, routeTracker, 5, 17);

            // simulate a number of gps-location update along the calculated route.
            Timer timer = new Timer(250);
            timer.Elapsed += new ElapsedEventHandler(TimerHandler);
            timer.Start();

            View = _mapView;
        }
        /// <summary>
        /// Flushes all data.
        /// </summary>
        public override void Flush()
        {
            base.Flush();

            // compress the graph.
            INodeWitnessCalculator witnessCalculator = new DykstraWitnessCalculator();
            var edgeDifference = new EdgeDifference(
                _graph, witnessCalculator);
            var preProcessor = new CHPreProcessor(
                _graph, edgeDifference, witnessCalculator);
            preProcessor.Start();

            // create tags.
            TagsCollectionBase metaTags = new TagsCollection();

            // create serializer.
            var routingSerializer = new CHEdgeDataDataSourceSerializer(true);
            routingSerializer.Serialize(_graphStream, _graph, metaTags);
            _graphStream.Flush();
        }
        public void TestCHDataSourceTopologicalSortTest()
        {
            const string embeddedString = "OsmSharp.Test.Unittests.test_network_real1.osm";

            // creates a new interpreter.
            var interpreter = new OsmRoutingInterpreter();

            // do the data processing.
            var original = CHEdgeGraphOsmStreamTarget.Preprocess(new XmlOsmStreamSource(
                                                                   Assembly.GetExecutingAssembly()
                                                                           .GetManifestResourceStream(embeddedString)),
                                                               interpreter,
                                                               Vehicle.Car);
            CHEdgeDataDataSourceSerializer serializer = new CHEdgeDataDataSourceSerializer(true);
            var sortedGraph = serializer.SortGraph(original);
            original = CHEdgeGraphOsmStreamTarget.Preprocess(new XmlOsmStreamSource(
                                                                   Assembly.GetExecutingAssembly()
                                                                           .GetManifestResourceStream(embeddedString)),
                                                               interpreter,
                                                               Vehicle.Car);
            var basicRouterOriginal = new CHRouter();
            Router referenceRouter = Router.CreateCHFrom(
                original, basicRouterOriginal, interpreter);

            // try to do some routing on the deserialized version.
            var basicRouter = new CHRouter();
            Router router = Router.CreateCHFrom(
                new DynamicGraphRouterDataSource<CHEdgeData>(sortedGraph, original.TagsIndex), basicRouter, interpreter);

            // loop over all nodes and resolve their locations.
            var resolvedReference = new RouterPoint[original.VertexCount];
            var resolved = new RouterPoint[original.VertexCount];
            for (uint idx = 1; idx < original.VertexCount + 1; idx++)
            { // resolve each vertex.
                float latitude, longitude;
                if (original.GetVertex(idx, out latitude, out longitude))
                {
                    resolvedReference[idx - 1] = referenceRouter.Resolve(Vehicle.Car, new GeoCoordinate(latitude, longitude));
                    resolved[idx - 1] = router.Resolve(Vehicle.Car, new GeoCoordinate(latitude, longitude));
                }

                Assert.IsNotNull(resolvedReference[idx - 1]);
                Assert.IsNotNull(resolved[idx - 1]);

                //Assert.AreEqual(resolvedReference[idx - 1].Location.Latitude,
                //    resolved[idx - 1].Location.Latitude, 0.0001);
                //Assert.AreEqual(resolvedReference[idx - 1].Location.Longitude,
                //    resolved[idx - 1].Location.Longitude, 0.0001);
            }

            //// check all the routes having the same weight(s).
            //for (int fromIdx = 0; fromIdx < resolved.Length; fromIdx++)
            //{
            //    for (int toIdx = 0; toIdx < resolved.Length; toIdx++)
            //    {
            //        OsmSharpRoute referenceRoute = referenceRouter.Calculate(Vehicle.Car,
            //            resolvedReference[fromIdx], resolvedReference[toIdx]);
            //        OsmSharpRoute route = router.Calculate(Vehicle.Car,
            //            resolved[fromIdx], resolved[toIdx]);

            //        Assert.IsNotNull(referenceRoute);
            //        Assert.IsNotNull(route);
            //        //Assert.AreEqual(referenceRoute.TotalDistance, route.TotalDistance, 0.1);
            //        // TODO: meta data is missing in some CH routing; see issue
            //        //Assert.AreEqual(reference_route.TotalTime, route.TotalTime, 0.0001);
            //    }
            //}
        }
        public static Stream TestSerialization(string name, string pbfFile, DynamicGraphRouterDataSource<CHEdgeData> data)
        {
            var testOutputFile = new FileInfo(@"test.routing");
            testOutputFile.Delete();
            var writeStream = testOutputFile.OpenWrite();

            var performanceInfo = new PerformanceInfoConsumer("CHSerializer");
            performanceInfo.Start();
            performanceInfo.Report("Writing to {0}...", testOutputFile.Name);

            TagsCollectionBase metaData = new TagsCollection();
            metaData.Add("some_key", "some_value");
            var routingSerializer = new CHEdgeDataDataSourceSerializer();
            routingSerializer.Serialize(writeStream, data, metaData);

            writeStream.Dispose();

            OsmSharp.Logging.Log.TraceEvent("CHSerializer", OsmSharp.Logging.TraceEventType.Information,
                string.Format("Serialized file: {0}KB", testOutputFile.Length / 1024));

            performanceInfo.Stop();

            return testOutputFile.OpenRead();
        }
Пример #20
0
 public static void Initialize()
 {
     var routingSerializer = new CHEdgeDataDataSourceSerializer();
     _graph = routingSerializer.Deserialize(
         Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Android.Routing.Offline.kempen-big.osm.pbf.contracted.mobile.routing"));
 }
Пример #21
0
        /// <summary>
        /// Tests routing between two points and the associated instructions.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="stream"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        public static void TestSerializeRoutingInstrictions(string name, Stream stream,
            GeoCoordinate from, GeoCoordinate to)
        {
            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("CHSerializedRouting");
            performanceInfo.Start();
            performanceInfo.Report("Routing & generating instructions...");

            TagsCollectionBase metaData = null;
            var routingSerializer = new CHEdgeDataDataSourceSerializer(true);
            var graphDeserialized = routingSerializer.Deserialize(
                stream, out metaData, true);

            var interpreter = new OsmRoutingInterpreter();
            var router = Router.CreateCHFrom(
                graphDeserialized, new CHRouter(),
                interpreter);

            RouterPoint fromPoint = router.Resolve(Vehicle.Car, from);
            RouterPoint toPoint = router.Resolve(Vehicle.Car, to);

            List<Instruction> instructions = new List<Instruction>();
            if (fromPoint != null && toPoint != null)
            {
                Route route = router.Calculate(Vehicle.Car, fromPoint, toPoint);
                if (route != null)
                {
                    instructions = InstructionGenerator.Generate(route, interpreter);
                }
            }

            performanceInfo.Stop();

            if (instructions.Count == 0)
            {
                OsmSharp.Logging.Log.TraceEvent("CHSerializedRouting", OsmSharp.Logging.TraceEventType.Information,
                    "Routing unsuccesfull!");
            }
            else
            {
                foreach (Instruction instruction in instructions)
                {
                    OsmSharp.Logging.Log.TraceEvent("CHSerializedRouting", OsmSharp.Logging.TraceEventType.Information,
                        instruction.Text);
                }
            }
        }
        /// <summary>
        /// Creates a router.
        /// </summary>
        /// <param name="interpreter"></param>
        /// <param name="manifestResourceName"></param>
        /// <returns></returns>
        protected override Router CreateRouter(IOsmRoutingInterpreter interpreter, string manifestResourceName)
        {
            var tagsIndex = new TagsTableCollectionIndex();

            // do the data processing.
            var source = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(manifestResourceName));
            var data = CHEdgeGraphOsmStreamTarget.Preprocess(
                source, new OsmRoutingInterpreter(), Vehicle.Car);

            // serialize.
            var memoryStream = new MemoryStream();
            TagsCollectionBase metaData = new TagsCollection();
            metaData.Add("some_key", "some_value");
            var routingSerializer = new CHEdgeDataDataSourceSerializer();
            routingSerializer.Serialize(memoryStream, data, metaData);

            memoryStream.Seek(0, SeekOrigin.Begin);

            var deserialized = routingSerializer.Deserialize(memoryStream);

            return Router.CreateCHFrom(deserialized, new CHRouter(), new OsmRoutingInterpreter());
        }
Пример #23
0
        /// <summary>
        /// Raises the create event.
        /// </summary>
        /// <param name="bundle">Bundle.</param>
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

            // enable the logggin.
            OsmSharp.Logging.Log.Enable();
            OsmSharp.Logging.Log.RegisterListener(new OsmSharp.Android.UI.Log.LogTraceListener());

            // initialize map.
            var map = new Map();
            // add a tile layer.
            //map.AddLayer(new LayerTile(@"http://otile1.mqcdn.com/tiles/1.0.0/osm/{0}/{1}/{2}.png"));
            // add an online osm-data->mapCSS translation layer.
            //map.AddLayer(new OsmLayer(dataSource, mapCSSInterpreter));
            // add a pre-processed vector data file.
            var sceneStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"OsmSharp.Android.UI.Sample.kempen-big.osm.pbf.scene.layered");
            map.AddLayer(new LayerScene(Scene2D.Deserialize(sceneStream, true)));

            // define dummy from and to points.
            var from = new GeoCoordinate(51.261203, 4.780760);
            var to = new GeoCoordinate(51.267797, 4.801362);

            // deserialize the pre-processed graph.
            var routingSerializer = new CHEdgeDataDataSourceSerializer(false);
            TagsCollectionBase metaData = null;
            var graphStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.kempen-big.osm.pbf.routing");
            var graphDeserialized = routingSerializer.Deserialize(graphStream, out metaData, true);

            // initialize router.
            _router = Router.CreateCHFrom(graphDeserialized, new CHRouter(), new OsmRoutingInterpreter());

            // resolve points.
            RouterPoint routerPoint1 = _router.Resolve(Vehicle.Car, from);
            RouterPoint routerPoint2 = _router.Resolve(Vehicle.Car, to);

            // calculate route.
            Route route = _router.Calculate(Vehicle.Car, routerPoint1, routerPoint2);
            RouteTracker routeTracker = new RouteTracker(route, new OsmRoutingInterpreter());
            _enumerator = route.GetRouteEnumerable(10).GetEnumerator();

            // add a router layer.
            _routeLayer = new LayerRoute(map.Projection);
            _routeLayer.AddRoute (route, SimpleColor.FromKnownColor(KnownColor.Blue, 125).Value, 12);
            map.AddLayer(_routeLayer);

            // define the mapview.
            _mapView = new MapView(this, new MapViewSurface(this));
            //_mapView = new MapView(this, new MapViewGLSurface(this));
            //_mapView.MapTapEvent += new MapViewEvents.MapTapEventDelegate(_mapView_MapTapEvent);
            (_mapView as IMapView).AutoInvalidate = true;
            _mapView.Map = map;
            _mapView.MapMaxZoomLevel = 20;
            _mapView.MapMinZoomLevel = 10;
            _mapView.MapTilt = 0;
            _mapView.MapCenter = new GeoCoordinate(51.26371, 4.78601);
            _mapView.MapZoom = 18;

            // add markers.
            _mapView.AddMarker (from);
            _mapView.AddMarker (to);

            // initialize a text view to display routing instructions.
            _textView = new TextView(this);
            _textView.SetBackgroundColor(global::Android.Graphics.Color.White);
            _textView.SetTextColor(global::Android.Graphics.Color.Black);

            // add the mapview to the linear layout.
            var layout = new LinearLayout(this);
            layout.Orientation = Orientation.Vertical;
            layout.AddView(_textView);
            layout.AddView(_mapView);

            // create the route tracker animator.
            _routeTrackerAnimator = new RouteTrackerAnimator(_mapView, routeTracker, 5, 18);

            // simulate a number of gps-location update along the calculated route.
            Timer timer = new Timer(500);
            timer.Elapsed += new ElapsedEventHandler(TimerHandler);
            timer.Start();

            SetContentView (layout);
        }