Ejemplo n.º 1
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>
        /// 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()));
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
                }
            }
        }
Ejemplo n.º 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)
        {
            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));
        }
Ejemplo n.º 6
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;
        }
Ejemplo n.º 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(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));
        }
Ejemplo n.º 8
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());
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 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)
        {
            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);
        }
Ejemplo n.º 13
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"));
 }