Example #1
0
        /// <summary>
        /// Executes the actual algorithm.
        /// </summary>
        protected override void DoRun()
        {
            var tiles = new Dictionary <TileIndex, RoutingTile>();

            _polygons = new List <Polygon>();

            _edgeVisitor.Visit += (id, startWeight, endWeight, shape) =>
            {
                this.AddEdgeVisit(tiles, startWeight, endWeight, shape);
            };
            _edgeVisitor.Run();

            var tileList = tiles.Values.ToList();

            tileList = UpdateForWalking(tileList, _level, _walkingSpeed, _limits.Max());
            if (tileList == null)
            {
                return;
            }

            foreach (var isochroneLimit in _limits)
            {
                var tilesWithin = tileList.Where(t => t.Weight < isochroneLimit).ToList();
                if (tilesWithin.Count > 0)
                {
                    var polygonOfTileIndexes = TilesToPolygon.TileSetToPolygon(tilesWithin);
                    _polygons.Add(new Polygon {
                        ExteriorRing = TileHelper.ToWorldCoordinates(polygonOfTileIndexes, _level)
                    });
                }
            }
        }
        /// <summary>
        /// Executes the actual algorithm.
        /// </summary>
        protected override void DoRun()
        {
            var tiles = new Dictionary <TileIndex, RoutingTile>();

            _edgeVisitor.Visit += (id, startVertex, startWeight, endVertex, endWeight, shape) =>
            {
                var         endCoordinate = shape[shape.Count - 1];
                var         index         = TileIndex.WorldToTileIndex(endCoordinate.Latitude, endCoordinate.Longitude, _level);
                RoutingTile tile;
                if (!tiles.TryGetValue(index, out tile))
                {
                    tile = new RoutingTile
                    {
                        Weight = endWeight,
                        Count  = 1,
                        Index  = index
                    };
                }
                else
                {
                    tile.Weight = (tile.Weight * tile.Count + endWeight) / tile.Count + 1;
                    tile.Count++;
                }
                tiles[index] = tile;
            };
            _edgeVisitor.Run();

            _result      = new HeatmapResult();
            _result.Data = new HeatmapSample[tiles.Count];

            var max = 0f;
            var i   = 0;

            foreach (var pair in tiles)
            {
                var location = TileIndex.TileIndexToWorld(pair.Key.X, pair.Key.Y, _level);
                _result.Data[i] = new HeatmapSample()
                {
                    Latitude  = location.Latitude,
                    Longitude = location.Longitude,
                    Value     = pair.Value.Weight
                };

                if (max < pair.Value.Weight)
                {
                    max = pair.Value.Weight;
                }

                i++;
            }
            _result.Max = max;

            this.HasSucceeded = true;
        }
Example #3
0
        /// <summary>
        /// Executes the actual algorithm.
        /// </summary>
        protected override void DoRun()
        {
            var tiles = new Dictionary <TileIndex, RoutingTile>();

            _polygons = new List <Polygon>();

            _edgeVisitor.Visit += (path) =>
            {
                var e         = path.Edge;
                var endWeight = path.Weight;
                if (e == Constants.NO_EDGE ||
                    path.From == null)
                {
                    return(false);
                }
                var startWeight = path.From.Weight;

                // Calculate weight at start vertex.
                uint edgeId;
                if (e > 0)
                {
                    edgeId = (uint)e - 1;
                }
                else
                {
                    edgeId = (uint)((-e) - 1);
                }
                var edge  = _graph.GetEdge(edgeId);
                var shape = _graph.GetShape(edge);

                this.AddEdgeVisit(tiles, startWeight, endWeight, shape);

                return(false);
            };
            _edgeVisitor.Run();

            var tileList = tiles.Values.ToList();

            tileList = UpdateForWalking(tileList, _level, _walkingSpeed, _limits.Max());

            foreach (var isochroneLimit in _limits)
            {
                var tilesWithin          = tileList.Where(t => t.Weight < isochroneLimit).ToList();
                var polygonOfTileIndexes = TilesToPolygon.TileSetToPolygon(tilesWithin);
                _polygons.Add(new Polygon {
                    ExteriorRing = TileHelper.ToWorldCoordinates(polygonOfTileIndexes, _level)
                });
            }
        }
