/// <summary>
        /// Builds the data.
        /// </summary>
        /// <param name="interpreter"></param>
        /// <param name="embeddedString"></param>
        /// <returns></returns>
        public override IBasicRouterDataSource <CHEdgeData> BuildData(IOsmRoutingInterpreter interpreter,
                                                                      string embeddedString)
        {
            string key = string.Format("CHEdgeDifference.Routing.IBasicRouterDataSource<CHEdgeData>.OSM.{0}",
                                       embeddedString);
            var data = StaticDictionary.Get <IBasicRouterDataSource <CHEdgeData> >(
                key);

            if (data == null)
            {
                var tagsIndex = new TagsTableCollectionIndex();

                // do the data processing.
                var memoryData = new DynamicGraphRouterDataSource <CHEdgeData>(tagsIndex);
                var targetData = new CHEdgeGraphOsmStreamTarget(
                    memoryData, interpreter, tagsIndex, Vehicle.Car);
                var dataProcessorSource = new XmlOsmStreamSource(
                    Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedString));
                var sorter = new OsmStreamFilterSort();
                sorter.RegisterSource(dataProcessorSource);
                targetData.RegisterSource(sorter);
                targetData.Pull();

                // do the pre-processing part.
                var witnessCalculator = new DykstraWitnessCalculator();
                var preProcessor      = new CHPreProcessor(memoryData,
                                                           new EdgeDifference(memoryData, witnessCalculator), witnessCalculator);
                preProcessor.Start();

                data = memoryData;
                StaticDictionary.Add <IBasicRouterDataSource <CHEdgeData> >(key, data);
            }
            return(data);
        }
        /// <summary>
        /// Executes the CH contractions while verifying each step.
        /// </summary>
        /// <param name="stream"></param>
        public void DoTestCHEdgeDifferenceVerifiedContraction(Stream stream)
        {
            _interpreter = new OsmRoutingInterpreter();

            var tagsIndex = new TagsIndex();

            // do the data processing.
            _data = new RouterDataSource <CHEdgeData>(new DirectedGraph <CHEdgeData>(), tagsIndex);
            var targetData = new CHEdgeGraphOsmStreamTarget(
                _data, _interpreter, tagsIndex, Vehicle.Car);
            var dataProcessorSource = new XmlOsmStreamSource(stream);
            var sorter = new OsmStreamFilterSort();

            sorter.RegisterSource(dataProcessorSource);
            targetData.RegisterSource(sorter);
            targetData.Pull();

            // do the pre-processing part.
            var witnessCalculator = new DykstraWitnessCalculator();
            var preProcessor      = new CHPreprocessor(_data,
                                                       new EdgeDifferenceContractedSearchSpace(_data, witnessCalculator), witnessCalculator);

            preProcessor.OnBeforeContractionEvent +=
                new CHPreprocessor.VertexDelegate(pre_processor_OnBeforeContractionEvent);
            preProcessor.OnAfterContractionEvent +=
                new CHPreprocessor.VertexDelegate(pre_processor_OnAfterContractionEvent);
            preProcessor.Start();
        }
Example #3
0
        public void TestReadWay()
        {
            // build the source.
            var source = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(
                    "OsmSharp.Test.data.xml.way.osm"));

            // read.
            var result = new List <OsmGeo>(source);

            // check results.
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count);
            Assert.IsInstanceOf <Way>(result[0]);
            var way = result[0] as Way;

            Assert.AreEqual(88310427, way.Id);
            Assert.AreEqual("Ben Abelshausen", way.UserName);
            Assert.AreEqual(137772, way.UserId);
            Assert.AreEqual(true, way.Visible);
            Assert.AreEqual(1, way.Version);
            Assert.AreEqual(6570367, way.ChangeSetId);
            Assert.AreEqual(new DateTime(2010, 12, 06, 23, 58, 37), way.TimeStamp.Value.ToUniversalTime());
            Assert.IsNotNull(way.Tags);
            Assert.AreEqual(1, way.Tags.Count);
            Assert.IsTrue(way.Tags.Contains("building", "yes"));
            Assert.IsNotNull(way.Nodes);
            Assert.AreEqual(5, way.Nodes.Length);
            Assert.AreEqual(1025709357, way.Nodes[0]);
            Assert.AreEqual(1025709360, way.Nodes[1]);
            Assert.AreEqual(1025709358, way.Nodes[2]);
            Assert.AreEqual(1025709344, way.Nodes[3]);
            Assert.AreEqual(1025709357, way.Nodes[4]);
        }
        /// <summary>
        /// Creates a router.
        /// </summary>
        /// <param name="interpreter"></param>
        /// <param name="manifestResourceName"></param>
        /// <returns></returns>
        protected override Router CreateRouter(IOsmRoutingInterpreter interpreter, string manifestResourceName)
        {
            var tagsIndex = new TagsTableCollectionIndex();

            // do the data processing.
            var source = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(manifestResourceName));
            var data = CHEdgeGraphOsmStreamTarget.Preprocess(
                source, new OsmRoutingInterpreter(), Vehicle.Car);

            // serialize.
            var memoryStream            = new MemoryStream();
            TagsCollectionBase metaData = new TagsCollection();

            metaData.Add("some_key", "some_value");
            var routingSerializer = new CHEdgeDataDataSourceSerializer();

            routingSerializer.Serialize(memoryStream, data, metaData);

            memoryStream.Seek(0, SeekOrigin.Begin);

            var deserialized = routingSerializer.Deserialize(memoryStream);

            return(Router.CreateCHFrom(deserialized, new CHRouter(), new OsmRoutingInterpreter()));
        }
