Пример #1
0
        /// <summary>
        /// Registers the source.
        /// </summary>
        public virtual void RegisterSource(OsmStreamSource source, bool filterNonRoutingTags)
        {
            if (filterNonRoutingTags)
            { // add filtering.
                var eventsFilter = new OsmSharp.Streams.Filters.OsmStreamFilterDelegate();
                eventsFilter.MoveToNextEvent += (osmGeo, param) =>
                {
                    if (osmGeo.Type == OsmGeoType.Way)
                    {
                        // normalize tags, reduce the combination of tags meaning the same thing.
                        var tags           = osmGeo.Tags.ToAttributes();
                        var normalizedTags = new AttributeCollection();
                        if (!DefaultTagNormalizer.Normalize(tags, normalizedTags, _vehicleCache))
                        { // invalid data, no access, or tags make no sense at all.
                            return(osmGeo);
                        }

                        // rewrite tags and keep whitelisted meta-tags.
                        osmGeo.Tags.Clear();
                        foreach (var tag in normalizedTags)
                        {
                            osmGeo.Tags.Add(tag.Key, tag.Value);
                        }
                        foreach (var tag in tags)
                        {
                            if (_vehicleCache.Vehicles.IsOnMetaWhiteList(tag.Key))
                            {
                                osmGeo.Tags.Add(tag.Key, tag.Value);
                            }
                        }
                    }
                    return(osmGeo);
                };
                eventsFilter.RegisterSource(source);

                base.RegisterSource(eventsFilter);
            }
            else
            { // no filtering.
                base.RegisterSource(source);
            }
        }
Пример #2
0
        /// <summary>
        /// Loads a routing network created from OSM data.
        /// </summary>
        public static void LoadOsmData(this RouterDb db, IEnumerable <OsmGeo> source, bool allCore = false, bool processRestrictions = false, bool normalizeTags = true,
                                       ITagNormalizer tagNormalizer = null, IEnumerable <ITwoPassProcessor> processors = null, params Itinero.Osm.Vehicles.Vehicle[] vehicles)
        {
            if (!db.IsEmpty)
            {
                throw new ArgumentException("Can only load a new routing network into an empty router db.");
            }

            if (normalizeTags && tagNormalizer == null)
            {
                tagNormalizer = new DefaultTagNormalizer();
            }

            // load the data.
            var target = new Streams.RouterDbStreamTarget(db,
                                                          vehicles, tagNormalizer, allCore, processRestrictions: processRestrictions, normalizeTags: normalizeTags, processors: processors);

            target.RegisterSource(source);
            target.Pull();

            // sort the network.
            db.Sort();
        }