Exemple #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();
        }
Exemple #2
0
        /// <summary>
        /// Loads a routing network created from OSM data.
        /// </summary>
        public static void LoadOsmData(this RouterDb db, Stream data, 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.");
            }

            // load the data.
            var source   = new PBFOsmStreamSource(data);
            var progress = new OsmSharp.Streams.Filters.OsmStreamFilterProgress();

            progress.RegisterSource(source);
            db.LoadOsmData(new OsmStreamSource[] { progress }, settings, vehicles);
        }
Exemple #3
0
 /// <summary>
 /// Loads a routing network created from OSM data.
 /// </summary>
 public static void LoadOsmData(this RouterDb db, OsmStreamSource source, LoadSettings settings, params Itinero.Profiles.Vehicle[] vehicles)
 {
     db.LoadOsmData(new OsmStreamSource[] { source }, settings, vehicles);
 }
Exemple #4
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();
        }