Exemplo n.º 1
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.º 2
0
        public void TestDecoding1()
        {
            Assert.Catch <ArgumentOutOfRangeException>(() =>
            {
                HeaderConvertor.Decode(new byte[] { 0 }, 4);
            });

            // decode a test header.
            var header = HeaderConvertor.Decode(new byte[] { 11 }, 0);

            Assert.AreEqual(3, header.Version);
            Assert.AreEqual(false, header.ArF0);
            Assert.AreEqual(false, header.IsPoint);
            Assert.AreEqual(false, header.ArF1);
            Assert.AreEqual(true, header.HasAttributes);

            // decode another test header.
            header = HeaderConvertor.Decode(new byte[] { 35 }, 0);
            Assert.AreEqual(3, header.Version);
            Assert.AreEqual(false, header.ArF0);
            Assert.AreEqual(true, header.IsPoint);
            Assert.AreEqual(false, header.ArF1);
            Assert.AreEqual(false, header.HasAttributes);

            // decode another test header.
            header = HeaderConvertor.Decode(new byte[] { 43 }, 0);
            Assert.AreEqual(3, header.Version);
            Assert.AreEqual(false, header.ArF0);
            Assert.AreEqual(true, header.IsPoint);
            Assert.AreEqual(false, header.ArF1);
            Assert.AreEqual(true, header.HasAttributes);

            // decode another test header.
            header = HeaderConvertor.Decode(new byte[] { 3 }, 0);
            Assert.AreEqual(3, header.Version);
            Assert.AreEqual(false, header.ArF0);
            Assert.AreEqual(false, header.IsPoint);
            Assert.AreEqual(false, header.ArF1);
            Assert.AreEqual(false, header.HasAttributes);

            // decode another test header.
            header = HeaderConvertor.Decode(new byte[] { 67 }, 0);
            Assert.AreEqual(3, header.Version);
            Assert.AreEqual(false, header.ArF0);
            Assert.AreEqual(false, header.IsPoint);
            Assert.AreEqual(true, header.ArF1);
            Assert.AreEqual(false, header.HasAttributes);

            // decode another test header.
            header = HeaderConvertor.Decode(new byte[] { 19 }, 0);
            Assert.AreEqual(3, header.Version);
            Assert.AreEqual(true, header.ArF0);
            Assert.AreEqual(false, header.IsPoint);
            Assert.AreEqual(false, header.ArF1);
            Assert.AreEqual(false, header.HasAttributes);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns true if the given data can be decoded by this decoder.
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        protected override bool CanDecode(byte[] data)
        {
            // decode the header first.
            var header = HeaderConvertor.Decode(data, 0);

            // check header info.
            if (!header.ArF1 ||
                header.IsPoint ||
                !header.ArF0 ||
                !header.HasAttributes)
            { // header is incorrect.
                return(false);
            }
            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns true if the given data can be decoded by this decoder.
        /// </summary>
        public static bool CanDecode(byte[] data)
        {
            // decode the header first.
            var header = HeaderConvertor.Decode(data, 0);

            // check header info.
            if (header.ArF1 &&
                !header.IsPoint &&
                header.ArF0 &&
                !header.HasAttributes)
            { // header is incorrect.
                return(false);
            }

            return(data != null && (data.Length == 20 || data.Length == 21));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Returns true if the given data can be decoded by this decoder.
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        protected override bool CanDecode(byte[] data)
        {
            // decode the header first.
            var header = HeaderConvertor.Decode(data, 0);

            // check header info.
            if (header.ArF1 ||
                header.IsPoint ||
                header.ArF0 ||
                header.HasAttributes)
            { // header is incorrect.
                return(false);
            }

            return(data != null && (data.Length == 8 || data.Length == 9 || data.Length == 10 || data.Length == 11));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Returns true if the given data can be decoded but this decoder.
        /// </summary>
        public static bool CanDecode(byte[] data)
        {
            if (data != null)
            {
                // decode the header first.
                var header = HeaderConvertor.Decode(data, 0);

                // check header info.
                if (header.ArF1 ||
                    header.IsPoint ||
                    header.ArF0 ||
                    !header.HasAttributes)
                { // header is incorrect.
                    return(false);
                }

                return(true);
            }
            return(false);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Returns true if the given data can be decoded but this decoder.
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        protected override bool CanDecode(byte[] data)
        {
            if (data != null)
            {
                // decode the header first.
                var header = HeaderConvertor.Decode(data, 0);

                // check header info.
                if (header.ArF1 ||
                    header.IsPoint ||
                    !header.ArF0 ||
                    header.HasAttributes)
                { // header is incorrect.
                    return(false);
                }

                int count = (data.Length - 15);
                return(count % 4 == 0);
            }
            return(false);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Returns true if the given data can be decoded but this decoder.
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        protected override bool CanDecode(byte[] data)
        {
            if (data != null)
            {
                // decode the header first.
                var header = HeaderConvertor.Decode(data, 0);

                // check header info.
                if (header.ArF1 ||
                    header.IsPoint ||
                    header.ArF0 ||
                    !header.HasAttributes)
                { // header is incorrect.
                    return(false);
                }

                //// check size.
                //int count = data.Length - 16;
                //int mod7 = count % 7;
                //return mod7 == 0 || mod7 == 1 || mod7 == 2;
                return(true);
            }
            return(false);
        }
Exemplo n.º 9
0
        public void TestEncoding1()
        {
            var data   = new byte[1];
            var header = new Header()
            {
                ArF0          = false,
                IsPoint       = false,
                ArF1          = false,
                HasAttributes = true,
                Version       = 3
            };

            // test out of range.
            Assert.Catch <ArgumentOutOfRangeException>(() =>
            {
                HeaderConvertor.Encode(data, 10, header);
            });

            // test encoding header.
            HeaderConvertor.Encode(data, 0, header);
            Assert.AreEqual(11, data[0]);

            // test encoding another header.
            header = new Header()
            {
                ArF0          = false,
                IsPoint       = true,
                ArF1          = false,
                HasAttributes = false,
                Version       = 3
            };
            HeaderConvertor.Encode(data, 0, header);
            Assert.AreEqual(35, data[0]);

            // test encoding another header.
            header = new Header()
            {
                ArF0          = false,
                IsPoint       = false,
                ArF1          = false,
                HasAttributes = false,
                Version       = 3
            };
            HeaderConvertor.Encode(data, 0, header);
            Assert.AreEqual(3, data[0]);

            // test encoding another header.
            header = new Header()
            {
                ArF0          = false,
                IsPoint       = false,
                ArF1          = true,
                HasAttributes = false,
                Version       = 3
            };
            HeaderConvertor.Encode(data, 0, header);
            Assert.AreEqual(67, data[0]);

            // test encoding another header.
            header = new Header()
            {
                ArF0          = true,
                IsPoint       = false,
                ArF1          = false,
                HasAttributes = false,
                Version       = 3
            };
            HeaderConvertor.Encode(data, 0, header);
            Assert.AreEqual(19, data[0]);
        }
Exemplo n.º 10
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);
        }