Exemplo n.º 1
0
        public void TestSideOfRoadFrcFow()
        {
            var data = new byte[1];

            data[0] = 0;

            // sideofroad-frc-fow.
            SideOfRoadConverter.Encode(SideOfRoad.Left, data, 0, 0);
            FunctionalRoadClassConvertor.Encode(FunctionalRoadClass.Frc3, data, 0, 2);
            FormOfWayConvertor.Encode(FormOfWay.Roundabout, data, 0, 5);
            Assert.AreEqual(156, data[0]);

            // frc-sideofroad-fow.
            data[0] = 0;
            FunctionalRoadClassConvertor.Encode(FunctionalRoadClass.Frc3, data, 0, 2);
            SideOfRoadConverter.Encode(SideOfRoad.Left, data, 0, 0);
            FormOfWayConvertor.Encode(FormOfWay.Roundabout, data, 0, 5);
            Assert.AreEqual(156, data[0]);

            // frc-fow-sideofroad.
            data[0] = 0;
            FunctionalRoadClassConvertor.Encode(FunctionalRoadClass.Frc3, data, 0, 2);
            FormOfWayConvertor.Encode(FormOfWay.Roundabout, data, 0, 5);
            SideOfRoadConverter.Encode(SideOfRoad.Left, data, 0, 0);
            Assert.AreEqual(156, data[0]);
        }
