Beispiel #1
0
        /// <summary>
        /// Calculates heatmap for the given profile.
        /// </summary>
        public static HeatmapResult CalculateHeatmap(this RouterBase router, Profile profile, RouterPoint origin, int limitInSeconds, int zoom, CancellationToken cancellationToken)
        {
            if (!router.SupportsAll(profile))
            {
                throw new ArgumentException(string.Format("Profile {0} not supported.",
                                                          profile.FullName));
            }

            if (profile.Metric != ProfileMetric.TimeInSeconds)
            {
                throw new ArgumentException(string.Format("Profile {0} not supported, only profiles with metric TimeInSeconds are supported.",
                                                          profile.FullName));
            }

            // get the weight handler.
            var weightHandler = router.GetDefaultWeightHandler(profile);
            var getFactor     = router.GetDefaultGetFactor(profile);

            // calculate isochrones.
            var isochrone = new TileBasedHeatmapBuilder(router.Db.Network.GeometricGraph,
                                                        new Algorithms.Default.Dykstra(router.Db.Network.GeometricGraph.Graph,
                                                                                       weightHandler, null, origin.ToEdgePaths <float>(router.Db, weightHandler, true), limitInSeconds, false), zoom);

            isochrone.Run(cancellationToken);

            var result = isochrone.Result;

            result.MaxMetric = profile.Metric.ToInvariantString();
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Tries to calculate a tree starting at the given location.
        /// </summary>
        public static Result <Tree> TryCalculateTree(this RouterBase router, Profile profile, RouterPoint origin, float max)
        {
            if (!router.SupportsAll(profile))
            {
                return(new Result <Tree>(string.Format("Profile {0} not supported.",
                                                       profile.Name)));
            }

            if (profile.Metric != ProfileMetric.TimeInSeconds)
            {
                return(new Result <Tree>(string.Format("Profile {0} not supported, only profiles with metric TimeInSeconds are supported.",
                                                       profile.Name)));
            }

            // get the weight handler.
            var weightHandler = router.GetDefaultWeightHandler(profile);
            var getFactor     = router.GetDefaultGetFactor(profile);

            // calculate isochrones.
            var treeBuilder = new TreeBuilder(
                new DykstraEdgeVisitor(router.Db.Network.GeometricGraph,
                                       getFactor, origin.ToEdgePaths <float>(router.Db, weightHandler, true), max));

            treeBuilder.Run();

            return(new Result <Tree>(treeBuilder.Tree));
        }
Beispiel #3
0
        /// <summary>
        /// Calculates heatmap for the given profile.
        /// </summary>
        public static HeatmapResult CalculateHeatmap(this RouterBase router, Profile profile, Coordinate origin, int limitInSeconds, int zoom, CancellationToken cancellationToken)
        {
            if (!router.SupportsAll(profile))
            {
                throw new ArgumentException(string.Format("Profile {0} not supported.",
                                                          profile.FullName));
            }

            var routerOrigin = router.Resolve(profile, origin);

            return(router.CalculateHeatmap(profile, routerOrigin, limitInSeconds, zoom, cancellationToken));
        }
Beispiel #4
0
        /// <summary>
        /// Tries to calculate a tree starting at the given location.
        /// </summary>
        public static Result <Tree> TryCalculateTree(this RouterBase router, Profile profile, RouterPoint origin, float max)
        {
            if (!router.SupportsAll(profile))
            {
                return(new Result <Tree>(string.Format("Profile {0} not supported.",
                                                       profile.FullName)));
            }

            if (profile.Metric != ProfileMetric.TimeInSeconds)
            {
                return(new Result <Tree>(string.Format("Profile {0} not supported, only profiles with metric TimeInSeconds are supported.",
                                                       profile.FullName)));
            }

            // get the weight handler.
            var weightHandler = router.GetDefaultWeightHandler(profile);
            var getFactor     = router.GetDefaultGetFactor(profile);

            // calculate isochrones.
            TreeBuilder treeBuilder = null;

            if (!router.Db.HasComplexRestrictions(profile))
            {
                treeBuilder = new TreeBuilder(router.Db.Network.GeometricGraph,
                                              new Algorithms.Default.Dykstra(router.Db.Network.GeometricGraph.Graph,
                                                                             weightHandler, null, origin.ToEdgePaths <float>(router.Db, weightHandler, true), max, router.Closures, false));
            }
            else
            {
                treeBuilder = new TreeBuilder(router.Db.Network.GeometricGraph,
                                              new Algorithms.Default.EdgeBased.Dykstra(router.Db.Network.GeometricGraph.Graph,
                                                                                       weightHandler, router.Db.GetGetRestrictions(profile, true), origin.ToEdgePaths <float>(router.Db, weightHandler, true), max, router.Closures, false));
            }
            treeBuilder.Run();

            return(new Result <Tree>(treeBuilder.Tree));
        }