Example #1
0
        /// <summary>
        /// Resolves multiple routerpoints.
        /// </summary>
        public static List <RouterPoint> ResolveMultiple(this Router router, Profile[] profiles, float latitude, float longitude, float maxOffsetDistance)
        {
            var algorithm = new ResolveMultipleAlgorithm(router.Db.Network.GeometricGraph, latitude, longitude, 0.01f, maxOffsetDistance,
                                                         router.GetIsAcceptable(profiles));

            algorithm.Run();
            if (!algorithm.HasSucceeded)
            {
                return(new List <RouterPoint>());
            }
            return(algorithm.Results);
        }
Example #2
0
        /// <summary>
        /// Adds a new stop links db for the given profile.
        /// </summary>
        public static void AddStopLinksDb(this MultimodalDb db, Profile profile, float searchOffset = DefaultSearchOffset,
                                          float maxDistance = DefaultMaxDistance, int maxRouterPoints = DefaultMaxRouterPoints)
        {
            var stopsDbEnumerator = db.TransitDb.GetStopsEnumerator();
            var linksDb           = new StopLinksDb(stopsDbEnumerator.Count, db.RouterDb, profile);

            while (stopsDbEnumerator.MoveNext())
            {
                var stopId        = stopsDbEnumerator.Id;
                var multiResolver = new ResolveMultipleAlgorithm(db.RouterDb.Network.GeometricGraph,
                                                                 stopsDbEnumerator.Latitude, stopsDbEnumerator.Longitude, searchOffset, maxDistance, (edge) =>
                {
                    // get profile.
                    float distance;
                    ushort edgeProfileId;
                    Itinero.Data.Edges.EdgeDataSerializer.Deserialize(edge.Data[0],
                                                                      out distance, out edgeProfileId);
                    var edgeProfile = db.RouterDb.EdgeProfiles.Get(edgeProfileId);
                    // get factor from profile.
                    if (profile.Factor(edgeProfile).Value <= 0)
                    {     // cannot be traversed by this profile.
                        return(false);
                    }
                    // verify stoppable.
                    if (!profile.CanStopOn(edgeProfile))
                    {     // this profile cannot stop on this edge.
                        return(false);
                    }
                    return(true);
                });
                multiResolver.Run();
                if (multiResolver.HasSucceeded)
                {
                    // get the n-closest.
                    var closest = multiResolver.Results.GetLowestN(maxRouterPoints,
                                                                   (p) => Coordinate.DistanceEstimateInMeter(stopsDbEnumerator.Latitude, stopsDbEnumerator.Longitude,
                                                                                                             p.Latitude, p.Longitude));

                    // add them as new links.
                    for (var i = 0; i < closest.Count; i++)
                    {
                        linksDb.Add((uint)stopId, closest[i]);
                    }
                }
            }

            db.AddStopLinksDb(linksDb);
        }