Example #4
0
        /// <summary>
        /// Executes the actual algorithm.
        /// </summary>
        protected override void DoRun()
        {
            _edges              = new HashSet <uint>();
            _treeEdges          = new List <TreeEdge>();
            _edgeVisitor.Visit += (directedEdgeId, startVertex, startWeight, endVertex, endWeight, shape) =>
            {
                uint edgeId;
                if (directedEdgeId > 0)
                {
                    edgeId = (uint)directedEdgeId - 1;
                }
                else
                {
                    edgeId = (uint)((-directedEdgeId) - 1);
                }

                if (!_edges.Contains(edgeId))
                {
                    _treeEdges.Add(new TreeEdge()
                    {
                        Weight1 = startWeight,
                        Vertex1 = startVertex,
                        Weight2 = endWeight,
                        Vertex2 = endVertex,
                        Shape   = shape.ToLonLatArray()
                    });

                    if (_max < endWeight)
                    {
                        _max = endWeight;
                    }
                }
            };
            _edgeVisitor.Run();

            _tree = new Tree()
            {
                Edges = _treeEdges.ToArray(),
                Max   = _max
            };

            this.HasSucceeded = true;
        }
Example #5
0
        /// <summary>
        /// Executes the actual algorithm.
        /// </summary>
        protected override void DoRun(CancellationToken cancellationToken)
        {
            var tiles = new Dictionary <TileIndex, RoutingTile>();

            _edgeVisitor.Visit += (path) =>
            {
                var e         = path.Edge;
                var endWeight = path.Weight;
                if (e == Constants.NO_EDGE)
                {
                    return(false);
                }

                // Calculate weight at start vertex.
                uint edgeId;
                if (e > 0)
                {
                    edgeId = (uint)e - 1;
                }
                else
                {
                    edgeId = (uint)((-e) - 1);
                }
                var edge  = _graph.GetEdge(edgeId);
                var shape = _graph.GetShape(edge);

                var         endCoordinate = shape[shape.Count - 1];
                var         index         = TileIndex.WorldToTileIndex(endCoordinate.Latitude, endCoordinate.Longitude, _level);
                RoutingTile tile;
                if (!tiles.TryGetValue(index, out tile))
                {
                    tile = new RoutingTile
                    {
                        Weight = endWeight,
                        Count  = 1,
                        Index  = index
                    };
                }
                else
                {
                    tile.Weight = (tile.Weight * tile.Count + endWeight) / tile.Count + 1;
                    tile.Count++;
                }
                tiles[index] = tile;

                return(false);
            };
            _edgeVisitor.Run(cancellationToken);

            _result      = new HeatmapResult();
            _result.Data = new HeatmapSample[tiles.Count];

            var max = 0f;
            var i   = 0;

            foreach (var pair in tiles)
            {
                var location = TileIndex.TileIndexToWorld(pair.Key.X, pair.Key.Y, _level);
                _result.Data[i] = new HeatmapSample()
                {
                    Latitude  = location.Latitude,
                    Longitude = location.Longitude,
                    Value     = pair.Value.Weight
                };

                if (max < pair.Value.Weight)
                {
                    max = pair.Value.Weight;
                }

                i++;
            }
            _result.Max = max;

            this.HasSucceeded = true;
        }
Example #6
0
        /// <summary>
        /// Executes the actual algorithm.
        /// </summary>
        protected override void DoRun(CancellationToken cancellationToken)
        {
            _edges     = new HashSet <uint>();
            _treeEdges = new List <TreeEdge>();

            _edgeVisitor.Visit += (path) =>
            {
                var e       = path.Edge;
                var weight2 = path.Weight;
                if (e == Constants.NO_EDGE)
                {
                    return(false);
                }

                var previousEdgeId = Constants.NO_EDGE;
                var weight1        = 0f;
                if (path.From != null)
                {
                    weight1 = path.From.Weight;
                    if (path.From.Edge > 0)
                    {
                        previousEdgeId = (uint)path.From.Edge - 1;
                    }
                    else
                    {
                        previousEdgeId = (uint)((-path.From.Edge) - 1);
                    }
                }

                uint edgeId;
                if (e > 0)
                {
                    edgeId = (uint)e - 1;
                }
                else
                {
                    edgeId = (uint)((-e) - 1);
                }
                var edge  = _graph.GetEdge(edgeId);
                var shape = _graph.GetShape(edge);
                if (e < 0)
                {
                    shape.Reverse();
                }

                var shapeArray = new float[shape.Count][];
                for (var i = 0; i < shapeArray.Length; i++)
                {
                    shapeArray[i]    = new float[2];
                    shapeArray[i][1] = shape[i].Latitude;
                    shapeArray[i][0] = shape[i].Longitude;
                }

                var treeEdge = new TreeEdge()
                {
                    EdgeId         = edgeId,
                    PreviousEdgeId = previousEdgeId,
                    Shape          = shapeArray,
                    Weight1        = weight1,
                    Weight2        = weight2
                };
                _treeEdges.Add(treeEdge);

                if (_max < weight2)
                {
                    _max = weight2;
                }

                return(false);
            };
            _edgeVisitor.Run(cancellationToken);

            _tree = new Tree()
            {
                Edges = _treeEdges.ToArray(),
                Max   = _max
            };

            this.HasSucceeded = true;
        }