/// <summary> /// Does the actual testing. /// </summary> /// <param name="embeddedString"></param> private void DoRoutingSerializationV2CHRoutingV2ComparisonTest(string embeddedString) { // 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); // create serializer. var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.CHEdgeDataDataSourceSerializer(); // serialize/deserialize. TagsCollectionBase metaData = new TagsCollection(); metaData.Add("some_key", "some_value"); byte[] byteArray; using (var stream = new MemoryStream()) { try { routingSerializer.Serialize(stream, original, metaData); byteArray = stream.ToArray(); } catch (Exception) { if (Debugger.IsAttached) { Debugger.Break(); } throw; } } IBasicRouterDataSource <CHEdgeData> deserializedVersion = routingSerializer.Deserialize(new MemoryStream(byteArray), out metaData); Assert.AreEqual(original.TagsIndex.Get(0), deserializedVersion.TagsIndex.Get(0)); Assert.IsTrue(deserializedVersion.SupportsProfile(Vehicle.Car)); Assert.IsFalse(deserializedVersion.SupportsProfile(Vehicle.Bicycle)); // create reference router. 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( deserializedVersion, basicRouter, interpreter); this.TestCompareAll(original, referenceRouter, router); }
public void RoutingSerializationV2CHRoutingComparisonTest() { 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); // create serializer. var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.CHEdgeDataDataSourceSerializer(true); // serialize/deserialize. byte[] byteArray; using (var stream = new MemoryStream()) { try { routingSerializer.Serialize(stream, original); byteArray = stream.ToArray(); } catch (Exception) { if (Debugger.IsAttached) { Debugger.Break(); } throw; } } IBasicRouterDataSource <CHEdgeData> deserializedVersion = routingSerializer.Deserialize(new MemoryStream(byteArray)); Assert.AreEqual(original.TagsIndex.Get(0), deserializedVersion.TagsIndex.Get(0)); // create reference router. 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( deserializedVersion, basicRouter, interpreter); //this.TestCompareAll(original, referenceRouter, router); }
private void InitializeRouting(OsmSharp.UI.Map.Map map) { //var osmInterpreter = new OsmRoutingInterpreter(); //_router = Router.CreateLiveFrom(new XmlOsmStreamSource(new FileInfo(@"c:\OSM\bin\wechel.osm").OpenRead()), // osmInterpreter); // creates a new interpreter. var interpreter = new OsmRoutingInterpreter(); var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.CHEdgeDataDataSourceSerializer(true); //var original = CHEdgeGraphOsmStreamWriter.Preprocess(new XmlOsmStreamSource( // new FileInfo(@"c:\OSM\bin\wechel.osm").OpenRead()), // interpreter, // Vehicle.Car); //byte[] byteArray; //using (var stream = new MemoryStream()) //{ // try // { // routingSerializer.Serialize(stream, original); // byteArray = stream.ToArray(); // } // catch (Exception) // { // throw; // } //} // Stream stream = new MemoryStream(byteArray); Stream stream = new FileInfo(@"c:\OSM\bin\wvl.osm.pbf.routing.ch.5").OpenRead(); IBasicRouterDataSource <CHEdgeData> deserializedVersion = routingSerializer.Deserialize(stream); var basicRouter = new CHRouter(deserializedVersion); _router = Router.CreateCHFrom( deserializedVersion, basicRouter, interpreter); _routeLayer = new LayerOsmSharpRoute(map.Projection); map.AddLayer(_routeLayer); }
/// <summary> /// Does the actual testing. /// </summary> /// <param name="embeddedString"></param> private void DoRoutingSerializationV2CHRoutingV2ComparisonTest(string embeddedString) { // 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); // create serializer. var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.CHEdgeDataDataSourceSerializer(false); // serialize/deserialize. TagsCollectionBase metaData = new TagsCollection(); metaData.Add("some_key", "some_value"); byte[] byteArray; using (var stream = new MemoryStream()) { try { routingSerializer.Serialize(stream, original, metaData); byteArray = stream.ToArray(); } catch (Exception) { if (Debugger.IsAttached) { Debugger.Break(); } throw; } } var deserializedVersion = routingSerializer.Deserialize(new MemoryStream(byteArray), out metaData); Assert.AreEqual(original.TagsIndex.Get(0), deserializedVersion.TagsIndex.Get(0)); Assert.IsTrue(deserializedVersion.SupportsProfile(Vehicle.Car)); Assert.IsFalse(deserializedVersion.SupportsProfile(Vehicle.Bicycle)); // create reference router. original = CHEdgeGraphOsmStreamTarget.Preprocess(new XmlOsmStreamSource( Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedString)), interpreter, Vehicle.Car); var basicRouterOriginal = new CHRouter(); var referenceRouter = Router.CreateCHFrom(original, basicRouterOriginal, interpreter); // try to do some routing on the deserialized version. var basicRouter = new CHRouter(); var router = Router.CreateCHFrom(deserializedVersion, basicRouter, interpreter); this.TestCompareAll(original, referenceRouter, router); }
public void RoutingSerializationV2CHRoutingComparisonTest() { 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); // create serializer. var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.CHEdgeDataDataSourceSerializer(true); // serialize/deserialize. byte[] byteArray; using (var stream = new MemoryStream()) { try { routingSerializer.Serialize(stream, original); byteArray = stream.ToArray(); } catch (Exception) { if (Debugger.IsAttached) { Debugger.Break(); } throw; } } IBasicRouterDataSource<CHEdgeData> deserializedVersion = routingSerializer.Deserialize(new MemoryStream(byteArray)); Assert.AreEqual(original.TagsIndex.Get(0), deserializedVersion.TagsIndex.Get(0)); // create reference router. 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( deserializedVersion, basicRouter, interpreter); //this.TestCompareAll(original, referenceRouter, router); }
public override void LoadView() { OsmSharp.Logging.Log.Enable(); base.LoadView(); // initialize a test-map. var map = new Map(); map.AddLayer(new LayerScene(Scene2DLayered.Deserialize( Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.iOS.UI.Sample.wvl.map"), true))); // Perform any additional setup after loading the view, typically from a nib. MapView mapView = new MapView(); _mapView = mapView; //mapViewAnimator = new MapViewAnimator (mapView); mapView.Map = map; mapView.MapCenter = new GeoCoordinate(51.158075, 2.961545); // gistel // mapView.MapTapEvent+= delegate(GeoCoordinate geoCoordinate) { // mapView.AddMarker(geoCoordinate).TouchDown += MapMarkerClicked; // }; mapView.MapMaxZoomLevel = 18; mapView.MapMinZoomLevel = 12; mapView.MapZoom = 16; mapView.MapTilt = 30; var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.CHEdgeDataDataSourceSerializer(false); var graphDeserialized = routingSerializer.Deserialize( Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.iOS.UI.Sample.wvl.routing"), true); _router = Router.CreateCHFrom( graphDeserialized, new CHRouter(graphDeserialized), new OsmRoutingInterpreter()); // long before = DateTime.Now.Ticks; // // var routeLocations = new GeoCoordinate[] { // new GeoCoordinate (50.8247730, 2.7524706), // new GeoCoordinate (50.8496394, 2.7301512), // new GeoCoordinate (50.8927741, 2.6138545), // new GeoCoordinate (50.8296363, 2.8869437) // }; // // var routerPoints = new RouterPoint[routeLocations.Length]; // for (int idx = 0; idx < routeLocations.Length; idx++) { // routerPoints [idx] = router.Resolve (Vehicle.Car, routeLocations [idx]); // // mapView.AddMarker (routeLocations [idx]); // } // OsmSharp.Routing.TSP.RouterTSPWrapper<RouterTSPAEXGenetic> tspRouter = new OsmSharp.Routing.TSP.RouterTSPWrapper<RouterTSPAEXGenetic> ( // new RouterTSPAEXGenetic (10, 20), router); // // Route route = tspRouter.CalculateTSP (Vehicle.Car, routerPoints); // // long after = DateTime.Now.Ticks; // // OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", System.Diagnostics.TraceEventType.Information,"Routing & TSP in {0}ms", // new TimeSpan (after - before).TotalMilliseconds); // 51.160477" lon="2.961497 GeoCoordinate point1 = new GeoCoordinate(51.158075, 2.961545); GeoCoordinate point2 = new GeoCoordinate(51.190503, 3.004793); //GeoCoordinate point1 = new GeoCoordinate(51.159132, 2.958755); //GeoCoordinate point2 = new GeoCoordinate(51.160477, 2.961497); RouterPoint routerPoint1 = _router.Resolve(Vehicle.Car, point1); RouterPoint routerPoint2 = _router.Resolve(Vehicle.Car, point2); Route route1 = _router.Calculate(Vehicle.Car, routerPoint1, routerPoint2); _enumerator = route1.GetRouteEnumerable(10).GetEnumerator(); //List<Instruction> instructions = InstructionGenerator.Generate(route1, new OsmRoutingInterpreter()); // _routeLayer = new LayerRoute(map.Projection); _routeLayer.AddRoute(route1); map.AddLayer(_routeLayer); View = mapView; mapView.AddMarker(new GeoCoordinate(51.1612, 2.9795)); mapView.AddMarker(new GeoCoordinate(51.1447, 2.9483)); mapView.AddMarker(point1); mapView.AddMarker(point2); mapView.AddMarker(new GeoCoordinate(51.1612, 2.9795)); mapView.AddMarker(new GeoCoordinate(51.1447, 2.9483)); mapView.AddMarker(new GeoCoordinate(51.1612, 2.9795)); mapView.AddMarker(new GeoCoordinate(51.1447, 2.9483)); // // //mapView.ZoomToMarkers(); //GeoCoordinateBox box = new GeoCoordinateBox (new GeoCoordinate[] { point1, point2 }); // mapView.MapTapEvent += delegate(GeoCoordinate geoCoordinate) { //_routeTrackerAnimator.Track(box.GenerateRandomIn()); //_mapView.AddMarker(geoCoordinate).Click += new EventHandler(MainActivity_Click); //mapViewAnimator.Stop(); //mapViewAnimator.Start(geoCoordinate, 15, new TimeSpan(0, 0, 2)); }; RouteTracker routeTracker = new RouteTracker(route1, new OsmRoutingInterpreter()); _routeTrackerAnimator = new RouteTrackerAnimator(mapView, routeTracker, 5); // // Timer timer = new Timer (150); // timer.Elapsed += new ElapsedEventHandler (TimerHandler); // timer.Start (); // // Task.Factory.StartNew (() => { // System.Threading.Thread.Sleep(200); // do something. // InvokeOnMainThread (() => { // mapView.ZoomToMarkers (); // }); // }); // }
public void RoutingSerializationCHSortedRoutingComparisonTest() { 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); // create serializer. var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.CHEdgeDataDataSourceSerializer(true); // serialize/deserialize. TagsCollectionBase metaData = new TagsCollection(); metaData.Add("some_key", "some_value"); byte[] byteArray; using (var stream = new MemoryStream()) { try { routingSerializer.Serialize(stream, original, metaData); byteArray = stream.ToArray(); } catch (Exception) { if (Debugger.IsAttached) { Debugger.Break(); } throw; } } IBasicRouterDataSource<CHEdgeData> deserializedVersion = routingSerializer.Deserialize(new MemoryStream(byteArray), out metaData); Assert.AreEqual(original.TagsIndex.Get(0), deserializedVersion.TagsIndex.Get(0)); Assert.IsTrue(deserializedVersion.SupportsProfile(Vehicle.Car)); Assert.IsFalse(deserializedVersion.SupportsProfile(Vehicle.Bicycle)); // create reference router. 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( deserializedVersion, 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(VehicleEnum.Car, // resolvedReference[fromIdx], resolvedReference[toIdx]); // OsmSharpRoute route = router.Calculate(VehicleEnum.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 void RoutingSerializationCHSortedRoutingComparisonTest() { 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); // create serializer. var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.CHEdgeDataDataSourceSerializer(true); // serialize/deserialize. byte[] byteArray; using (var stream = new MemoryStream()) { try { routingSerializer.Serialize(stream, original); byteArray = stream.ToArray(); } catch (Exception) { if (Debugger.IsAttached) { Debugger.Break(); } throw; } } IBasicRouterDataSource <CHEdgeData> deserializedVersion = routingSerializer.Deserialize(new MemoryStream(byteArray)); Assert.AreEqual(original.TagsIndex.Get(0), deserializedVersion.TagsIndex.Get(0)); // create reference router. 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( deserializedVersion, 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(VehicleEnum.Car, // resolvedReference[fromIdx], resolvedReference[toIdx]); // OsmSharpRoute route = router.Calculate(VehicleEnum.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); // } // } }
/// <summary> /// Raises the create event. /// </summary> /// <param name="bundle">Bundle.</param> protected override void OnCreate(Bundle bundle) { base.OnCreate (bundle); OsmSharp.Logging.Log.Enable(); // OsmSharp.IO.Output.OutputStreamHost.RegisterOutputStream ( // new OsmSharp.Android.UI.IO.Output.ConsoleOutputStream ()); // create the MapCSS image source. var imageSource = new MapCSSDictionaryImageSource(); imageSource.Add("styles/default/parking.png", Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.images.parking.png")); imageSource.Add("styles/default/bus.png", Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.images.bus.png")); imageSource.Add("styles/default/postbox.png", Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.images.postbox.png")); // // load mapcss style interpreter. // var mapCSSInterpreter = new MapCSSInterpreter( // Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.test.mapcss"), // imageSource); // initialize the data source. //var dataSource = new MemoryDataSource(); // var source = new XmlOsmStreamReader( // Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.test.osm")); // var source = new PBFOsmStreamReader( // Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.test.osm.pbf")); // dataSource.PullFromSource(source); // initialize map. var map = new Map(); //map.AddLayer(new LayerTile(@"http://otile1.mqcdn.com/tiles/1.0.0/osm/{0}/{1}/{2}.png")); //map.AddLayer(new OsmLayer(dataSource, mapCSSInterpreter)); // map.AddLayer(new LayerScene(Scene2DSimple.Deserialize( // Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.wvl.osm.pbf.scene.simple"), true))); map.AddLayer( new LayerScene( Scene2DLayered.Deserialize( Assembly.GetExecutingAssembly().GetManifestResourceStream(@"OsmSharp.Android.UI.Sample.wvl.map"), true))); // var routingSerializer = new V2RoutingDataSourceLiveEdgeSerializer(true); // var graphSerialized = routingSerializer.Deserialize( // //Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.test.osm.pbf.routing.3")); // Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.wvl.pbf.routing.4")); //// //// var graphLayer = new LayerDynamicGraphLiveEdge(graphSerialized, mapCSSInterpreter); //// map.AddLayer(graphLayer); // // // calculate route. // Router router = Router.CreateLiveFrom( // graphSerialized, // new OsmRoutingInterpreter()); var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.CHEdgeDataDataSourceSerializer(false); var graphDeserialized = routingSerializer.Deserialize( Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.wvl.routing"), true); _router = Router.CreateCHFrom( graphDeserialized, new CHRouter(), new OsmRoutingInterpreter()); GeoCoordinate point1 = new GeoCoordinate(51.158075, 2.961545); GeoCoordinate point2 = new GeoCoordinate(51.190503, 3.004793); RouterPoint routerPoint1 = _router.Resolve(Vehicle.Car, point1); RouterPoint routerPoint2 = _router.Resolve(Vehicle.Car, point2); Route route1 = _router.Calculate(Vehicle.Car, routerPoint1, routerPoint2); RouteTracker routeTracker = new RouteTracker(route1, new OsmRoutingInterpreter()); _enumerator = route1.GetRouteEnumerable(20).GetEnumerator(); _routeLayer = new LayerRoute(map.Projection); _routeLayer.AddRoute (route1, SimpleColor.FromKnownColor(KnownColor.Blue).Value); map.AddLayer(_routeLayer); // // create gpx layer. // LayerGpx gpxLayer = new LayerGpx(map.Projection); // gpxLayer.AddGpx( // Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.test.gpx")); // map.AddLayer(gpxLayer); // // set control properties. // var mapView = new MapView(this); // mapView.MapMaxZoomLevel = 20; // mapView.MapMinZoomLevel = 12; // //var mapView = new MapGLView (this); // mapView.Map = map; // //mapView.Center = new GeoCoordinate(51.158075, 2.961545); // gistel // //mapView.MapCenter = new GeoCoordinate (50.88672, 3.23899); // mapView.MapCenter = new GeoCoordinate(51.26337, 4.78739); // //mapView.Center = new GeoCoordinate(51.156803, 2.958887); // mapView.MapZoomLevel = 15; // var mapView = new OpenGLRenderer2D( // this, null); // _mapView = new MapView<MapGLView>(this, new MapGLView(this)); _mapView = new MapView(this, new MapViewSurface(this)); //_mapView = new MapView(this, new MapViewGLSurface(this)); _mapView.Map = map; (_mapView as IMapView).AutoInvalidate = true; _mapView.MapMaxZoomLevel = 20; _mapView.MapMinZoomLevel = 12; _mapView.MapTilt = 0; //var mapView = new MapGLView (this); _mapView.MapCenter = new GeoCoordinate(51.158075, 2.961545); // gistel //mapView.MapCenter = new GeoCoordinate (50.88672, 3.23899); //mapLayout.MapCenter = new GeoCoordinate(51.26337, 4.78739); //mapView.Center = new GeoCoordinate(51.156803, 2.958887); _mapView.MapZoom = 17; //MapViewAnimator mapViewAnimator = new MapViewAnimator(mapLayout); //_mapView.MapTapEvent += delegate(GeoCoordinate geoCoordinate) //{ // _mapView.ZoomToMarkers(); // //_mapView.AddMarker(geoCoordinate).Click += new EventHandler(MainActivity_Click); // //mapViewAnimator.Stop(); // //mapViewAnimator.Start(geoCoordinate, 15, new TimeSpan(0, 0, 2)); //}; //Create the user interface in code var layout = new RelativeLayout (this); layout.AddView(_mapView); _mapView.AddMarker(new GeoCoordinate(51.1612, 2.9795)); _mapView.AddMarker(new GeoCoordinate(51.1447, 2.9483)); //_mapView.ZoomToMarkers(); _routeTrackerAnimator = new RouteTrackerAnimator(_mapView, routeTracker, 5); Timer timer = new Timer(250); timer.Elapsed += new ElapsedEventHandler(TimerHandler); timer.Start(); SetContentView (layout); }
public void RoutingSerializationCHEdgeData() { const string embeddedString = "OsmSharp.Test.Unittests.test_network_real1.osm"; // load the network. var referenceNetwork = CHEdgeGraphOsmStreamTarget.Preprocess(new XmlOsmStreamSource( Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedString)), new OsmRoutingInterpreter(), Vehicle.Car); // serialize network. var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.CHEdgeDataDataSourceSerializer(false); // serialize/deserialize. TagsCollectionBase metaData = new TagsCollection(); metaData.Add("some_key", "some_value"); byte[] byteArray; using (var stream = new MemoryStream()) { try { routingSerializer.Serialize(stream, referenceNetwork, metaData); byteArray = stream.ToArray(); } catch (Exception) { if (Debugger.IsAttached) { Debugger.Break(); } throw; } } var network = routingSerializer.Deserialize(new MemoryStream(byteArray), out metaData); // compare networks. Assert.IsNotNull(network); // Assert.AreEqual(referenceNetwork.VertexCount, network.VertexCount); for (uint vertex = 1; vertex < referenceNetwork.VertexCount; vertex++) { float referenceLatitude, referenceLongitude, latitude, longitude; Assert.IsTrue(referenceNetwork.GetVertex(vertex, out referenceLatitude, out referenceLongitude)); Assert.IsTrue(network.GetVertex(vertex, out latitude, out longitude)); Assert.AreEqual(referenceLatitude, latitude); Assert.AreEqual(referenceLongitude, longitude); var referenceArcs = referenceNetwork.GetEdges(vertex).ToKeyValuePairs(); var arcs = network.GetEdges(vertex).ToKeyValuePairs(); Assert.AreEqual(referenceArcs.Length, arcs.Length); for (int idx = 0; idx < referenceArcs.Length; idx++) { var referenceArc = referenceArcs[idx]; // find the same edge in the new arcs. var arc = arcs.First((x) => { return x.Key == referenceArcs[idx].Key; }); Assert.AreEqual(referenceArc.Key, arc.Key); Assert.AreEqual(referenceArc.Value.Forward, arc.Value.Forward); Assert.AreEqual(referenceArc.Value.ForwardWeight, arc.Value.ForwardWeight); Assert.AreEqual(referenceArc.Value.ForwardContractedId, arc.Value.ForwardContractedId); Assert.AreEqual(referenceArc.Value.Backward, arc.Value.Backward); Assert.AreEqual(referenceArc.Value.BackwardWeight, arc.Value.BackwardWeight); Assert.AreEqual(referenceArc.Value.BackwardContractedId, arc.Value.BackwardContractedId); Assert.AreEqual(referenceArc.Value.RepresentsNeighbourRelations, arc.Value.RepresentsNeighbourRelations); Assert.AreEqual(referenceArc.Value.Tags, arc.Value.Tags); ICoordinateCollection referenceCoordinates; ICoordinateCollection coordinates; if (referenceNetwork.GetEdgeShape(vertex, referenceArc.Key, out referenceCoordinates)) { // there is a shape. Assert.IsTrue(network.GetEdgeShape(vertex, arc.Key, out coordinates)); if (referenceCoordinates == null) { // reference shape is null, shape is null. Assert.IsNull(coordinates); } else { // reference shape is not null compare them. Assert.IsNotNull(coordinates); referenceCoordinates.Reset(); coordinates.Reset(); while (referenceCoordinates.MoveNext()) { Assert.IsTrue(coordinates.MoveNext()); Assert.AreEqual(referenceCoordinates.Latitude, coordinates.Latitude); Assert.AreEqual(referenceCoordinates.Longitude, coordinates.Longitude); } Assert.IsFalse(coordinates.MoveNext()); } } else { // there is no shape. Assert.IsFalse(network.GetEdgeShape(vertex, arc.Key, out coordinates)); } if (referenceNetwork.GetEdgeShape(referenceArc.Key, vertex, out referenceCoordinates)) { // there is a shape. Assert.IsTrue(network.GetEdgeShape(arc.Key, vertex, out coordinates)); if (referenceCoordinates == null) { // reference shape is null, shape is null. Assert.IsNull(coordinates); } else { // reference shape is not null compare them. Assert.IsNotNull(coordinates); referenceCoordinates.Reset(); coordinates.Reset(); while (referenceCoordinates.MoveNext()) { Assert.IsTrue(coordinates.MoveNext()); Assert.AreEqual(referenceCoordinates.Latitude, coordinates.Latitude); Assert.AreEqual(referenceCoordinates.Longitude, coordinates.Longitude); } Assert.IsFalse(coordinates.MoveNext()); } } else { // there is no shape. Assert.IsFalse(network.GetEdgeShape(vertex, arc.Key, out coordinates)); } // check tags. var referenceTags = referenceNetwork.TagsIndex.Get(referenceArc.Value.Tags); var tags = network.TagsIndex.Get(arc.Value.Tags); if (referenceTags == null) { // other tags also have to be null. Assert.IsNull(tags); } else { // contents need to be the same. Assert.AreEqual(referenceTags.Count, tags.Count); foreach (var referenceTag in referenceTags) { Assert.IsTrue(tags.ContainsKeyValue(referenceTag.Key, referenceTag.Value)); } } } } }
public override void LoadView() { OsmSharp.Logging.Log.Enable (); base.LoadView (); // initialize a test-map. var map = new Map (); map.AddLayer (new LayerScene (Scene2DLayered.Deserialize ( Assembly.GetExecutingAssembly ().GetManifestResourceStream ("OsmSharp.iOS.UI.Sample.wvl.map"), true))); // Perform any additional setup after loading the view, typically from a nib. MapView mapView = new MapView (); _mapView = mapView; //mapViewAnimator = new MapViewAnimator (mapView); mapView.Map = map; mapView.MapCenter = new GeoCoordinate(51.158075, 2.961545); // gistel // mapView.MapTapEvent+= delegate(GeoCoordinate geoCoordinate) { // mapView.AddMarker(geoCoordinate).TouchDown += MapMarkerClicked; // }; mapView.MapMaxZoomLevel = 18; mapView.MapMinZoomLevel = 12; mapView.MapZoom = 16; mapView.MapTilt = 30; var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.CHEdgeDataDataSourceSerializer(false); var graphDeserialized = routingSerializer.Deserialize( Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.iOS.UI.Sample.wvl.routing"), true); _router = Router.CreateCHFrom( graphDeserialized, new CHRouter(graphDeserialized), new OsmRoutingInterpreter()); // long before = DateTime.Now.Ticks; // // var routeLocations = new GeoCoordinate[] { // new GeoCoordinate (50.8247730, 2.7524706), // new GeoCoordinate (50.8496394, 2.7301512), // new GeoCoordinate (50.8927741, 2.6138545), // new GeoCoordinate (50.8296363, 2.8869437) // }; // // var routerPoints = new RouterPoint[routeLocations.Length]; // for (int idx = 0; idx < routeLocations.Length; idx++) { // routerPoints [idx] = router.Resolve (Vehicle.Car, routeLocations [idx]); // // mapView.AddMarker (routeLocations [idx]); // } // OsmSharp.Routing.TSP.RouterTSPWrapper<RouterTSPAEXGenetic> tspRouter = new OsmSharp.Routing.TSP.RouterTSPWrapper<RouterTSPAEXGenetic> ( // new RouterTSPAEXGenetic (10, 20), router); // // Route route = tspRouter.CalculateTSP (Vehicle.Car, routerPoints); // // long after = DateTime.Now.Ticks; // // OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", System.Diagnostics.TraceEventType.Information,"Routing & TSP in {0}ms", // new TimeSpan (after - before).TotalMilliseconds); // 51.160477" lon="2.961497 GeoCoordinate point1 = new GeoCoordinate(51.158075, 2.961545); GeoCoordinate point2 = new GeoCoordinate(51.190503, 3.004793); //GeoCoordinate point1 = new GeoCoordinate(51.159132, 2.958755); //GeoCoordinate point2 = new GeoCoordinate(51.160477, 2.961497); RouterPoint routerPoint1 = _router.Resolve(Vehicle.Car, point1); RouterPoint routerPoint2 = _router.Resolve(Vehicle.Car, point2); Route route1 = _router.Calculate(Vehicle.Car, routerPoint1, routerPoint2); _enumerator = route1.GetRouteEnumerable(10).GetEnumerator(); //List<Instruction> instructions = InstructionGenerator.Generate(route1, new OsmRoutingInterpreter()); // _routeLayer = new LayerRoute(map.Projection); _routeLayer.AddRoute (route1); map.AddLayer(_routeLayer); View = mapView; mapView.AddMarker(new GeoCoordinate(51.1612, 2.9795)); mapView.AddMarker(new GeoCoordinate(51.1447, 2.9483)); mapView.AddMarker(point1); mapView.AddMarker(point2); mapView.AddMarker(new GeoCoordinate(51.1612, 2.9795)); mapView.AddMarker(new GeoCoordinate(51.1447, 2.9483)); mapView.AddMarker(new GeoCoordinate(51.1612, 2.9795)); mapView.AddMarker(new GeoCoordinate(51.1447, 2.9483)); // // //mapView.ZoomToMarkers(); //GeoCoordinateBox box = new GeoCoordinateBox (new GeoCoordinate[] { point1, point2 }); // mapView.MapTapEvent += delegate(GeoCoordinate geoCoordinate) { //_routeTrackerAnimator.Track(box.GenerateRandomIn()); //_mapView.AddMarker(geoCoordinate).Click += new EventHandler(MainActivity_Click); //mapViewAnimator.Stop(); //mapViewAnimator.Start(geoCoordinate, 15, new TimeSpan(0, 0, 2)); }; RouteTracker routeTracker = new RouteTracker(route1, new OsmRoutingInterpreter()); _routeTrackerAnimator = new RouteTrackerAnimator(mapView, routeTracker, 5); // // Timer timer = new Timer (150); // timer.Elapsed += new ElapsedEventHandler (TimerHandler); // timer.Start (); // // Task.Factory.StartNew (() => { // System.Threading.Thread.Sleep(200); // do something. // InvokeOnMainThread (() => { // mapView.ZoomToMarkers (); // }); // }); // }
/// <summary> /// Raises the create event. /// </summary> /// <param name="bundle">Bundle.</param> protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); OsmSharp.Logging.Log.Enable(); // OsmSharp.IO.Output.OutputStreamHost.RegisterOutputStream ( // new OsmSharp.Android.UI.IO.Output.ConsoleOutputStream ()); // create the MapCSS image source. var imageSource = new MapCSSDictionaryImageSource(); imageSource.Add("styles/default/parking.png", Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.images.parking.png")); imageSource.Add("styles/default/bus.png", Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.images.bus.png")); imageSource.Add("styles/default/postbox.png", Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.images.postbox.png")); // // load mapcss style interpreter. // var mapCSSInterpreter = new MapCSSInterpreter( // Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.test.mapcss"), // imageSource); // initialize the data source. //var dataSource = new MemoryDataSource(); // var source = new XmlOsmStreamReader( // Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.test.osm")); // var source = new PBFOsmStreamReader( // Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.test.osm.pbf")); // dataSource.PullFromSource(source); // initialize map. var map = new Map(); //map.AddLayer(new LayerTile(@"http://otile1.mqcdn.com/tiles/1.0.0/osm/{0}/{1}/{2}.png")); //map.AddLayer(new OsmLayer(dataSource, mapCSSInterpreter)); // map.AddLayer(new LayerScene(Scene2DSimple.Deserialize( // Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.wvl.osm.pbf.scene.simple"), true))); map.AddLayer( new LayerScene( Scene2DLayered.Deserialize( Assembly.GetExecutingAssembly().GetManifestResourceStream(@"OsmSharp.Android.UI.Sample.wvl.map"), true))); // var routingSerializer = new V2RoutingDataSourceLiveEdgeSerializer(true); // var graphSerialized = routingSerializer.Deserialize( // //Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.test.osm.pbf.routing.3")); // Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.wvl.pbf.routing.4")); //// //// var graphLayer = new LayerDynamicGraphLiveEdge(graphSerialized, mapCSSInterpreter); //// map.AddLayer(graphLayer); // // // calculate route. // Router router = Router.CreateLiveFrom( // graphSerialized, // new OsmRoutingInterpreter()); var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.CHEdgeDataDataSourceSerializer(false); var graphDeserialized = routingSerializer.Deserialize( Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.wvl.routing"), true); _router = Router.CreateCHFrom( graphDeserialized, new CHRouter(), new OsmRoutingInterpreter()); GeoCoordinate point1 = new GeoCoordinate(51.158075, 2.961545); GeoCoordinate point2 = new GeoCoordinate(51.190503, 3.004793); RouterPoint routerPoint1 = _router.Resolve(Vehicle.Car, point1); RouterPoint routerPoint2 = _router.Resolve(Vehicle.Car, point2); Route route1 = _router.Calculate(Vehicle.Car, routerPoint1, routerPoint2); RouteTracker routeTracker = new RouteTracker(route1, new OsmRoutingInterpreter()); _enumerator = route1.GetRouteEnumerable(20).GetEnumerator(); _routeLayer = new LayerRoute(map.Projection); _routeLayer.AddRoute(route1, SimpleColor.FromKnownColor(KnownColor.Blue).Value); map.AddLayer(_routeLayer); // // create gpx layer. // LayerGpx gpxLayer = new LayerGpx(map.Projection); // gpxLayer.AddGpx( // Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.test.gpx")); // map.AddLayer(gpxLayer); // // set control properties. // var mapView = new MapView(this); // mapView.MapMaxZoomLevel = 20; // mapView.MapMinZoomLevel = 12; // //var mapView = new MapGLView (this); // mapView.Map = map; // //mapView.Center = new GeoCoordinate(51.158075, 2.961545); // gistel // //mapView.MapCenter = new GeoCoordinate (50.88672, 3.23899); // mapView.MapCenter = new GeoCoordinate(51.26337, 4.78739); // //mapView.Center = new GeoCoordinate(51.156803, 2.958887); // mapView.MapZoomLevel = 15; // var mapView = new OpenGLRenderer2D( // this, null); // _mapView = new MapView<MapGLView>(this, new MapGLView(this)); _mapView = new MapView(this, new MapViewSurface(this)); //_mapView = new MapView(this, new MapViewGLSurface(this)); _mapView.Map = map; (_mapView as IMapView).AutoInvalidate = true; _mapView.MapMaxZoomLevel = 20; _mapView.MapMinZoomLevel = 12; _mapView.MapTilt = 0; //var mapView = new MapGLView (this); _mapView.MapCenter = new GeoCoordinate(51.158075, 2.961545); // gistel //mapView.MapCenter = new GeoCoordinate (50.88672, 3.23899); //mapLayout.MapCenter = new GeoCoordinate(51.26337, 4.78739); //mapView.Center = new GeoCoordinate(51.156803, 2.958887); _mapView.MapZoom = 17; //MapViewAnimator mapViewAnimator = new MapViewAnimator(mapLayout); //_mapView.MapTapEvent += delegate(GeoCoordinate geoCoordinate) //{ // _mapView.ZoomToMarkers(); // //_mapView.AddMarker(geoCoordinate).Click += new EventHandler(MainActivity_Click); // //mapViewAnimator.Stop(); // //mapViewAnimator.Start(geoCoordinate, 15, new TimeSpan(0, 0, 2)); //}; //Create the user interface in code var layout = new RelativeLayout(this); layout.AddView(_mapView); _mapView.AddMarker(new GeoCoordinate(51.1612, 2.9795)); _mapView.AddMarker(new GeoCoordinate(51.1447, 2.9483)); //_mapView.ZoomToMarkers(); _routeTrackerAnimator = new RouteTrackerAnimator(_mapView, routeTracker, 5); Timer timer = new Timer(250); timer.Elapsed += new ElapsedEventHandler(TimerHandler); timer.Start(); SetContentView(layout); }
public void RoutingSerializationCHEdgeData() { const string embeddedString = "OsmSharp.Test.Unittests.test_network_real1.osm"; // load the network. var referenceNetwork = CHEdgeGraphOsmStreamTarget.Preprocess(new XmlOsmStreamSource( Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedString)), new OsmRoutingInterpreter(), Vehicle.Car); // serialize network. var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.CHEdgeDataDataSourceSerializer(false); // serialize/deserialize. TagsCollectionBase metaData = new TagsCollection(); metaData.Add("some_key", "some_value"); byte[] byteArray; using (var stream = new MemoryStream()) { try { routingSerializer.Serialize(stream, referenceNetwork, metaData); byteArray = stream.ToArray(); } catch (Exception) { if (Debugger.IsAttached) { Debugger.Break(); } throw; } } var network = routingSerializer.Deserialize(new MemoryStream(byteArray), out metaData); // compare networks. Assert.IsNotNull(network); // Assert.AreEqual(referenceNetwork.VertexCount, network.VertexCount); for (uint vertex = 1; vertex < referenceNetwork.VertexCount; vertex++) { float referenceLatitude, referenceLongitude, latitude, longitude; Assert.IsTrue(referenceNetwork.GetVertex(vertex, out referenceLatitude, out referenceLongitude)); Assert.IsTrue(network.GetVertex(vertex, out latitude, out longitude)); Assert.AreEqual(referenceLatitude, latitude); Assert.AreEqual(referenceLongitude, longitude); var referenceArcs = referenceNetwork.GetEdges(vertex).ToKeyValuePairsAndShapes(); var arcs = network.GetEdges(vertex).ToKeyValuePairsAndShapes(); Assert.AreEqual(referenceArcs.Length, arcs.Length); for (int idx = 0; idx < referenceArcs.Length; idx++) { var referenceArc = referenceArcs[idx]; // find the same edge in the new arcs. var arc = arcs.First((x) => { return(x.Key == referenceArcs[idx].Key && x.Value.Key.Equals(referenceArcs[idx].Value.Key)); }); Assert.AreEqual(referenceArc.Key, arc.Key); Assert.AreEqual(referenceArc.Value.Key.Meta, arc.Value.Key.Meta); Assert.AreEqual(referenceArc.Value.Key.Value, arc.Value.Key.Value); Assert.AreEqual(referenceArc.Value.Key.Weight, arc.Value.Key.Weight); Assert.AreEqual(referenceArc.Value.Key.RepresentsNeighbourRelations, arc.Value.Key.RepresentsNeighbourRelations); Assert.AreEqual(referenceArc.Value.Key.Tags, arc.Value.Key.Tags); var referenceCoordinates = referenceArc.Value.Value; var coordinates = arc.Value.Value; if (referenceCoordinates == null) { // reference shape is null, shape is null. Assert.IsNull(coordinates); } else { // reference shape is not null compare them. Assert.IsNotNull(coordinates); referenceCoordinates.Reset(); coordinates.Reset(); while (referenceCoordinates.MoveNext()) { Assert.IsTrue(coordinates.MoveNext()); Assert.AreEqual(referenceCoordinates.Latitude, coordinates.Latitude); Assert.AreEqual(referenceCoordinates.Longitude, coordinates.Longitude); } Assert.IsFalse(coordinates.MoveNext()); } // check tags. if (!referenceArc.Value.Key.IsContracted) { var referenceTags = referenceNetwork.TagsIndex.Get(referenceArc.Value.Key.Tags); var tags = network.TagsIndex.Get(arc.Value.Key.Tags); if (referenceTags == null) { // other tags also have to be null. Assert.IsNull(tags); } else { // contents need to be the same. Assert.AreEqual(referenceTags.Count, tags.Count); foreach (var referenceTag in referenceTags) { Assert.IsTrue(tags.ContainsKeyValue(referenceTag.Key, referenceTag.Value)); } } } } } }