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

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

            BearingConvertor.Encode(0, data, 0, 0);
            Assert.AreEqual(0, data[0]);
            BearingConvertor.Encode(1, data, 0, 3);
            Assert.AreEqual(1, data[0]);
            BearingConvertor.Encode(5, data, 0, 3);
            Assert.AreEqual(5, data[0]);
            BearingConvertor.Encode(9, data, 0, 3);
            Assert.AreEqual(9, data[0]);

            data[0] = 0;
            BearingConvertor.Encode(1, data, 0, 1);
            Assert.AreEqual(4, data[0]);
            data[0] = 0;
            BearingConvertor.Encode(5, data, 0, 1);
            Assert.AreEqual(20, data[0]);
            data[0] = 0;
            BearingConvertor.Encode(9, data, 0, 1);
            Assert.AreEqual(36, data[0]);
        }
Exemplo n.º 2
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.º 3
0
        /// <summary>
        /// Decodes the given data into a location reference.
        /// </summary>
        public static PointAlongLineLocation Decode(byte[] data)
        {
            var pointAlongLine = new PointAlongLineLocation();

            // decode first location reference point.
            var first = new LocationReferencePoint();

            first.Coordinate         = CoordinateConverter.Decode(data, 1);
            first.FuntionalRoadClass = FunctionalRoadClassConvertor.Decode(data, 7, 2);
            first.FormOfWay          = FormOfWayConvertor.Decode(data, 7, 5);
            first.LowestFunctionalRoadClassToNext = FunctionalRoadClassConvertor.Decode(data, 8, 0);
            first.Bearing        = BearingConvertor.DecodeAngleFromBearing(BearingConvertor.Decode(data, 8, 3));
            first.DistanceToNext = DistanceToNextConvertor.Decode(data[9]);

            // decode second location reference point.
            var last = new LocationReferencePoint();

            last.Coordinate         = CoordinateConverter.DecodeRelative(first.Coordinate, data, 10);
            last.FuntionalRoadClass = FunctionalRoadClassConvertor.Decode(data, 14, 2);
            last.FormOfWay          = FormOfWayConvertor.Decode(data, 14, 5);
            last.Bearing            = BearingConvertor.DecodeAngleFromBearing(BearingConvertor.Decode(data, 15, 3));

            pointAlongLine.First       = first;
            pointAlongLine.Orientation = OrientationConverter.Decode(data, 7, 0);
            pointAlongLine.SideOfRoad  = SideOfRoadConverter.Decode(data, 14, 0);
            pointAlongLine.PositiveOffsetPercentage = OffsetConvertor.Decode(data, 16);
            pointAlongLine.Last = last;

            return(pointAlongLine);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Decodes the given data into a location reference.
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        protected override ClosedLineLocation Decode(byte[] data)
        {
            // decode first location reference point.
            var first = new LocationReferencePoint();

            first.Coordinate         = CoordinateConverter.Decode(data, 1);
            first.FuntionalRoadClass = FunctionalRoadClassConvertor.Decode(data, 7, 2);
            first.FormOfWay          = FormOfWayConvertor.Decode(data, 7, 5);
            first.LowestFunctionalRoadClassToNext = FunctionalRoadClassConvertor.Decode(data, 8, 0);
            first.Bearing        = BearingConvertor.DecodeAngleFromBearing(BearingConvertor.Decode(data, 8, 3));
            first.DistanceToNext = DistanceToNextConvertor.Decode(data[9]);

            // calculate the intermediate points count.
            var intermediateList = new List <LocationReferencePoint>();
            int intermediates    = (data.Length - 12) / 7;
            int location         = 10;
            var reference        = first.Coordinate; // the reference for the relative coordinates.

            for (int idx = 0; idx < intermediates; idx++)
            {
                // create an intermediate point.
                var intermediate = new LocationReferencePoint();
                intermediate.Coordinate = CoordinateConverter.DecodeRelative(reference, data, location);
                reference = intermediate.Coordinate;
                location  = location + 4;
                intermediate.FuntionalRoadClass = FunctionalRoadClassConvertor.Decode(data, location, 2);
                intermediate.FormOfWay          = FormOfWayConvertor.Decode(data, location, 5);
                location             = location + 1;
                intermediate.Bearing = BearingConvertor.DecodeAngleFromBearing(BearingConvertor.Decode(data, location, 3));
                intermediate.LowestFunctionalRoadClassToNext = FunctionalRoadClassConvertor.Decode(data, location, 0);
                location = location + 1;
                intermediate.DistanceToNext = DistanceToNextConvertor.Decode(data[location]);
                location = location + 1;

                intermediateList.Add(intermediate);
            }

            // decode last location reference point.
            var last = new LocationReferencePoint();

            // no last coordinates, identical to the first.
            last.Coordinate         = first.Coordinate;
            last.FuntionalRoadClass = FunctionalRoadClassConvertor.Decode(data, location, 2);
            last.FormOfWay          = FormOfWayConvertor.Decode(data, location, 5);
            location = location + 1;
            last.LowestFunctionalRoadClassToNext = FunctionalRoadClassConvertor.Decode(data, location, 0);
            last.Bearing = BearingConvertor.DecodeAngleFromBearing(BearingConvertor.Decode(data, location, 3));
            location     = location + 1;

            // create line location.
            var lineLocation = new ClosedLineLocation();

            lineLocation.First        = first;
            lineLocation.Intermediate = intermediateList.ToArray();
            lineLocation.Last         = last;
            return(lineLocation);
        }
Exemplo n.º 5
0
 public void TestBearingAngleDecoding()
 {
     Assert.AreEqual(0, BearingConvertor.DecodeAngleFromBearing(0));
     Assert.Catch <ArgumentOutOfRangeException>(() =>
     {
         BearingConvertor.DecodeAngleFromBearing(-1);
     });
     Assert.Catch <ArgumentOutOfRangeException>(() =>
     {
         BearingConvertor.DecodeAngleFromBearing(32);
     });
     Assert.AreEqual(90, BearingConvertor.DecodeAngleFromBearing(8));
     Assert.AreEqual(180, BearingConvertor.DecodeAngleFromBearing(16));
     Assert.AreEqual(270, BearingConvertor.DecodeAngleFromBearing(24));
 }
Exemplo n.º 6
0
 public void TestBearingAngleEncoding()
 {
     Assert.AreEqual(0, BearingConvertor.EncodeAngleToBearing(0));
     Assert.Catch <ArgumentOutOfRangeException>(() =>
     {
         BearingConvertor.EncodeAngleToBearing(-1);
     });
     Assert.Catch <ArgumentOutOfRangeException>(() =>
     {
         BearingConvertor.EncodeAngleToBearing(360);
     });
     Assert.AreEqual(8, BearingConvertor.EncodeAngleToBearing(90));
     Assert.AreEqual(16, BearingConvertor.EncodeAngleToBearing(180));
     Assert.AreEqual(24, BearingConvertor.EncodeAngleToBearing(270));
 }
Exemplo n.º 7
0
        public void TestFrcBearing()
        {
            var data = new byte[1];

            data[0] = 0;

            // bearing-frc.
            BearingConvertor.Encode(17, data, 0, 3);
            FunctionalRoadClassConvertor.Encode(FunctionalRoadClass.Frc3, data, 0, 0);
            Assert.AreEqual(113, data[0]);

            // frc-bearing.
            FunctionalRoadClassConvertor.Encode(FunctionalRoadClass.Frc3, data, 0, 0);
            BearingConvertor.Encode(17, data, 0, 3);
            Assert.AreEqual(113, data[0]);
        }
Exemplo n.º 8
0
        public void TestDecoding1()
        {
            Assert.Catch <ArgumentOutOfRangeException>(() =>
            {
                BearingConvertor.Decode(new byte[] { 0 }, 4);
            });

            Assert.AreEqual(0, BearingConvertor.Decode(new byte[] { 0 }, 0, 0));
            Assert.AreEqual(0, BearingConvertor.Decode(new byte[] { 0 }, 0));
            Assert.AreEqual(1, BearingConvertor.Decode(new byte[] { 1 }, 3));
            Assert.AreEqual(5, BearingConvertor.Decode(new byte[] { 5 }, 3));
            Assert.AreEqual(9, BearingConvertor.Decode(new byte[] { 9 }, 3));

            Assert.AreEqual(1, BearingConvertor.Decode(new byte[] { 4 }, 1));
            Assert.AreEqual(5, BearingConvertor.Decode(new byte[] { 20 }, 1));
            Assert.AreEqual(9, BearingConvertor.Decode(new byte[] { 36 }, 1));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Decodes the given data into a location reference.
        /// </summary>
        public static PoiWithAccessPointLocation Decode(byte[] data)
        {
            // decode first location reference point.
            var first = new LocationReferencePoint();

            first.Coordinate = CoordinateConverter.Decode(data, 1);
            var orientation = OrientationConverter.Decode(data, 7, 0);

            first.FuntionalRoadClass = FunctionalRoadClassConvertor.Decode(data, 7, 2);
            first.FormOfWay          = FormOfWayConvertor.Decode(data, 7, 5);
            first.LowestFunctionalRoadClassToNext = FunctionalRoadClassConvertor.Decode(data, 8, 0);
            first.Bearing        = BearingConvertor.DecodeAngleFromBearing(BearingConvertor.Decode(data, 8, 3));
            first.DistanceToNext = DistanceToNextConvertor.Decode(data[9]);

            // decode last location reference point.
            var last = new LocationReferencePoint();

            // no last coordinates, identical to the first.
            last.Coordinate = CoordinateConverter.DecodeRelative(first.Coordinate, data, 10);
            var sideOfRoad = SideOfRoadConverter.Decode(data, 14, 0);

            last.FuntionalRoadClass = FunctionalRoadClassConvertor.Decode(data, 14, 2);
            last.FormOfWay          = FormOfWayConvertor.Decode(data, 14, 5);
            last.Bearing            = BearingConvertor.DecodeAngleFromBearing(BearingConvertor.Decode(data, 15, 3));

            // poi details.
            var coordinate = CoordinateConverter.DecodeRelative(first.Coordinate, data, 17);

            // create line location.
            var poiWithAccessPointLocation = new PoiWithAccessPointLocation();

            poiWithAccessPointLocation.First          = first;
            poiWithAccessPointLocation.Last           = last;
            poiWithAccessPointLocation.Coordinate     = coordinate;
            poiWithAccessPointLocation.Orientation    = orientation;
            poiWithAccessPointLocation.PositiveOffset = null;
            poiWithAccessPointLocation.SideOfRoad     = sideOfRoad;
            return(poiWithAccessPointLocation);
        }
Exemplo n.º 10
0
        public void TestPOffNOffBearing()
        {
            var data = new byte[1];

            data[0] = 0;

            // poff-noff-bearing.
            OffsetConvertor.EncodeFlag(true, data, 0, 1);
            OffsetConvertor.EncodeFlag(true, data, 0, 2);
            BearingConvertor.Encode(17, data, 0, 3);
            Assert.AreEqual(113, data[0]);

            // poff-bearing-noff.
            OffsetConvertor.EncodeFlag(true, data, 0, 1);
            BearingConvertor.Encode(17, data, 0, 3);
            OffsetConvertor.EncodeFlag(true, data, 0, 2);
            Assert.AreEqual(113, data[0]);

            // bearing-poff-noff.
            BearingConvertor.Encode(17, data, 0, 3);
            OffsetConvertor.EncodeFlag(true, data, 0, 1);
            OffsetConvertor.EncodeFlag(true, data, 0, 2);
            Assert.AreEqual(113, data[0]);
        }
Exemplo n.º 11
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);
        }