/// <summary> /// Gets a feature collection with features representing the stop links. /// </summary> /// <returns></returns> public static FeatureCollection GetStopLinks(this MultimodalDb db, Profile profile, uint stopId) { var features = new FeatureCollection(); var stopEnumerator = db.TransitDb.GetStopsEnumerator(); if (stopEnumerator.MoveTo(stopId)) { var stopLocation = new GeoAPI.Geometries.Coordinate(stopEnumerator.Longitude, stopEnumerator.Latitude); var attributes = new AttributesTable(); attributes.AddAttribute("stop_id", stopId); features.Add(new Feature(new Point(stopLocation), attributes)); var stopLinksDb = db.GetStopLinksDb(profile).GetEnumerator(); stopLinksDb.MoveTo(stopId); while (stopLinksDb.MoveNext()) { var routerPoint = new RouterPoint(0, 0, stopLinksDb.EdgeId, stopLinksDb.Offset); var linkLocation = routerPoint.LocationOnNetwork(db.RouterDb).ToCoordinate(); attributes = new AttributesTable(); attributes.AddAttribute("edge_id", stopLinksDb.EdgeId.ToInvariantString()); attributes.AddAttribute("offset", stopLinksDb.Offset.ToInvariantString()); features.Add(new Feature(new Point(linkLocation), attributes)); features.Add(new Feature(new LineString(new GeoAPI.Geometries.Coordinate[] { stopLocation, linkLocation }), new AttributesTable())); } } return(features); }
public void TestAddStopLinksDb() { // build a simple network and connections db. var routerDb = new RouterDb(); routerDb.LoadTestNetwork( System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream( "Itinero.Transit.Test.test_data.networks.network1.geojson")); var transitDb = new TransitDb(); var feed = DummyGTFSFeedBuilder.OneConnection( TimeOfDay.FromTotalSeconds(0), TimeOfDay.FromTotalSeconds(3600)); feed.Stops.Get(0).Latitude = 51.22965768754021f; feed.Stops.Get(0).Longitude = 4.460974931716918f; feed.Stops.Get(1).Latitude = 51.229617377118906f; feed.Stops.Get(1).Longitude = 4.463152885437011f; transitDb.LoadFrom(feed); var db = new MultimodalDb(routerDb, transitDb); // add stop links. var profile = VehicleMock.Car().Fastest(); db.AddStopLinksDb(profile); // check result. var stopLinksDb = db.GetStopLinksDb(profile); Assert.IsNotNull(stopLinksDb); var stop0 = db.TransitDb.SearchFirstStopsWithTags((t) => { return(t.Contains("id", "0")); }); var stop1 = db.TransitDb.SearchFirstStopsWithTags((t) => { return(t.Contains("id", "1")); }); var stopLinksDbEnumerator = stopLinksDb.GetEnumerator(); stopLinksDbEnumerator.MoveTo(stop0); Assert.AreEqual(1, stopLinksDbEnumerator.Count); Assert.IsTrue(stopLinksDbEnumerator.MoveNext()); Assert.AreEqual(0, stopLinksDbEnumerator.EdgeId); Assert.AreEqual(0, stopLinksDbEnumerator.Offset); stopLinksDbEnumerator.MoveTo(stop1); Assert.AreEqual(1, stopLinksDbEnumerator.Count); Assert.IsTrue(stopLinksDbEnumerator.MoveNext()); Assert.AreEqual(0, stopLinksDbEnumerator.EdgeId); Assert.AreEqual(ushort.MaxValue, stopLinksDbEnumerator.Offset); }