Exemplo n.º 2
0
        public void TestOrientationFrcFoW()
        {
            var data = new byte[1];

            data[0] = 127;

            // orientation-frc-fow.
            OrientationConverter.Encode(Orientation.FirstToSecond, data, 0, 0);
            FunctionalRoadClassConvertor.Encode(FunctionalRoadClass.Frc3, data, 0, 2);
            FormOfWayConvertor.Encode(FormOfWay.Roundabout, data, 0, 5);
            Assert.AreEqual(92, data[0]);

            // frc-orientation-fow.
            data[0] = 127;
            FunctionalRoadClassConvertor.Encode(FunctionalRoadClass.Frc3, data, 0, 2);
            OrientationConverter.Encode(Orientation.FirstToSecond, data, 0, 0);
            FormOfWayConvertor.Encode(FormOfWay.Roundabout, data, 0, 5);
            Assert.AreEqual(92, data[0]);

            // frc-fow-orientation.
            data[0] = 127;
            FunctionalRoadClassConvertor.Encode(FunctionalRoadClass.Frc3, data, 0, 2);
            FormOfWayConvertor.Encode(FormOfWay.Roundabout, data, 0, 5);
            OrientationConverter.Encode(Orientation.FirstToSecond, data, 0, 0);
            Assert.AreEqual(92, data[0]);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Encodes a point along line location.
        /// </summary>
        public static byte[] Encode(PointAlongLineLocation location)
        {
            var data = new byte[17];

            var header = new Header();

            header.Version       = 3;
            header.HasAttributes = true;
            header.ArF0          = false;
            header.IsPoint       = true;
            header.ArF1          = false;
            HeaderConvertor.Encode(data, 0, header);
            CoordinateConverter.Encode(location.First.Coordinate, data, 1);
            FunctionalRoadClassConvertor.Encode(location.First.FuntionalRoadClass.Value, data, 7, 2);
            FormOfWayConvertor.Encode(location.First.FormOfWay.Value, data, 7, 5);
            FunctionalRoadClassConvertor.Encode(location.First.LowestFunctionalRoadClassToNext.Value, data, 8, 0);
            BearingConvertor.Encode(BearingConvertor.EncodeAngleToBearing(location.First.Bearing.Value), data, 8, 3);
            data[9] = DistanceToNextConvertor.Encode(location.First.DistanceToNext);

            CoordinateConverter.EncodeRelative(location.First.Coordinate, location.Last.Coordinate, data, 10);
            FunctionalRoadClassConvertor.Encode(location.Last.FuntionalRoadClass.Value, data, 14, 2);
            FormOfWayConvertor.Encode(location.Last.FormOfWay.Value, data, 14, 5);
            BearingConvertor.Encode(BearingConvertor.EncodeAngleToBearing(location.Last.Bearing.Value), data, 15, 3);

            OrientationConverter.Encode(location.Orientation.Value, data, 7, 0);
            SideOfRoadConverter.Encode(location.SideOfRoad.Value, data, 14, 0);
            if (location.PositiveOffsetPercentage.HasValue)
            { // positive offset percentage is present.
                OffsetConvertor.Encode(location.PositiveOffsetPercentage.Value, data, 16);
            }

            return(data);
        }
Exemplo n.º 4
0
        public void TestEncoding1()
        {
            var data = new byte[1];

            Assert.Catch <ArgumentOutOfRangeException>(() =>
            {
                FormOfWayConvertor.Encode(FormOfWay.Undefined, data, 0, 10);
            });

            FormOfWayConvertor.Encode(FormOfWay.Undefined, data, 0, 5);
            Assert.AreEqual(0, data[0]);
            FormOfWayConvertor.Encode(FormOfWay.Motorway, data, 0, 5);
            Assert.AreEqual(1, data[0]);
            FormOfWayConvertor.Encode(FormOfWay.MultipleCarriageWay, data, 0, 5);
            Assert.AreEqual(2, data[0]);
            FormOfWayConvertor.Encode(FormOfWay.SingleCarriageWay, data, 0, 5);
            Assert.AreEqual(3, data[0]);
            FormOfWayConvertor.Encode(FormOfWay.Roundabout, data, 0, 5);
            Assert.AreEqual(4, data[0]);
            FormOfWayConvertor.Encode(FormOfWay.TrafficSquare, data, 0, 5);
            Assert.AreEqual(5, data[0]);
            FormOfWayConvertor.Encode(FormOfWay.SlipRoad, data, 0, 5);
            Assert.AreEqual(6, data[0]);
            FormOfWayConvertor.Encode(FormOfWay.Other, data, 0, 5);
            Assert.AreEqual(7, data[0]);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Encodes a point along line location.
        /// </summary>
        /// <param name="location"></param>
        /// <returns></returns>
        protected override byte[] EncodeByteArray(LineLocation location)
        {
            int size = 18;

            if (location.Intermediate != null)
            { // each intermediate adds 7 bytes.
                size = size + (location.Intermediate.Length * 7);
            }
            byte[] data = new byte[size];

            var header = new Header();

            header.Version       = 3;
            header.HasAttributes = true;
            header.ArF0          = false;
            header.IsPoint       = false;
            header.ArF1          = false;
            HeaderConvertor.Encode(data, 0, header);
            CoordinateConverter.Encode(location.First.Coordinate, data, 1);
            FunctionalRoadClassConvertor.Encode(location.First.FuntionalRoadClass.Value, data, 7, 2);
            FormOfWayConvertor.Encode(location.First.FormOfWay.Value, data, 7, 5);
            FunctionalRoadClassConvertor.Encode(location.First.LowestFunctionalRoadClassToNext.Value, data, 8, 0);
            BearingConvertor.Encode(BearingConvertor.EncodeAngleToBearing(location.First.Bearing.Value), data, 8, 3);
            data[9] = DistanceToNextConvertor.Encode(location.First.DistanceToNext);

            // calculate the intermediate points count.
            var position  = 10;
            var reference = location.First.Coordinate;

            if (location.Intermediate != null)
            {
                for (int idx = 0; idx < location.Intermediate.Length; idx++)
                { // create an intermediate point.
                    var intermediate = location.Intermediate[idx];
                    CoordinateConverter.EncodeRelative(location.First.Coordinate, intermediate.Coordinate, data, position);
                    reference = intermediate.Coordinate;
                    position  = position + 4;
                    FunctionalRoadClassConvertor.Encode(intermediate.FuntionalRoadClass.Value, data, position, 2);
                    FormOfWayConvertor.Encode(intermediate.FormOfWay.Value, data, position, 5);
                    position = position + 1;
                    BearingConvertor.Encode(BearingConvertor.EncodeAngleToBearing(intermediate.Bearing.Value), data, position, 3);
                    FunctionalRoadClassConvertor.Encode(intermediate.LowestFunctionalRoadClassToNext.Value, data, position, 0);
                    position       = position + 1;
                    data[position] = DistanceToNextConvertor.Encode(intermediate.DistanceToNext);
                    position       = position + 1;
                }
            }

            CoordinateConverter.EncodeRelative(reference, location.Last.Coordinate, data, position);
            FunctionalRoadClassConvertor.Encode(location.Last.FuntionalRoadClass.Value, data, position + 4, 2);
            FormOfWayConvertor.Encode(location.Last.FormOfWay.Value, data, position + 4, 5);
            BearingConvertor.Encode(BearingConvertor.EncodeAngleToBearing(location.Last.Bearing.Value), data, position + 5, 3);

            if (location.PositiveOffsetPercentage.HasValue)
            { // positive offset percentage is present.
                OffsetConvertor.EncodeFlag(true, data, position + 5, 1);
                OffsetConvertor.Encode(location.PositiveOffsetPercentage.Value, data, position + 6);
            }
            if (location.NegativeOffsetPercentage.HasValue)
            { // positive offset percentage is present.
                OffsetConvertor.EncodeFlag(true, data, position + 5, 2);
                OffsetConvertor.Encode(location.NegativeOffsetPercentage.Value, data, position + 7);
            }

            return(data);
        }