Пример #1
0
        private Engine()
        {
            if (string.IsNullOrWhiteSpace(PbfDataFilePath))
            {
                throw new NullReferenceException("PbfDataFilePath must be set.");
            }

            if (!File.Exists(PbfDataFilePath))
            {
                throw new NullReferenceException("PbfDataFilePath '" + PbfDataFilePath + "' does not exist.");
            }

            // keeps a memory-efficient version of the osm-tags.
            var tagsIndex = new OsmTagsIndex();

            // creates a routing interpreter. (used to translate osm-tags into a routable network)
            var interpreter = new OsmRoutingInterpreter();

            // create a routing datasource, keeps all processed osm routing data.
            var osmData = new MemoryRouterDataSource<SimpleWeighedEdge>(tagsIndex);

            // load data into this routing datasource.
            Stream osmPbfData = new FileInfo(PbfDataFilePath).OpenRead(); // for example moscow!
            using (osmPbfData)
            {
                var targetData = new
                   SimpleWeighedDataGraphProcessingTarget(
                                osmData, interpreter, osmData.TagsIndex, VehicleEnum.Car);

                // replace this with PBFdataProcessSource when having downloaded a PBF file.
                var dataProcessorSource = new
                  PBFDataProcessorSource(osmPbfData);

                // pre-process the data.
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                var sorter = new DataProcessorFilterSort();
                sorter.RegisterSource(dataProcessorSource);
                targetData.RegisterSource(sorter);
                targetData.Pull();

                stopwatch.Stop();
            }

            // create the router object: there all routing functions are available.
            router = new Router<SimpleWeighedEdge>(
                osmData, interpreter, new DykstraRoutingLive(osmData.TagsIndex));
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Engine"/> class.
        /// </summary>
        protected Engine()
        {
            // keeps a memory-efficient version of the osm-tags.
            var tagsIndex = new OsmTagsIndex();

            // creates a routing interpreter. (used to translate osm-tags into a routable network)
            interpreter = new OsmRoutingInterpreter();

            // create a routing datasource, keeps all processed osm routing data.
            var osmData = new MemoryRouterDataSource <SimpleWeighedEdge>(tagsIndex);

            // load data into this routing datasource.
            var    fileSource = HostingEnvironment.MapPath("~/App_Data/Manchester.osm.pbf");
            Stream osmXmlData = new FileInfo(fileSource).OpenRead(); // for example moscow!

            using (osmXmlData)
            {
                var targetData = new SimpleWeighedDataGraphProcessingTarget(
                    osmData,
                    interpreter,
                    osmData.TagsIndex,
                    VehicleEnum.Car);

                // replace this with PBFdataProcessSource when having downloaded a PBF file.
                var dataProcessorSource = new
                                          OsmSharp.Osm.Data.PBF.Raw.Processor.PBFDataProcessorSource(osmXmlData);

                // pre-process the data.
                var sorter = new DataProcessorFilterSort();
                sorter.RegisterSource(dataProcessorSource);
                targetData.RegisterSource(sorter);
                targetData.Pull();
            }

            // create the router object: there all routing functions are available.
            router = new Router <SimpleWeighedEdge>(
                osmData,
                interpreter,
                new DykstraRoutingLive(osmData.TagsIndex));
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Engine"/> class.
        /// </summary>
        protected Engine()
        {
            // keeps a memory-efficient version of the osm-tags.
            var tagsIndex = new OsmTagsIndex();

            // creates a routing interpreter. (used to translate osm-tags into a routable network)
            interpreter = new OsmRoutingInterpreter();

            // create a routing datasource, keeps all processed osm routing data.
            var osmData = new MemoryRouterDataSource<SimpleWeighedEdge>(tagsIndex);

            // load data into this routing datasource.
            var fileSource = HostingEnvironment.MapPath("~/App_Data/Manchester.osm.pbf");
            Stream osmXmlData = new FileInfo(fileSource).OpenRead(); // for example moscow!
            using (osmXmlData)
            {
                var targetData = new SimpleWeighedDataGraphProcessingTarget(
                                osmData,
                                interpreter,
                                osmData.TagsIndex,
                                VehicleEnum.Car);

                // replace this with PBFdataProcessSource when having downloaded a PBF file.
                var dataProcessorSource = new
                  OsmSharp.Osm.Data.PBF.Raw.Processor.PBFDataProcessorSource(osmXmlData);

                // pre-process the data.
                var sorter = new DataProcessorFilterSort();
                sorter.RegisterSource(dataProcessorSource);
                targetData.RegisterSource(sorter);
                targetData.Pull();
            }

            // create the router object: there all routing functions are available.
            router = new Router<SimpleWeighedEdge>(
                osmData,
                interpreter,
                new DykstraRoutingLive(osmData.TagsIndex));
        }
        /// <summary>
        /// Calculates a route to test on.
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        private OsmSharpRoute Calculate(GeoCoordinate from, GeoCoordinate to)
        {
            if (_router == null)
            {
                var interpreter = new OsmRoutingInterpreter();
                var tagsIndex = new OsmTagsIndex();

                // do the data processing.
                var memoryData =
                    new DynamicGraphRouterDataSource<SimpleWeighedEdge>(tagsIndex);
                var targetData = new SimpleWeighedDataGraphProcessingTarget(
                    memoryData, interpreter, memoryData.TagsIndex, VehicleEnum.Car);
                var dataProcessorSource = new XmlDataProcessorSource(
                    Assembly.GetExecutingAssembly().GetManifestResourceStream(
                        "OsmSharp.UnitTests.test_instructions.osm"));
                var sorter = new DataProcessorFilterSort();
                sorter.RegisterSource(dataProcessorSource);
                targetData.RegisterSource(sorter);
                targetData.Pull();

                _router = new Router<SimpleWeighedEdge>(
                    memoryData, interpreter, new DykstraRoutingLive(memoryData.TagsIndex));
            }

            RouterPoint fromPoint = _router.Resolve(VehicleEnum.Car, from);
            RouterPoint toPoint = _router.Resolve(VehicleEnum.Car, to);
            return _router.Calculate(VehicleEnum.Car, fromPoint, toPoint);
        }
        /// <summary>
        /// Prepares the router.
        /// </summary>
        private void PrepareRouter()
        {
            #if DEBUG
            OsmSharp.Tools.Output.OutputStreamHost.RegisterOutputStream(
                new OsmSharp.Tools.Output.DebugOutputStream());
            #endif
            // initialize the interpreters.
            _interpreter =
                new  OsmRoutingInterpreter();

            string file = OperationProcessor.Settings["pbf_file"];

            var tagsIndex = new OsmTagsIndex(new ObjectTable<OsmTagsIndex.OsmTags>(true));

            // do the data processing.
            var data = new DynamicGraphRouterDataSource<SimpleWeighedEdge>(tagsIndex);
            var targetData = new SimpleWeighedDataGraphProcessingTarget(
                data, _interpreter, data.TagsIndex, VehicleEnum.Car);
            var dataProcessorSource = new PBFDataProcessorSource((new FileInfo(
                file)).OpenRead());
            var progressSource = new ProgressDataProcessorSource(dataProcessorSource);
            targetData.RegisterSource(progressSource);
            targetData.Pull();

            _data = data; // only set the data property here now after pre-processing!
        }