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 isochrones for the given profile based on the given limits.
        /// </summary>
        public static List <LocalGeo.Polygon> CalculateIsochrones(this RouterBase router, Profile profile, RouterPoint origin, List <float> limits, int zoom = 16)
        {
            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 TileBasedIsochroneBuilder(router.Db.Network.GeometricGraph,
                                                          new Algorithms.Default.Dykstra(router.Db.Network.GeometricGraph.Graph,
                                                                                         weightHandler, null, origin.ToEdgePaths <float>(router.Db, weightHandler, true), limits.Max() * 1.1f, false),
                                                          limits, zoom);

            isochrone.Run();

            return(isochrone.Polygons);
        }
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));
        }
Beispiel #5
0
        /// <summary>
        /// Calculates heatmap for the given profile.
        /// </summary>
        public static HeatmapResult CalculateHeatmap(this RouterBase router, Profile profile, RouterPoint origin, int limitInSeconds, int zoom = 16)
        {
            if (profile.Metric != ProfileMetric.TimeInSeconds)
            {
                throw new ArgumentException(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 isochrone = new TileBasedHeatmapBuilder(
                new DykstraEdgeVisitor(router.Db.Network.GeometricGraph,
                                       getFactor, origin.ToEdgePaths <float>(router.Db, weightHandler, true), limitInSeconds), zoom);

            isochrone.Run();

            var result = isochrone.Result;

            result.MaxMetric = profile.Name;
            return(result);
        }
Beispiel #6
0
 /// <summary>
 /// Returns the default weight handler.
 /// </summary>
 public static DefaultWeightHandler DefaultWeightHandler(this IProfileInstance profile, RouterBase router)
 {
     return(router.GetDefaultWeightHandler(profile));
 }