/// <summary> /// Registers the source for this target. /// </summary> /// <param name="source">The source.</param> /// <param name="filterTags">The filter tags flag.</param> public virtual void RegisterSource(OsmStreamSource source, bool filterTags) { if (filterTags) { // add filter to remove all irrelevant tags. var tagsFilter = new OsmStreamFilterTagsFilter((TagsCollectionBase tags) => { var tagsToRemove = new List <Tag>(); foreach (var tag in tags) { if (!_interpreter.IsRelevant(tag.Key, tag.Value) && !Vehicle.IsRelevantForOneOrMore(tag.Key, tag.Value)) { // not relevant for both interpreter and all registered vehicle profiles. tagsToRemove.Add(tag); } } foreach (Tag tag in tagsToRemove) { tags.RemoveKeyValue(tag.Key, tag.Value); } }); tagsFilter.RegisterSource(source); base.RegisterSource(tagsFilter); } else { // no filter! base.RegisterSource(source); } }
/// <summary> /// Registers the source for this target. /// </summary> /// <param name="source"></param> public override void RegisterSource(OsmStreamSource source) { // add filter to remove all irrelevant tags. OsmStreamFilterTagsFilter tagsFilter = new OsmStreamFilterTagsFilter((TagsCollectionBase tags) => { List <Tag> tagsToRemove = new List <Tag>(); foreach (Tag tag in tags) { if (!_interpreter.IsRelevant(tag.Key, tag.Value)) { tagsToRemove.Add(tag); } } foreach (Tag tag in tagsToRemove) { tags.RemoveKeyValue(tag.Key, tag.Value); } }); tagsFilter.RegisterSource(source); base.RegisterSource(tagsFilter); }
/// <summary> /// Adds a given way. /// </summary> /// <param name="way"></param> public override void AddWay(Way way) { if (!_preIndexMode && _waysToCache != null && _waysToCache.Contains(way.Id.Value)) { // cache this way? _dataCache.AddWay(way); } // initialize the way interpreter. if (_interpreter.EdgeInterpreter.IsRoutable(way.Tags)) { // the way is a road. if (_preIndexMode) { // index only relevant nodes. if (way.Nodes != null) { foreach (long node in way.Nodes) { if (_preIndex.Contains(node)) { _usedTwiceOrMore.Add(node); } else { _preIndex.Add(node); // node is relevant. } } } } else { // add the forward edges. //if (!interpreter.IsOneWayReverse()) if (true) // add backward edges too! { // loop over all edges. if (way.Nodes != null && way.Nodes.Count > 1) { // way has at least two nodes. // keep the relevant tags. TagsCollection relevantTags = new SimpleTagsCollection(); foreach (var relevantTag in way.Tags) { if (_interpreter.IsRelevant(relevantTag.Key)) { relevantTags.Add(relevantTag); } } if (this.CalculateIsTraversable(_interpreter.EdgeInterpreter, _tagsIndex, relevantTags)) { // the edge is traversable, add the edges. uint?from = this.AddRoadNode(way.Nodes[0]); for (int idx = 1; idx < way.Nodes.Count; idx++) { // the to-node. uint?to = this.AddRoadNode(way.Nodes[idx]); // add the edge(s). if (from.HasValue && to.HasValue) { // add a road edge. if (!this.AddRoadEdge(relevantTags, true, from.Value, to.Value)) { // add the reverse too if it has been indicated that this was needed. this.AddRoadEdge(relevantTags, false, to.Value, from.Value); } } from = to; // the to node becomes the from. } } } } } } }