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));
        }
        public void DecodeBase64Test()
        {
            double delta = 0.0001;

            // define a base64 string we are sure is a line location.
            var stringData = Convert.FromBase64String("KwRboCNGfhJRAf/O/7SSQ03/fgCD");

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

            Assert.IsNotNull(location);
            Assert.IsInstanceOf <PoiWithAccessPointLocation>(location);
            var poiWithAccessPointLocation = (location as PoiWithAccessPointLocation);

            // check first reference.
            Assert.IsNotNull(poiWithAccessPointLocation.First);
            Assert.AreEqual(6.12829, poiWithAccessPointLocation.First.Coordinate.Longitude, delta); // 6.12829°
            Assert.AreEqual(49.60597, poiWithAccessPointLocation.First.Coordinate.Latitude, delta); // 49.60597°
            Assert.AreEqual(FunctionalRoadClass.Frc2, poiWithAccessPointLocation.First.FuntionalRoadClass);
            Assert.AreEqual(FormOfWay.MultipleCarriageWay, poiWithAccessPointLocation.First.FormOfWay);
            Assert.AreEqual(FunctionalRoadClass.Frc2, poiWithAccessPointLocation.First.LowestFunctionalRoadClassToNext);
            // Assert.AreEqual(92, poiWithAccessPointLocation.First.DistanceToNext);
            // Assert.AreEqual(202, poiWithAccessPointLocation.First.BearingDistance);

            // check second reference.
            Assert.IsNotNull(poiWithAccessPointLocation.Last);
            Assert.AreEqual(6.12779, poiWithAccessPointLocation.Last.Coordinate.Longitude, delta); // 6.12779°
            Assert.AreEqual(49.60521, poiWithAccessPointLocation.Last.Coordinate.Latitude, delta); // 49.60521°
            Assert.AreEqual(FunctionalRoadClass.Frc2, poiWithAccessPointLocation.Last.FuntionalRoadClass);
            Assert.AreEqual(FormOfWay.MultipleCarriageWay, poiWithAccessPointLocation.Last.FormOfWay);
            // Assert.AreEqual(42, poiWithAccessPointLocation.Last.BearingDistance);

            // check other properties.
            Assert.AreEqual(6.12699, poiWithAccessPointLocation.Coordinate.Longitude, delta);
            Assert.AreEqual(49.60728, poiWithAccessPointLocation.Coordinate.Latitude, delta);
            Assert.AreEqual(Orientation.NoOrientation, poiWithAccessPointLocation.Orientation);
            Assert.AreEqual(SideOfRoad.Left, poiWithAccessPointLocation.SideOfRoad);
        }