Example #5
0
        /// <summary>
        /// Builds the data.
        /// </summary>
        /// <param name="interpreter"></param>
        /// <param name="embeddedString"></param>
        /// <returns></returns>
        public override IBasicRouterDataSource <CHEdgeData> BuildData(IOsmRoutingInterpreter interpreter,
                                                                      string embeddedString)
        {
            var tagsIndex = new TagsTableCollectionIndex();

            // do the data processing.
            var memoryData = new DynamicGraphRouterDataSource <CHEdgeData>(tagsIndex);
            var targetData = new CHEdgeGraphOsmStreamTarget(
                memoryData, interpreter, tagsIndex, Vehicle.Car);
            var dataProcessorSource = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedString));
            var sorter = new OsmStreamFilterSort();

            sorter.RegisterSource(dataProcessorSource);
            targetData.RegisterSource(sorter);
            targetData.Pull();

            // do the pre-processing part.
            var preProcessor = new CHPreProcessor(memoryData,
                                                  new SparseOrdering(memoryData), new DykstraWitnessCalculator());

            preProcessor.Start();

            return(memoryData);
        }
Example #6
0
        public void TestReadNode()
        {
            // build the source.
            var source = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(
                    "OsmSharp.Test.data.xml.node.osm"));

            // read.
            var result = new List <OsmGeo>(source);

            // check results.
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count);
            Assert.IsInstanceOf <Node>(result[0]);
            var node = result[0] as Node;

            Assert.AreEqual(471625991, node.Id);
            Assert.AreEqual(51.2704712, node.Latitude);
            Assert.AreEqual(4.8006659, node.Longitude);
            Assert.AreEqual("marc12", node.UserName);
            Assert.AreEqual(540527, node.UserId);
            Assert.AreEqual(true, node.Visible);
            Assert.AreEqual(3, node.Version);
            Assert.AreEqual(9797840, node.ChangeSetId);
            Assert.AreEqual(new DateTime(2011, 11, 11, 16, 43, 47), node.TimeStamp.Value.ToUniversalTime());
            Assert.IsNotNull(node.Tags);
            Assert.AreEqual(3, node.Tags.Count);
            Assert.IsTrue(node.Tags.Contains("alt_name", "Lille"));
            Assert.IsTrue(node.Tags.Contains("name", "Wechelderzande"));
            Assert.IsTrue(node.Tags.Contains("traffic_sign", "city_limit"));
        }
Example #7
0
        public void RoutingRegressionTest1()
        {
            var interpreter = new OsmRoutingInterpreter();
            var tagsIndex   = new TagsTableCollectionIndex();

            // do the data processing.
            var memoryData          = new DynamicGraphRouterDataSource <LiveEdge>(tagsIndex);
            var targetData          = new LiveGraphOsmStreamTarget(memoryData, interpreter, tagsIndex);
            var dataProcessorSource = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test_routing_regression1.osm"));
            var sorter = new OsmStreamFilterSort();

            sorter.RegisterSource(dataProcessorSource);
            targetData.RegisterSource(sorter);
            targetData.Pull();

            var basicRouter = new DykstraRoutingLive();
            var router      = Router.CreateLiveFrom(memoryData, basicRouter, interpreter);

            // resolve the three points in question.
            var point35         = new GeoCoordinate(51.01257, 4.000753);
            var point35resolved = router.Resolve(Vehicle.Car, point35);
            var point45         = new GeoCoordinate(51.01315, 3.999588);
            var point45resolved = router.Resolve(Vehicle.Car, point45);

            // route between 35 and 45.
            var routebefore = router.Calculate(Vehicle.Car, point35resolved, point45resolved);

            // route between 35 and 45.
            var routeafter = router.Calculate(Vehicle.Car, point35resolved, point45resolved);

            Assert.AreEqual(routebefore.TotalDistance, routeafter.TotalDistance);
        }
        /// <summary>
        /// Returns a new router.
        /// </summary>
        /// <param name="interpreter"></param>
        /// <param name="embeddedName"></param>
        /// <returns></returns>
        public override Router BuildRouter(IOsmRoutingInterpreter interpreter, string embeddedName)
        {
            if (_data == null)
            {
                _data = new Dictionary <string, RouterDataSource <CHEdgeData> >();
            }
            RouterDataSource <CHEdgeData> data = null;

            if (!_data.TryGetValue(embeddedName, out data))
            {
                var tagsIndex = new TagsIndex();

                // do the data processing.
                data = new RouterDataSource <CHEdgeData>(new DirectedGraph <CHEdgeData>(), tagsIndex);
                var targetData = new CHEdgeGraphOsmStreamTarget(
                    data, interpreter, tagsIndex, Vehicle.Car);
                var dataProcessorSource = new XmlOsmStreamSource(
                    Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format(
                                                                                  "OsmSharp.Test.Unittests.{0}", embeddedName)));
                var sorter = new OsmStreamFilterSort();
                sorter.RegisterSource(dataProcessorSource);
                targetData.RegisterSource(sorter);
                targetData.Pull();

                _data[embeddedName] = data;
            }
            return(Router.CreateCHFrom(data, new CHRouter(), interpreter));
        }
