public void ParseGpsDirectory_ValidDirectory_LatLongMetadata() { var gpsDirectory = new GpsDirectory(); var photo = new Photo(""); var gpsReference = "N"; var gpsRationalArr = new Rational[3] { new Rational(1, 1), new Rational(60, 1), new Rational(3600, 1) }; gpsDirectory.Set(GpsDirectory.TagLatitudeRef, gpsReference); gpsDirectory.Set(GpsDirectory.TagLatitude, gpsRationalArr); gpsDirectory.Set(GpsDirectory.TagLongitudeRef, gpsReference); gpsDirectory.Set(GpsDirectory.TagLongitude, gpsRationalArr); gpsDirectory.Parse(photo); var actualLatitude = photo.Latitude; var actualLongitude = photo.Longitude; var expectedLatitude = MetadataConverter.DegreesMinutesSecondsToDecimalDegrees(gpsRationalArr, gpsReference); var expectedLongitude = MetadataConverter.DegreesMinutesSecondsToDecimalDegrees(gpsRationalArr, gpsReference); Assert.Equal(expectedLatitude, actualLatitude); Assert.Equal(expectedLongitude, actualLongitude); }
/// <summary>Parses <see cref="GpsDirectory" /> metadata and saves it to the <see cref="Photo" />.</summary> /// <param name="directory">Directory containing the GPS metadata.</param> /// <param name="photo">Photo object used for storing metadata.</param> public static void Parse(this GpsDirectory directory, Photo photo) { if (directory is null || photo is null) { return; } var gpsLatRef = directory.GetString(GpsDirectory.TagLatitudeRef); var gpsLat = directory.GetRationalArray(GpsDirectory.TagLatitude); var gpsLonRef = directory.GetString(GpsDirectory.TagLongitudeRef); var gpsLon = directory.GetRationalArray(GpsDirectory.TagLongitude); var latitude = MetadataConverter.DegreesMinutesSecondsToDecimalDegrees(gpsLat, gpsLatRef); var longitude = MetadataConverter.DegreesMinutesSecondsToDecimalDegrees(gpsLon, gpsLonRef); photo.Latitude = latitude; photo.Longitude = longitude; // if we cannot get both the altitude and its reference, do not save anything if (directory.TryGetByte(GpsDirectory.TagAltitudeRef, out var gpsAltBit) && directory.TryGetInt16(GpsDirectory.TagAltitude, out var gpsAlt)) { photo.AltitudeReference = gpsAltBit == 0 ? "Sea level" : "Below sea level"; photo.Altitude = gpsAlt; } }
public void ComputeGpsDmsToDecimalDegrees_InvalidDms() { var degMinSec = new Rational[2]; var actual = MetadataConverter.DegreesMinutesSecondsToDecimalDegrees(degMinSec, ""); Assert.Null(actual); }
public void ComputeGpsDmsToDecimalDegrees_ValidDms_InvalidGpsReference() { var degMinSec = new Rational[3]; degMinSec[0] = new Rational(1, 1); // 1 degMinSec[1] = new Rational(60, 1); // 60 degMinSec[2] = new Rational(3600, 1); // 3600 Assert.Throws <ArgumentException>(() => MetadataConverter.DegreesMinutesSecondsToDecimalDegrees(degMinSec, "A")); }
public void ComputeGpsDmsToDecimalDegrees_ValidDms_SouthGpsReference() { var degMinSec = new Rational[3]; degMinSec[0] = new Rational(1, 1); // 1 degMinSec[1] = new Rational(60, 1); // 60 degMinSec[2] = new Rational(3600, 1); // 3600 var expected = -3.0; // -1 * (1 + 60/60 + 3600/3600) = -3.0 var actual = MetadataConverter.DegreesMinutesSecondsToDecimalDegrees(degMinSec, "S"); Assert.Equal(expected, actual); }
public void ComputeGpsDmsToDecimalDegrees_NullDms() { var actual = MetadataConverter.DegreesMinutesSecondsToDecimalDegrees(null, "S"); Assert.Null(actual); }