/// <summary> /// Decodes the given data into a location reference. /// </summary> /// <param name="data"></param> /// <returns></returns> protected override GeoCoordinateLocation Decode(byte[] data) { var geoCoordinate = new GeoCoordinateLocation(); geoCoordinate.Coordinate = CoordinateConverter.Decode(data, 1); return(geoCoordinate); }
/// <summary> /// Decodes the given data into a location reference. /// </summary> public static GeoCoordinateLocation Decode(byte[] data) { var geoCoordinate = new GeoCoordinateLocation(); geoCoordinate.Coordinate = CoordinateConverter.Decode(data, 1); return(geoCoordinate); }
/// <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); }
/// <summary> /// Decodes the given data into a location reference. /// </summary> /// <param name="data"></param> /// <returns></returns> protected override CircleLocation Decode(byte[] data) { var circleLocation = new CircleLocation(); circleLocation.Coordinate = CoordinateConverter.Decode(data, 1); circleLocation.Radius = data[7]; return(circleLocation); }
/// <summary> /// Decodes the given data into a location reference. /// </summary> public static RectangleLocation Decode(byte[] data) { var rectangleLocation = new RectangleLocation(); rectangleLocation.LowerLeft = CoordinateConverter.Decode(data, 1); rectangleLocation.UpperRight = CoordinateConverter.DecodeRelative(rectangleLocation.LowerLeft, data, 7); return(rectangleLocation); }
/// <summary> /// Decodes the given data into a location reference. /// </summary> public static CircleLocation Decode(byte[] data) { var circleLocation = new CircleLocation(); circleLocation.Coordinate = CoordinateConverter.Decode(data, 1); circleLocation.Radius = data[7]; return(circleLocation); }
/// <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); }
public void TestDecoding1() { double delta = 0.0001; // manually specify a binary coordinate. byte[] data = new byte[6]; data[0] = 0; data[1] = 0; data[2] = 0; data[3] = 0; data[4] = 0; data[5] = 0; // decode the coordinate. var coordinate = CoordinateConverter.Decode(data); Assert.IsNotNull(coordinate); Assert.AreEqual(0, coordinate.Latitude); Assert.AreEqual(0, coordinate.Longitude); // manually specify a binary coordinate. data[0] = 0; data[1] = 0; data[2] = 255; data[3] = 0; data[4] = 0; data[5] = 255; // decode the coordinate. coordinate = CoordinateConverter.Decode(data); Assert.IsNotNull(coordinate); Assert.AreEqual(0.005460978, coordinate.Latitude, delta); Assert.AreEqual(0.005460978, coordinate.Longitude, delta); // manually specify a binary coordinate (see example in OpenLR whitepaper). data[0] = 4; data[1] = 91; data[2] = 91; data[3] = 35; data[4] = 70; data[5] = 245; // decode the coordinate. coordinate = CoordinateConverter.Decode(data); Assert.IsNotNull(coordinate); Assert.AreEqual(49.60851, coordinate.Latitude, delta); Assert.AreEqual(6.12683, coordinate.Longitude, delta); // decode the coordinate (ensure full code coverage). coordinate = CoordinateConverter.Decode(data, 0); Assert.IsNotNull(coordinate); Assert.AreEqual(49.60851, coordinate.Latitude, delta); Assert.AreEqual(6.12683, coordinate.Longitude, delta); }
/// <summary> /// Decodes the given data into a location reference. /// </summary> /// <param name="data"></param> /// <returns></returns> protected override GridLocation Decode(byte[] data) { // decode box. var lowerLeft = CoordinateConverter.Decode(data, 1); var upperRight = CoordinateConverter.DecodeRelative(lowerLeft, data, 7); // decode column/row info. var columns = data[11] * 256 + data[12]; var rows = data[13] * 256 + data[14]; // create grid location. var grid = new GridLocation(); grid.LowerLeft = lowerLeft; grid.UpperRight = upperRight; grid.Columns = columns; grid.Rows = rows; return(grid); }
public void RegressionTestEncodeDecodeNegative() { var delta = 0.0001; // specify coordinate. var coordinate = new Coordinate() { Latitude = -52.932136535644531, Longitude = -1.5213972330093384 }; // encode. var data = new byte[1024]; CoordinateConverter.Encode(coordinate, data, 0); var decoded = CoordinateConverter.Decode(data); Assert.AreEqual(coordinate.Latitude, decoded.Latitude, delta); Assert.AreEqual(coordinate.Longitude, decoded.Longitude, delta); }
/// <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); }
/// <summary> /// Decodes the given data into a location reference. /// </summary> /// <param name="data"></param> /// <returns></returns> protected override PolygonLocation Decode(byte[] data) { // just need to decode list of coordinate. var coordinates = new List <Coordinate>(); coordinates.Add(CoordinateConverter.Decode(data, 1)); // calculate the number of points. var previous = coordinates[0]; var location = 7; int points = 1 + (data.Length - 6) / 4; for (int idx = 0; idx < points - 1; idx++) { coordinates.Add(CoordinateConverter.DecodeRelative( coordinates[coordinates.Count - 1], data, location + (idx * 4))); } var polygonLocation = new PolygonLocation(); polygonLocation.Coordinates = coordinates.ToArray(); return(polygonLocation); }