Example #9
0
        /// <summary>
        /// Builds the data.
        /// </summary>
        /// <param name="interpreter"></param>
        /// <param name="embeddedString"></param>
        /// <returns></returns>
        public override IRoutingAlgorithmData <CHEdgeData> BuildData(IOsmRoutingInterpreter interpreter,
                                                                     string embeddedString)
        {
            string key = string.Format("CHEdgeDifference.Routing.IRoutingAlgorithmData<CHEdgeData>.OSM.{0}",
                                       embeddedString);
            var data = StaticDictionary.Get <IRoutingAlgorithmData <CHEdgeData> >(
                key);

            if (data == null)
            {
                var tagsIndex = new TagsIndex();

                // do the data processing.
                var memoryData = new RouterDataSource <CHEdgeData>(new DirectedGraph <CHEdgeData>(), tagsIndex);
                var targetData = new CHEdgeGraphOsmStreamTarget(
                    memoryData, interpreter, tagsIndex, Vehicle.Car);
                var dataProcessorSource = new XmlOsmStreamSource(
                    Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedString));
                var sorter = new OsmStreamFilterSort();
                sorter.RegisterSource(dataProcessorSource);
                targetData.RegisterSource(sorter);
                targetData.Pull();

                data = memoryData;
                StaticDictionary.Add <IRoutingAlgorithmData <CHEdgeData> >(key, data);
            }
            return(data);
        }
        /// <summary>
        /// Returns a new router.
        /// </summary>
        /// <param name="interpreter"></param>
        /// <param name="embeddedName"></param>
        /// <param name="contract"></param>
        /// <returns></returns>
        public override Router BuildRouter(IOsmRoutingInterpreter interpreter, string embeddedName, bool contract)
        {
            if (_data == null)
            {
                _data = new Dictionary <string, DynamicGraphRouterDataSource <LiveEdge> >();
            }
            DynamicGraphRouterDataSource <LiveEdge> data = null;

            if (!_data.TryGetValue(embeddedName, out data))
            {
                var tagsIndex = new TagsTableCollectionIndex();

                // do the data processing.
                data = new DynamicGraphRouterDataSource <LiveEdge>(tagsIndex);
                var targetData = new LiveGraphOsmStreamTarget(
                    data, interpreter, tagsIndex, new Vehicle[] { Vehicle.Car }, false);
                var dataProcessorSource = new XmlOsmStreamSource(
                    Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format(
                                                                                  "OsmSharp.Test.Unittests.{0}", embeddedName)));
                var sorter = new OsmStreamFilterSort();
                sorter.RegisterSource(dataProcessorSource);
                targetData.RegisterSource(sorter);
                targetData.Pull();

                _data[embeddedName] = data;
            }
            return(Router.CreateLiveFrom(data, new Dykstra(), interpreter));
        }
        /// <summary>
        /// Returns a new router.
        /// </summary>
        /// <param name="interpreter"></param>
        /// <param name="embeddedName"></param>
        /// <param name="contract"></param>
        /// <returns></returns>
        public override Router BuildRouter(IOsmRoutingInterpreter interpreter, string embeddedName, bool contract)
        {
            if (_data == null)
            {
                _data = new Dictionary <string, DynamicGraphRouterDataSource <CHEdgeData> >();
            }
            DynamicGraphRouterDataSource <CHEdgeData> data = null;

            if (!_data.TryGetValue(embeddedName, out data))
            {
                var tagsIndex = new TagsTableCollectionIndex();

                // do the data processing.
                data =
                    new DynamicGraphRouterDataSource <CHEdgeData>(tagsIndex);
                var targetData = new CHEdgeGraphOsmStreamTarget(
                    data, interpreter, tagsIndex, Vehicle.Car);
                var dataProcessorSource = new XmlOsmStreamSource(
                    Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format(
                                                                                  "OsmSharp.Test.Unittests.{0}", embeddedName)));
                var sorter = new OsmStreamFilterSort();
                sorter.RegisterSource(dataProcessorSource);
                targetData.RegisterSource(sorter);
                targetData.Pull();

                // do the pre-processing part.
                var preProcessor = new CHPreProcessor(data,
                                                      new SparseOrdering(data), new DykstraWitnessCalculator());
                preProcessor.Start();

                _data[embeddedName] = data;
            }
            return(Router.CreateCHFrom(data, new CHRouter(), interpreter));
        }
