Beispiel #1
0
        /// <summary>
        /// Creates a new processor target.
        /// </summary>
        /// <param name="dynamicGraph">The graph that will be filled.</param>
        /// <param name="interpreter">The interpreter to generate the edge data.</param>
        /// <param name="edgeComparer"></param>
        /// <param name="tagsIndex"></param>
        /// <param name="idTransformations"></param>
        /// <param name="box"></param>
        protected DynamicGraphOsmStreamWriter(
            IDynamicGraphRouterDataSource <TEdgeData> dynamicGraph, IOsmRoutingInterpreter interpreter, IDynamicGraphEdgeComparer <TEdgeData> edgeComparer,
            ITagsCollectionIndex tagsIndex, IDictionary <long, uint> idTransformations,
            GeoCoordinateBox box)
        {
            _dynamicGraph = dynamicGraph;
            _interpreter  = interpreter;
            _edgeComparer = edgeComparer;
            _box          = box;

            _tagsIndex         = tagsIndex;
            _idTransformations = idTransformations;
            _preIndexMode      = true;
            _preIndex          = new OsmSharp.Collections.HugeHashSet <long>();
            _usedTwiceOrMore   = new OsmSharp.Collections.HugeHashSet <long>();

            _dataCache = new OsmDataCacheMemory();
        }
Beispiel #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);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }