Beispiel #1
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();
        }
        /// <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, params Itinero.Osm.Vehicles.Vehicle[] vehicles)
        {
            if (!db.IsEmpty)
            {
                throw new ArgumentException("Can only load a new routing network into an empty router db.");
            }

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

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

            // sort the network.
            db.Sort();
        }
        /// <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();
        }
Beispiel #4
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();
        }
Beispiel #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();
        }