Example #12
0
        /// <summary>
        /// Creates a router.
        /// </summary>
        /// <param name="interpreter"></param>
        /// <param name="manifestResourceName"></param>
        /// <returns></returns>
        protected override Router CreateRouter(IOsmRoutingInterpreter interpreter, string manifestResourceName)
        {
            SimpleTagsIndex tagsIndex = new SimpleTagsIndex();

            // do the data processing.
            var data       = new DynamicGraphRouterDataSource <CHEdgeData>(tagsIndex);
            var targetData = new CHEdgeGraphOsmStreamTarget(
                data, interpreter, tagsIndex, Vehicle.Car);
            var dataProcessorSource = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(manifestResourceName));
            var sorter = new OsmStreamFilterSort();

            sorter.RegisterSource(dataProcessorSource);
            targetData.RegisterSource(sorter);
            targetData.Pull();

            // do the pre-processing part.
            var witnessCalculator = new DykstraWitnessCalculator();
            var preProcessor      = new CHPreProcessor(data,
                                                       new EdgeDifference(data, witnessCalculator), witnessCalculator);

            preProcessor.Start();

            //IBasicRouter<LiveEdge> basicRouter = new DykstraRoutingLive(memoryData.TagsIndex);
            return(Router.CreateCHFrom(data, new CHRouter(), interpreter));
        }
Example #13
0
        public void FullTranslateAddresses()
        {
            var sourceFile = "SampleE911Addresses.osm";
            var source     = new XmlOsmStreamSource(File.OpenRead(sourceFile));

            using (Translator translator = new Translator(source))
            {
                translator.AddLookup("Lookups\\Directions.json");
                translator.AddLookup("Lookups\\PlaceTypes.json");
                translator.AddLookup("Lookups\\StreetSuffixes.json");
                var sqlFile      = "Queries\\E911AddressesToOsmSchema.sql";
                var expectedFile = "E911AddressesToOsmSchema.sql+SampleE911Addresses.osm";

                var results   = translator.QueryElements(File.ReadAllText(sqlFile));
                var expecteds = new XmlOsmStreamSource(File.OpenRead(expectedFile)).ToArray();

                Assert.AreEqual(results.Length, expecteds.Length);
                var index = results.ToDictionary(e => e.Id);

                foreach (var expected in expecteds)
                {
                    Assert.IsTrue(index.ContainsKey(expected.Id));
                    var result = index[expected.Id];
                    Assert.AreEqual(result.Tags.Count, expected.Tags.Count);

                    foreach (var expectedTag in expected.Tags)
                    {
                        Assert.IsTrue(result.Tags.Contains(expectedTag));
                    }
                }
            }
        }
Example #14
0
        /// <summary>
        /// Bootstraps this service.
        /// </summary>
        public static void Start(string dataPath)
        {
            Bootstrapper.DataPath = dataPath;

            Bootstrapper.GetData = (stream, box, file) =>
            {
                var fullFilePath = Path.Combine(dataPath, file);
                if (!File.Exists(fullFilePath))
                {
                    throw new FileNotFoundException();
                }
                using (var inputStream = File.Open(fullFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    OsmStreamSource source;
                    if (fullFilePath.EndsWith("osm"))
                    {
                        source = new XmlOsmStreamSource(inputStream);
                    }
                    else if (fullFilePath.EndsWith("osm.pbf"))
                    {
                        source = new PBFOsmStreamSource(inputStream);
                    }
                    else
                    {
                        throw new NotSupportedException("File need to be an OSM-XML or OSM-PBF file.");
                    }

                    var filtered = source.FilterBox(box.Left, box.Top, box.Right, box.Bottom, true);

                    var target = new XmlOsmStreamTarget(stream);
                    target.RegisterSource(filtered);
                    target.Pull();
                }
            };
        }
Example #15
0
        /// <summary>
        /// Builds data source.
        /// </summary>
        /// <param name="interpreter"></param>
        /// <param name="embeddedString"></param>
        /// <returns></returns>
        public override IBasicRouterDataSource <LiveEdge> BuildData(IOsmRoutingInterpreter interpreter,
                                                                    string embeddedString)
        {
            string key = string.Format("Dykstra.Routing.IBasicRouterDataSource<SimpleWeighedEdge>.OSM.{0}",
                                       embeddedString);
            var data = StaticDictionary.Get <IBasicRouterDataSource <LiveEdge> >(
                key);

            if (data == null)
            {
                var tagsIndex = new TagsTableCollectionIndex();

                // do the data processing.
                var memoryData          = new DynamicGraphRouterDataSource <LiveEdge>(tagsIndex);
                var targetData          = new LiveGraphOsmStreamTarget(memoryData, interpreter, tagsIndex);
                var dataProcessorSource = new XmlOsmStreamSource(
                    Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedString));
                var sorter = new OsmStreamFilterSort();
                sorter.RegisterSource(dataProcessorSource);
                targetData.RegisterSource(sorter);
                targetData.Pull();

                data = memoryData;
                StaticDictionary.Add <IBasicRouterDataSource <LiveEdge> >(key,
                                                                          data);
            }
            return(data);
        }
Example #16
0
        public OSMreader()
        {
            _peeks = new List <Peek>();

            file      = new FileInfo(@"OSMrecources\België.osm");
            xmlSource = new XmlOsmStreamSource(file.OpenRead());
            xmlSource.Initialize();
            read();
        }
Example #17
0
        private static void OpenOsmFile(string osmPath)
        {
            var fs = File.OpenRead(osmPath);

            Console.WriteLine("Opening osm file");
            var stream = new XmlOsmStreamSource(fs);

            osm = stream.ToComplete();
        }
Example #18
0
        protected async Task <IEnumerable <T> > GetOfType <T>(string address, Action <HttpRequestMessage> auth = null) where T : class
        {
            var content = await Get(address, auth);

            var streamSource = new XmlOsmStreamSource(await content.ReadAsStreamAsync());
            var elements     = streamSource.OfType <T>();

            return(elements);
        }
Example #19
0
        /// <summary>
        /// Raises the OnLoad event.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // initialize mapcss interpreter.
            var mapCSSInterpreter = new MapCSSInterpreter(
                new FileInfo(@"D:\Dropbox\Dropbox\SharpSoftware\Projects\Eurostation ReLive\Server_Dropbox\OSM\static\default.mapcss").OpenRead(), new MapCSSDictionaryImageSource());

            // initialize map.
            var map = new OsmSharp.UI.Map.Map();

            //// initialize router.
            //_router = Router.CreateLiveFrom(new OsmSharp.Osm.PBF.Streams.PBFOsmStreamSource(
            //    new FileInfo(@"kempen.osm.pbf").OpenRead()), new OsmRoutingInterpreter());

            var scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), new List <float>(new float[] {
                16, 14, 12, 10
            }));
            var target = new StyleOsmStreamSceneTarget(
                mapCSSInterpreter, scene, new WebMercator());
            var source = new XmlOsmStreamSource(
                new FileInfo(@"D:\Dropbox\Dropbox\SharpSoftware\Projects\Eurostation ReLive\Server_Dropbox\OSM\relive_mechelen\mechelen_new.osm").OpenRead());
            var progress = new OsmStreamFilterProgress();

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

            //var merger = new Scene2DObjectMerger();
            //scene = merger.BuildMergedScene(scene);

            map.AddLayer(new LayerScene(scene));
            //var dataSource = MemoryDataSource.CreateFromXmlStream(
            //    new FileInfo(@"D:\Dropbox\Dropbox\SharpSoftware\Projects\Eurostation ReLive\Server_Dropbox\OSM\relive_mechelen\mechelen_new.osm").OpenRead());
            //map.AddLayer(new LayerOsm(dataSource, mapCSSInterpreter, map.Projection));
            //var layerTile = new LayerTile(@"http://otile1.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpg", 200);
            //layerTile.MinZoom = 12;
            //layerTile.MaxZoom = 13;
            //map.AddLayer(layerTile);
            //map.AddLayer(new LayerScene(
            //    Scene2D.Deserialize(new FileInfo(@"default.map").OpenRead(),
            //        true)));

            // initialize route/points layer.
            _layerRoute = new LayerRoute(new OsmSharp.Math.Geo.Projections.WebMercator());
            map.AddLayer(_layerRoute);
            _layerPrimitives = new LayerPrimitives(new OsmSharp.Math.Geo.Projections.WebMercator());
            map.AddLayer(_layerPrimitives);

            // set control properties.
            this.mapControl1.Map            = map;
            this.mapControl1.MapCenter      = new GeoCoordinate(51.0167, 4.4914); // wechel
            this.mapControl1.MapZoom        = 14;
            this.mapControl1.MapMouseClick += mapControl1_MapMouseClick;
            this.mapControl1.MapMouseMove  += mapControl1_MapMouseMove;
        }
        public void RoutingRegressionTest7Contracted()
        {
            double e = 0.2; // 10 cm

            // network:
            //        x(6)-----------x(4)---x(5)
            //        /              /
            // x(1)--x(2)---------x(3)

            var vertex1 = new GeoCoordinate(50.984988723456084, 4.828170772332617);
            var vertex2 = new GeoCoordinate(50.984987035397620, 4.828346366914291);
            var vertex3 = new GeoCoordinate(50.984985823202960, 4.828728258663133);
            var vertex4 = new GeoCoordinate(50.985013303511700, 4.828792771883094);
            var vertex5 = new GeoCoordinate(50.985012880931120, 4.828949650265730);
            var vertex6 = new GeoCoordinate(50.985017593072016, 4.828410262241598);

            var source = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test_routing_regression5.osm"));
            var router = Router.CreateCHFrom(source, new OsmRoutingInterpreter(), Vehicle.Car);

            var resolved1 = router.Resolve(Vehicle.Car, vertex1, true);

            Assert.AreEqual(0, resolved1.Location.DistanceReal(vertex1).Value, e);
            var resolved2 = router.Resolve(Vehicle.Car, vertex2, true);

            Assert.AreEqual(0, resolved2.Location.DistanceReal(vertex2).Value, e);
            var resolved3 = router.Resolve(Vehicle.Car, vertex3, true);

            Assert.AreEqual(0, resolved3.Location.DistanceReal(vertex3).Value, e);
            var resolved4 = router.Resolve(Vehicle.Car, vertex4, true);

            Assert.AreEqual(0, resolved4.Location.DistanceReal(vertex4).Value, e);
            var resolved5 = router.Resolve(Vehicle.Car, vertex5, true);

            Assert.AreEqual(0, resolved5.Location.DistanceReal(vertex5).Value, e);

            var route  = router.Calculate(Vehicle.Car, resolved1, resolved5);
            var points = new List <GeoCoordinate>(route.GetPoints());

            Assert.AreEqual(5, points.Count);
            Assert.AreEqual(0, points[0].DistanceReal(vertex1).Value, e);
            Assert.AreEqual(0, points[1].DistanceReal(vertex2).Value, e);
            Assert.AreEqual(0, System.Math.Min(points[2].DistanceReal(vertex6).Value, points[2].DistanceReal(vertex3).Value), e);
            Assert.AreEqual(0, points[3].DistanceReal(vertex4).Value, e);
            Assert.AreEqual(0, points[4].DistanceReal(vertex5).Value, e);

            route  = router.Calculate(Vehicle.Car, resolved5, resolved1);
            points = new List <GeoCoordinate>(route.GetPoints());

            Assert.AreEqual(5, points.Count);
            Assert.AreEqual(0, points[4].DistanceReal(vertex1).Value, e);
            Assert.AreEqual(0, points[3].DistanceReal(vertex2).Value, e);
            Assert.AreEqual(0, System.Math.Min(points[2].DistanceReal(vertex6).Value, points[2].DistanceReal(vertex3).Value), e);
            Assert.AreEqual(0, points[1].DistanceReal(vertex4).Value, e);
            Assert.AreEqual(0, points[0].DistanceReal(vertex5).Value, e);
        }
Example #21
0
        public List <OsmGeo> GetOsmGeoList(MapBounds mapbounds)
        {
            var task = this.Client
                       .GetStreamAsync($"{BaseAddress}/map?bbox={mapbounds.Left},{mapbounds.Bottom},{mapbounds.Right},{mapbounds.Top}");

            using (var stream = new XmlOsmStreamSource(task.Result))
            {
                return(stream.ToList());
            }
        }
Example #22
0
        /// <summary>
        /// Reads an osmGeo object from disk.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="type"></param>
        private OsmGeo Read(long id, OsmGeoType type)
        {
            XmlOsmStreamSource source      = new XmlOsmStreamSource(this.StoreFileName(id, type));
            List <OsmGeo>      readObjects = new List <OsmGeo>(source);

            source.Dispose();

            if (readObjects != null && readObjects.Count == 1)
            {
                return(readObjects[0]);
            }
            throw new InvalidDataException("Invalid cached file read, make sure not to modify the cached while in use or to synchonize access.");
        }
        public void RoutingRegressionTest8Contracted()
        {
            double e = 0.2; // 10 cm

            // network: (a/b) a=vertexX, b=contractedVertexId
            //                x(6/5)--------x(8/x)-x(4/2)---x(5/3)
            //               /                    /
            // x(1/4)--x(2/1)-x(7/6)--------x(3/x)

            // x(7/5) is one of the shapepoints converted to an actual vertex to prevent two edges 1<->2.
            // this regression test has everything to do with x(7/5).

            var vertex1 = new GeoCoordinate(50.984988723456084, 4.828170772332617);
            var vertex2 = new GeoCoordinate(50.984987035397620, 4.828346366914291);
            var vertex3 = new GeoCoordinate(50.984985823202960, 4.828728258663133);
            var vertex4 = new GeoCoordinate(50.985013303511700, 4.828792771883094);
            var vertex5 = new GeoCoordinate(50.985012880931120, 4.828949650265730);
            var vertex6 = new GeoCoordinate(50.985017593072016, 4.828410262241598);
            var vertex7 = new GeoCoordinate(50.984986416884716, 4.828409529435097);
            var vertex8 = new GeoCoordinate(50.985013738270930, 4.828723851247985);

            var source = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test_routing_regression6.osm"));
            var router = Router.CreateCHFrom(source, new OsmRoutingInterpreter(), Vehicle.Car);

            var resolved1 = router.Resolve(Vehicle.Car, vertex1, true);

            Assert.AreEqual(0, resolved1.Location.DistanceReal(vertex1).Value, e);
            var resolved2 = router.Resolve(Vehicle.Car, vertex2, true);

            Assert.AreEqual(0, resolved2.Location.DistanceReal(vertex2).Value, e);
            var resolved3 = router.Resolve(Vehicle.Car, vertex3, true);

            Assert.AreEqual(0, resolved3.Location.DistanceReal(vertex3).Value, e);
            var resolved4 = router.Resolve(Vehicle.Car, vertex4, true);

            Assert.AreEqual(0, resolved4.Location.DistanceReal(vertex4).Value, e);
            var resolved5 = router.Resolve(Vehicle.Car, vertex5, true);

            Assert.AreEqual(0, resolved5.Location.DistanceReal(vertex5).Value, e);
            var resolved6 = router.Resolve(Vehicle.Car, vertex6, true);

            Assert.AreEqual(0, resolved6.Location.DistanceReal(vertex6).Value, e);
            var resolved7 = router.Resolve(Vehicle.Car, vertex7, true);

            Assert.AreEqual(0, resolved7.Location.DistanceReal(vertex7).Value, e);
            var resolved8 = router.Resolve(Vehicle.Car, vertex8, true);

            Assert.AreEqual(0, resolved8.Location.DistanceReal(vertex8).Value, e);
        }
Example #24
0
        public void ReadRealXMLNonSeekable()
        {
            using (var fileStream = new NonSeekableStream(Assembly.GetExecutingAssembly().GetManifestResourceStream(
                                                              "OsmSharp.Test.data.xml.wechel.osm")))
            {
                var wechel = new List <OsmGeo>();
                using (var reader = new XmlOsmStreamSource(fileStream))
                {
                    wechel.AddRange(reader);
                }

                Assert.AreEqual(13978, wechel.Count);
            }
        }
Example #25
0
        /// <summary>
        /// Element Full
        /// <see href="https://wiki.openstreetmap.org/wiki/API_v0.6#Full:_GET_.2Fapi.2F0.6.2F.5Bway.7Crelation.5D.2F.23id.2Ffull">
        /// GET /api/0.6/[way|relation]/#id/full</see>.
        /// </summary>
        private async Task <TCompleteOsmGeo> GetCompleteElement <TCompleteOsmGeo>(long id) where TCompleteOsmGeo : ICompleteOsmGeo, new()
        {
            var type    = new TCompleteOsmGeo().Type.ToString().ToLower();
            var address = BaseAddress + $"0.6/{type}/{id}/full";
            var content = await Get(address);

            var stream = await content.ReadAsStreamAsync();

            var streamSource   = new XmlOsmStreamSource(stream);
            var completeSource = new OsmSimpleCompleteStreamSource(streamSource);
            var element        = completeSource.OfType <TCompleteOsmGeo>().FirstOrDefault();

            return(element);
        }
Example #26
0
        public void XmlOsmStreamSource_ShouldBeAbleToReadFromStreamWithPositionNotAvailable()
        {
            using (var fileStream = new DeflateMockStream(Assembly.GetExecutingAssembly().GetManifestResourceStream(
                                                              "OsmSharp.Test.data.xml.wechel.osm")))
            {
                var wechel = new List <OsmGeo>();
                using (var reader = new XmlOsmStreamSource(fileStream))
                {
                    wechel.AddRange(reader);
                }

                Assert.AreEqual(13978, wechel.Count);
            }
        }
