Esempio n. 1
0
        /// <summary>
        /// Decodes the given string.
        /// </summary>
        public override ILocation Decode(string encoded)
        {
            if (encoded == null)
            {
                throw new ArgumentNullException("encoded");
            }

            // the data in a binary decoder should be a base64 string.
            byte[] binaryData = null;
            try
            {
                binaryData = Convert.FromBase64String(encoded);
            }
            catch (FormatException ex)
            { // not a base64 string.
                throw ex;
            }

            if (CircleLocationCodec.CanDecode(binaryData))
            {
                return(CircleLocationCodec.Decode(binaryData));
            }
            if (ClosedLineLocationCodec.CanDecode(binaryData))
            {
                return(ClosedLineLocationCodec.Decode(binaryData));
            }
            if (GeoCoordinateLocationCodec.CanDecode(binaryData))
            {
                return(GeoCoordinateLocationCodec.Decode(binaryData));
            }
            if (GridLocationCodec.CanDecode(binaryData))
            {
                return(GridLocationCodec.Decode(binaryData));
            }
            if (LineLocationCodec.CanDecode(binaryData))
            {
                return(LineLocationCodec.Decode(binaryData));
            }
            if (PointAlongLineLocationCodec.CanDecode(binaryData))
            {
                return(PointAlongLineLocationCodec.Decode(binaryData));
            }
            if (PoiWithAccessPointLocationCodec.CanDecode(binaryData))
            {
                return(PoiWithAccessPointLocationCodec.Decode(binaryData));
            }
            if (PolygonLocationCodec.CanDecode(binaryData))
            {
                return(PolygonLocationCodec.Decode(binaryData));
            }
            if (RectangleLocationCodec.CanDecode(binaryData))
            {
                return(RectangleLocationCodec.Decode(binaryData));
            }
            throw new ArgumentException(string.Format("Cannot decode string, no codec found: {0}", encoded));
        }
Esempio n. 2
0
        public void DecodeBase64Test()
        {
            double delta = 0.0001;

            // define a base64 string we are sure is a line location.
            var stringData = Convert.FromBase64String("CwRbWyNG9RpsCQCb/jsbtAT/6/+jK1lE");

            // decode.
            Assert.IsTrue(LineLocationCodec.CanDecode(stringData));
            var location = LineLocationCodec.Decode(stringData);

            Assert.IsNotNull(location);
            Assert.IsInstanceOf <LineLocation>(location);
            var lineLocation = (location as LineLocation);

            // check first reference.
            Assert.IsNotNull(lineLocation.First);
            Assert.AreEqual(6.12683, lineLocation.First.Coordinate.Longitude, delta); // 6.12683°
            Assert.AreEqual(49.60851, lineLocation.First.Coordinate.Latitude, delta); // 49.60851°
            Assert.AreEqual(FunctionalRoadClass.Frc3, lineLocation.First.FuntionalRoadClass);
            Assert.AreEqual(FormOfWay.MultipleCarriageWay, lineLocation.First.FormOfWay);
            Assert.AreEqual(FunctionalRoadClass.Frc3, lineLocation.First.LowestFunctionalRoadClassToNext);

            // check intermediates.
            Assert.IsNotNull(lineLocation.Intermediate);
            Assert.AreEqual(1, lineLocation.Intermediate.Length);
            Assert.AreEqual(6.12838, lineLocation.Intermediate[0].Coordinate.Longitude, delta); // 6.12838°
            Assert.AreEqual(49.60398, lineLocation.Intermediate[0].Coordinate.Latitude, delta); // 49.60398°
            Assert.AreEqual(FunctionalRoadClass.Frc3, lineLocation.Intermediate[0].FuntionalRoadClass);
            Assert.AreEqual(FormOfWay.SingleCarriageWay, lineLocation.Intermediate[0].FormOfWay);
            Assert.AreEqual(FunctionalRoadClass.Frc5, lineLocation.Intermediate[0].LowestFunctionalRoadClassToNext);

            // check second reference.
            Assert.IsNotNull(lineLocation.Last);
            Assert.AreEqual(6.12817, lineLocation.Last.Coordinate.Longitude, delta); // 6.12817°
            Assert.AreEqual(49.60305, lineLocation.Last.Coordinate.Latitude, delta); // 49.60305°
            Assert.AreEqual(FunctionalRoadClass.Frc5, lineLocation.Last.FuntionalRoadClass);
            Assert.AreEqual(FormOfWay.SingleCarriageWay, lineLocation.Last.FormOfWay);
        }