Ejemplo n.º 1
0
        public void EncodeReferencedLineLocationNotShortestPath()
        {
            var e = 0.00001f;

            // setup a routing network to test against.
            var routerDb = new RouterDb();

            routerDb.LoadTestNetwork(
                System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(
                    "OpenLR.Test.test_data.networks.network3.geojson"));
            routerDb.Sort();
            routerDb.AddSupportedVehicle(Itinero.Osm.Vehicles.Vehicle.Car);

            // setup test location and data to verify this.
            var vertex2  = routerDb.Network.GetVertex(2);
            var vertex3  = routerDb.Network.GetVertex(3);
            var vertex4  = routerDb.Network.GetVertex(4);
            var vertex5  = routerDb.Network.GetVertex(5);
            var vertex6  = routerDb.Network.GetVertex(6);
            var vertex7  = routerDb.Network.GetVertex(7);
            var location = new ReferencedLine()
            {
                Edges                    = new long[] { 1, 3, 4, 5, 2 },
                Vertices                 = new uint[] { 7, 4, 3, 2, 5, 6 },
                StartLocation            = routerDb.CreateRouterPointForVertex(7, routerDb.GetSupportedProfile("car")),
                EndLocation              = routerDb.CreateRouterPointForVertex(6, routerDb.GetSupportedProfile("car")),
                NegativeOffsetPercentage = 0,
                PositiveOffsetPercentage = 0
            };
            var json = location.ToFeatures(routerDb).ToGeoJson();

            var length = Itinero.LocalGeo.Coordinate.DistanceEstimateInMeter(
                new List <Itinero.LocalGeo.Coordinate>(new Itinero.LocalGeo.Coordinate[]
            {
                vertex7,
                vertex4,
                vertex3,
                vertex2,
                vertex5,
                vertex6
            }));

            // encode and verify result.
            var encoded = ReferencedLineCodec.Encode(location, new Coder(routerDb, new OsmCoderProfile()));

            Assert.IsNotNull(encoded.First);
            Assert.AreEqual(vertex7.Latitude, encoded.First.Coordinate.Latitude, e);
            Assert.AreEqual(vertex7.Longitude, encoded.First.Coordinate.Longitude, e);
            Assert.IsTrue(encoded.Intermediate != null && encoded.Intermediate.Length == 1);
            Assert.AreEqual(vertex6.Latitude, encoded.Last.Coordinate.Latitude, e);
            Assert.AreEqual(vertex6.Longitude, encoded.Last.Coordinate.Longitude, e);
            Assert.AreEqual(0, encoded.NegativeOffsetPercentage);
            Assert.AreEqual(0, encoded.PositiveOffsetPercentage);
            Assert.AreEqual(FunctionalRoadClass.Frc4, encoded.First.FuntionalRoadClass);
            Assert.AreEqual(FunctionalRoadClass.Frc4, encoded.First.LowestFunctionalRoadClassToNext);
            Assert.AreEqual(length, encoded.First.DistanceToNext + encoded.Intermediate[0].DistanceToNext, 1);
        }
Ejemplo n.º 2
0
        public void EncodeReferencedLineLocation()
        {
            var e = 0.00001f;

            // setup a routing network to test against.
            var routerDb = new RouterDb();

            routerDb.LoadTestNetwork(
                System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(
                    "OpenLR.Test.test_data.networks.network3.geojson"));
            routerDb.Sort();
            routerDb.AddSupportedVehicle(Itinero.Osm.Vehicles.Vehicle.Car);

            // setup test location and data to verify this.
            var start    = routerDb.Network.GetVertex(7);
            var end      = routerDb.Network.GetVertex(6);
            var location = new ReferencedLine()
            {
                Edges                    = new long[] { 1, -6, 2 },
                Vertices                 = new uint[] { 7, 4, 5, 6 },
                StartLocation            = routerDb.CreateRouterPointForVertex(7, routerDb.GetSupportedProfile("car")),
                EndLocation              = routerDb.CreateRouterPointForVertex(6, routerDb.GetSupportedProfile("car")),
                NegativeOffsetPercentage = 0,
                PositiveOffsetPercentage = 0
            };

            // encode and verify result.
            var encoded = ReferencedLineCodec.Encode(location, new Coder(routerDb, new OsmCoderProfile()));

            Assert.IsNotNull(encoded.First);
            Assert.AreEqual(start.Latitude, encoded.First.Coordinate.Latitude, e);
            Assert.AreEqual(start.Longitude, encoded.First.Coordinate.Longitude, e);
            Assert.IsTrue(encoded.Intermediate == null || encoded.Intermediate.Length == 0);
            Assert.AreEqual(end.Latitude, encoded.Last.Coordinate.Latitude, e);
            Assert.AreEqual(end.Longitude, encoded.Last.Coordinate.Longitude, e);
            Assert.AreEqual(0, encoded.NegativeOffsetPercentage);
            Assert.AreEqual(0, encoded.PositiveOffsetPercentage);
            Assert.AreEqual(FunctionalRoadClass.Frc4, encoded.First.FuntionalRoadClass);
            Assert.AreEqual(FunctionalRoadClass.Frc4, encoded.First.LowestFunctionalRoadClassToNext);
            Assert.AreEqual(Itinero.LocalGeo.Coordinate.DistanceEstimateInMeter(start, end),
                            encoded.First.DistanceToNext, 1);
        }