Example #27
0
        public IActionResult Get(int x, int y, int z, string file)
        {
            var completeFilePath = Path.Combine(Startup.DataFolder, file);
            var fileInfo         = new FileInfo(completeFilePath);

            if (!fileInfo.Exists)
            {
                return(new NotFoundResult());
            }

            var resultStream = new MemoryStream();

            using (var stream = fileInfo.OpenRead())
            {
                OsmStreamSource source;
                if (fileInfo.Name.EndsWith(".osm.pbf"))
                {
                    source = new PBFOsmStreamSource(stream);
                }
                else if (fileInfo.Name.EndsWith(".osm"))
                {
                    source = new XmlOsmStreamSource(stream);
                }
                else
                {
                    return(new NotFoundResult());
                }

                // parse the zoom, x and y.
                var tile = new Tile(x, y, z);
                tile = tile.InvertY();
                var filter = source.FilterBox(tile.Left, tile.Top, tile.Right, tile.Bottom,
                                              true);

                var target = new XmlOsmStreamTarget(resultStream);
                target.ExtraRootAttributes.Add(new System.Tuple <string, string>("upload", "never"));
                target.Bounds = new OsmSharp.API.Bounds()
                {
                    MaxLatitude  = tile.Top,
                    MaxLongitude = tile.Right,
                    MinLatitude  = tile.Bottom,
                    MinLongitude = tile.Left
                };
                target.RegisterSource(filter);
                target.Pull();

                resultStream.Seek(0, SeekOrigin.Begin);
            }
            return(new FileStreamResult(resultStream, "text/xml"));
        }
        /// <summary>
        /// Test simple to complete conversion on the given resource.
        /// </summary>
        /// <param name="embeddedResource"></param>
        private void TestSimpleToCompleteOn(string embeddedResource)
        {
            var dataProcessorSource = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedResource));

            // fill the memory data source with source-data.
            var referenceSource = MemoryDataSource.CreateFrom(dataProcessorSource);

            // pull the complete objects.
            dataProcessorSource.Reset();
            var list = this.PullToCompleteList(dataProcessorSource);

            // compare the two.
            this.Compare(referenceSource, list);
        }
Example #29
0
        private async Task <TOsmGeo> GetElement <TOsmGeo>(string id, string type) where TOsmGeo : OsmGeo
        {
            using (var client = new HttpClient())
            {
                var address  = _elementAddress.Replace(":id", id).Replace(":type", type);
                var response = await client.GetAsync(address);

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    return(null);
                }
                var streamSource = new XmlOsmStreamSource(await response.Content.ReadAsStreamAsync());
                return(streamSource.OfType <TOsmGeo>().FirstOrDefault());
            }
        }
        public void RoutingRegressionTest6Contracted()
        {
            double e = 0.1; // 10 cm

            // network:
            //        x(1)------x(2)
            //       /           \
            // x(3)--x(4)---------x(5)--x(6)

            // 1: 50.98508962508, 4.82958530756
            // 2: 50.98509255957, 4.83009340615
            // 3: 50.98496931078, 4.82889075077
            // 4: 50.98496931078, 4.82939884936
            // 5: 50.98496931078, 4.83025189562
            // 6: 50.98496931078, 4.83079728585

            var vertex1 = new GeoCoordinate(50.98508962508, 4.82958530756);
            var vertex2 = new GeoCoordinate(50.98509255957, 4.83009340615);
            var vertex3 = new GeoCoordinate(50.98496931078, 4.82889075077);
            var vertex4 = new GeoCoordinate(50.98496931078, 4.82939884936);
            var vertex5 = new GeoCoordinate(50.98496931078, 4.83025189562);
            var vertex6 = new GeoCoordinate(50.98496931078, 4.83079728585);

            var source = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test_routing_regression4.osm"));
            var router = Router.CreateCHFrom(source, new OsmRoutingInterpreter(), Vehicle.Car);

            var resolved3 = router.Resolve(Vehicle.Car, vertex3, true);
            var resolved6 = router.Resolve(Vehicle.Car, vertex6, true);

            var route  = router.Calculate(Vehicle.Car, resolved3, resolved6);
            var points = new List <GeoCoordinate>(route.GetPoints());

            Assert.AreEqual(4, points.Count);
            Assert.AreEqual(0, points[0].DistanceReal(vertex3).Value, e);
            Assert.AreEqual(0, points[1].DistanceReal(vertex4).Value, e);
            Assert.AreEqual(0, points[2].DistanceReal(vertex5).Value, e);
            Assert.AreEqual(0, points[3].DistanceReal(vertex6).Value, e);

            route  = router.Calculate(Vehicle.Car, resolved6, resolved3);
            points = new List <GeoCoordinate>(route.GetPoints());

            Assert.AreEqual(4, points.Count);
            Assert.AreEqual(0, points[0].DistanceReal(vertex6).Value, e);
            Assert.AreEqual(0, points[1].DistanceReal(vertex5).Value, e);
            Assert.AreEqual(0, points[2].DistanceReal(vertex4).Value, e);
            Assert.AreEqual(0, points[3].DistanceReal(vertex3).Value, e);
        }