/// <summary>
        /// Adds the given node.
        /// </summary>
        /// <param name="node"></param>
        public override void AddNode(Node node)
        {
            if (!_preIndexMode)
            {
                if (_nodesToCache != null &&
                    _nodesToCache.Contains(node.Id.Value))
                { // cache this node?
                    _dataCache.AddNode(node);
                }

                if (_preIndex != null && _preIndex.Contains(node.Id.Value))
                { // only save the coordinates for relevant nodes.
                    // save the node-coordinates.
                    // add the relevant nodes.
                    _coordinates[node.Id.Value] = new GeoCoordinateSimple()
                    {
                        Latitude  = (float)node.Latitude.Value,
                        Longitude = (float)node.Longitude.Value
                    };

                    // add the node as a possible restriction.
                    if (_interpreter.IsRestriction(OsmGeoType.Node, node.Tags))
                    { // tests quickly if a given node is possibly a restriction.
                        var vehicleTypes = _interpreter.CalculateRestrictions(node);
                        if (vehicleTypes != null &&
                            vehicleTypes.Count > 0)
                        { // add all the restrictions.
                            this._relevantNodes.Add(node.Id.Value);

                            var vertexId    = this.AddRoadNode(node.Id.Value).Value; // will always exists, has just been added to coordinates.
                            var restriction = new uint[] { vertexId };
                            if (vehicleTypes.Contains(null))
                            { // restriction is valid for all vehicles.
                                _graph.AddRestriction(restriction);
                            }
                            else
                            { // restriction is restricted to some vehicles only.
                                foreach (string vehicle in vehicleTypes)
                                {
                                    _graph.AddRestriction(vehicle, restriction);
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Adds the given node.
        /// </summary>
        /// <param name="node"></param>
        public override void AddNode(Node node)
        {
            if (!_preIndexMode)
            {
                if (_nodesToCache != null &&
                    _nodesToCache.Contains(node.Id.Value))
                { // cache this node?
                    _dataCache.AddNode(node);
                }

                if (_preIndex != null && _preIndex.Contains(node.Id.Value))
                { // only save the coordinates for relevant nodes.
                  // save the node-coordinates.
                  // add the relevant nodes.

                    if (_box == null || _box.Contains(new GeoCoordinate((float)node.Latitude.Value, (float)node.Longitude.Value)))
                    { // the coordinate is acceptable.
                        _coordinates[node.Id.Value] = new GeoCoordinateSimple()
                        {
                            Latitude  = (float)node.Latitude.Value,
                            Longitude = (float)node.Longitude.Value
                        };
                        if (_coordinates.Count == _preIndex.Count)
                        {
                            _preIndex.Clear();
                            _preIndex = null;
                        }

                        if (_bounds == null)
                        { // create bounds.
                            _bounds = new GeoCoordinateBox(
                                new GeoCoordinate(node.Latitude.Value, node.Longitude.Value),
                                new GeoCoordinate(node.Latitude.Value, node.Longitude.Value));
                        }
                        else
                        { // expand bounds.
                            _bounds.ExpandWith(
                                new GeoCoordinate(node.Latitude.Value, node.Longitude.Value));
                        }

                        // add the node as a possible restriction.
                        if (_interpreter.IsRestriction(OsmGeoType.Node, node.Tags))
                        { // tests quickly if a given node is possibly a restriction.
                            List <Vehicle> vehicles = _interpreter.CalculateRestrictions(node);
                            if (vehicles != null &&
                                vehicles.Count > 0)
                            {                                                               // add all the restrictions.
                                uint   vertexId    = this.AddRoadNode(node.Id.Value).Value; // will always exists, has just been added to coordinates.
                                uint[] restriction = new uint[] { vertexId };
                                if (vehicles.Contains(null))
                                { // restriction is valid for all vehicles.
                                    _dynamicGraph.AddRestriction(restriction);
                                }
                                else
                                { // restriction is restricted to some vehicles only.
                                    foreach (Vehicle vehicle in vehicles)
                                    {
                                        _dynamicGraph.AddRestriction(vehicle, restriction);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }