/// <summary>
        /// Move to the next object.
        /// </summary>
        public override bool MoveNext(bool ignoreNodes, bool ignoreWays, bool ignoreRelations)
        {
            if (_mergedSource == null)
            {
                var mergedSource = new OsmStreamFilterMerge();
                mergedSource.RegisterSource(this.Source);
                mergedSource.RegisterSource(_creations);
                _mergedSource = mergedSource;
            }

            OsmGeo modified;

            while (_mergedSource.MoveNext(ignoreNodes, ignoreWays, ignoreRelations))
            {
                // returns the next out of the merged source of the creations and the source.
                _current = _mergedSource.Current();

                // check for deletions or modifications.
                var key = new OsmGeoKey(_current);
                if (_deletions.Contains(key))
                {
                    // move next.
                    _current = null;
                    continue;
                }
                else if (_modifications.TryGetValue(key, out modified))
                {
                    _current = modified;
                }
                return(true);
            }
            return(false);
        }
Пример #2
0
        /// <summary>
        /// Loads a routing network created from OSM data.
        /// </summary>
        public static void LoadOsmData(this RouterDb db, OsmStreamSource[] sources, LoadSettings settings, params Itinero.Profiles.Vehicle[] vehicles)
        {
            if (!db.IsEmpty)
            {
                throw new ArgumentException("Can only load a new routing network into an empty router db, add multiple streams at once to load multiple files.");
            }
            if (vehicles == null || vehicles.Length == 0)
            {
                throw new ArgumentNullException("vehicles", "A least one vehicle is needed to load OSM data.");
            }
            if (sources == null || sources.Length == 0)
            {
                throw new ArgumentNullException("sources", "A least one source is needed to load OSM data.");
            }

            if (settings == null)
            {
                settings = new LoadSettings();
            }

            // merge sources if needed.
            var source = sources[0];

            for (var i = 1; i < sources.Length; i++)
            {
                var merger = new OsmSharp.Streams.Filters.OsmStreamFilterMerge();
                merger.RegisterSource(source);
                merger.RegisterSource(sources[i]);
                source = merger;
            }

            if (sources.Length > 1 && !(source is OsmStreamFilterProgress))
            { // just one source the the callee is choosing a progress filter but assumed the default for a merged stream.
                var progress = new OsmStreamFilterProgress();
                progress.RegisterSource(source);
                source = progress;
            }

            // load the data.
            var target = new Streams.RouterDbStreamTarget(db,
                                                          vehicles, settings.AllCore, processRestrictions: settings.ProcessRestrictions, processors: settings.Processors,
                                                          simplifyEpsilonInMeter: settings.NetworkSimplificationEpsilon);

            target.KeepNodeIds = settings.KeepNodeIds;
            target.RegisterSource(source);
            target.Pull();

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

            // optimize the network if requested.
            if (settings.NetworkSimplificationEpsilon != 0)
            {
                db.OptimizeNetwork(settings.NetworkSimplificationEpsilon);
            }

            // compress the network.
            db.Network.Compress();
        }
Пример #3
0
        /// <summary>
        /// Loads a routing network created from OSM data.
        /// </summary>
        public static void LoadOsmData(this RouterDb db, OsmStreamSource[] sources, bool allCore = false, bool processRestrictions = true,
                                       IEnumerable <ITwoPassProcessor> processors = null, params Itinero.Profiles.Vehicle[] vehicles)
        {
            if (!db.IsEmpty)
            {
                throw new ArgumentException("Can only load a new routing network into an empty router db, add multiple streams at once to load multiple files.");
            }
            if (vehicles == null || vehicles.Length == 0)
            {
                throw new ArgumentNullException("vehicles", "A least one vehicle is needed to load OSM data.");
            }
            if (sources == null || sources.Length == 0)
            {
                throw new ArgumentNullException("sources", "A least one source is needed to load OSM data.");
            }

            // merge sources if needed.
            var source = sources[0];

            for (var i = 1; i < sources.Length; i++)
            {
                var merger = new OsmSharp.Streams.Filters.OsmStreamFilterMerge();
                merger.RegisterSource(source);
                merger.RegisterSource(sources[i]);
                source = merger;
            }

            if (sources.Length > 1 && !(source is OsmStreamFilterProgress))
            { // just one source the the callee is choosing a progress filter but assumed the default for a merged stream.
                var progress = new OsmStreamFilterProgress();
                progress.RegisterSource(source);
                source = progress;
            }

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

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

            // sort the network.
            db.Sort();
        }
Пример #4
0
        static void AddFromSourceOsmData(string osmFile, string osmTransitFile)
        {
            // load transit data formatted as osm data.
            using var transitSource = File.OpenRead(osmTransitFile);
            var osmTransitSource = new OsmSharp.Streams.BinaryOsmStreamSource(transitSource);

            using var source = File.OpenRead(osmFile);
            var osmSource = new OsmSharp.Streams.PBFOsmStreamSource(source);

            var merged = new OsmSharp.Streams.Filters.OsmStreamFilterMerge();

            merged.RegisterSource(osmSource);
            merged.RegisterSource(osmTransitSource);

            // run through transit handler filter.
            var transitFilter = new TransitDataHandlerOsmStream((osmGeo) =>
            {
                if (osmGeo.Tags != null && osmGeo.Tags.Contains("source", "ANYWAYS:transitdb"))
                {
                    return(true);
                }

                return(false);
            });

            transitFilter.RegisterSource(merged);

            // build routerdb.
            var routerDb = new RouterDb();

            routerDb.LoadOsmData(transitFilter, Vehicle.Bicycle);

            // after routerdb is finished, use filtered data to properly add transit data.
            routerDb.AddPublicTransport(transitFilter, new IProfileInstance[] { Vehicle.Bicycle.Fastest() });

            // write the result.
            routerDb.WriteToShape("output.shp");
        }
Пример #5
0
        /// <summary>
        /// Loads a routing network created from OSM data.
        /// </summary>
        public static void LoadOsmData(this RouterDb db, OsmStreamSource[] sources, LoadSettings settings, params Itinero.Profiles.Vehicle[] vehicles)
        {
            if (!db.IsEmpty)
            {
                throw new ArgumentException("Can only load a new routing network into an empty router db, add multiple streams at once to load multiple files.");
            }
            if (vehicles == null || vehicles.Length == 0)
            {
                throw new ArgumentNullException("vehicles", "A least one vehicle is needed to load OSM data.");
            }
            if (sources == null || sources.Length == 0)
            {
                throw new ArgumentNullException("sources", "A least one source is needed to load OSM data.");
            }

            if (settings == null)
            {
                settings = new LoadSettings();
            }

            // merge sources if needed.
            var source = sources[0];

            for (var i = 1; i < sources.Length; i++)
            {
                var merger = new OsmSharp.Streams.Filters.OsmStreamFilterMerge();
                merger.RegisterSource(source);
                merger.RegisterSource(sources[i]);
                source = merger;
            }

            if (sources.Length > 1 && !(source is OsmStreamFilterProgress))
            { // just one source the the callee is choosing a progress filter but assumed the default for a merged stream.
                var progress = new OsmStreamFilterProgress();
                progress.RegisterSource(source);
                source = progress;
            }

            // make sure the routerdb can handle multiple edges.
            db.Network.GeometricGraph.Graph.MarkAsMulti();

            // determine normalization flag.
            var normalize = true;

            foreach (var vehicle in vehicles)
            {
                if (vehicle.Normalize)
                {
                    continue;
                }
                normalize = false;
                break;
            }

            // load the data.
            var target = new Streams.RouterDbStreamTarget(db,
                                                          vehicles, settings.AllCore, processRestrictions: settings.ProcessRestrictions, processors: settings.Processors,
                                                          simplifyEpsilonInMeter: settings.NetworkSimplificationEpsilon);

            target.KeepNodeIds = settings.KeepNodeIds;
            target.KeepWayIds  = settings.KeepWayIds;
            target.RegisterSource(source, normalize);
            target.Pull();

            // optimize the network.
            db.RemoveDuplicateEdges();
            db.SplitLongEdges();
            db.ConvertToSimple();

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

            // optimize the network if requested.
            if (settings.NetworkSimplificationEpsilon > 0)
            {
                db.OptimizeNetwork(settings.NetworkSimplificationEpsilon);
            }

            // compress the network.
            db.Compress();
        }