/// <summary> /// Parses the GPS data from the specified <paramref name="bmpMetadata" /> and returns the data in an instance of <see cref="GpsLocation" />. /// </summary> /// <param name="bmpMetadata">An object containing the metadata.</param> /// <returns>An instance of <see cref="GpsLocation" />.</returns> public static GpsLocation Parse(IWpfMetadata bmpMetadata) { GpsLocation gps = new GpsLocation(); gps.Version = GetVersion(bmpMetadata); gps.Latitude = GetLatitude(bmpMetadata); gps.Longitude = GetLongitude(bmpMetadata); gps.Altitude = GetAltitude(bmpMetadata); gps.DestLatitude = GetDestLatitude(bmpMetadata); gps.DestLongitude = GetDestLongitude(bmpMetadata); //// Combine date portion of gpsDate or gpsDate2 with time portion of gpsTime2 //object gpsDate = bmpMetadata.GetQuery("System.GPS.Date"); // System.Runtime.InteropServices.ComTypes.FILETIME //object gpsDate2 = bmpMetadata.GetQuery("/app1/ifd/gps/{ushort=29}"); // 2010:08:08 //DateTime gpsDate3 = Convert((System.Runtime.InteropServices.ComTypes.FILETIME)gpsDate); //ulong[] gpsTime2 = bmpMetadata.GetQuery("/app1/ifd/gps/{ushort=7}") as ulong[]; // ulong[3] //double hh = SplitLongAndDivide(gpsTime2[0]); //double mm = SplitLongAndDivide(gpsTime2[1]); //double ss = SplitLongAndDivide(gpsTime2[2]); //object satellites = bmpMetadata.GetQuery("System.GPS.Satellites"); //"05" //object satellites2 = bmpMetadata.GetQuery("/app1/ifd/gps/{ushort=8}"); //"05" //double longitude = ConvertCoordinate(longitudeArray); return(gps); }
/// <summary> /// Invokes the <see cref="BitmapMetadata.GetQuery" /> method on <paramref name="bmpMetadata" />, passing in the specified /// <paramref name="query" />. Any <see cref="NotSupportedException" /> exceptions are silently swallowed. /// </summary> /// <param name="bmpMetadata">An object containing the metadata.</param> /// <param name="query">The query to execute against <paramref name="bmpMetadata" />.</param> /// <returns></returns> private static object GetQuery(IWpfMetadata bmpMetadata, string query) { try { return(bmpMetadata.GetQuery(query)); } catch (NotSupportedException) { return(null); } catch (System.Runtime.InteropServices.COMException) { return(null); } }
/// <summary> /// Gets the destination longitude GPS data from <paramref name="bmpMetadata" />. /// </summary> /// <param name="bmpMetadata">An object containing the metadata.</param> /// <returns>An instance of <see cref="GpsDistance" />.</returns> private static GpsDistance GetDestLongitude(IWpfMetadata bmpMetadata) { string direction = GetQuery(bmpMetadata, "System.GPS.DestLongitudeRef") as string ?? GetQuery(bmpMetadata, @"/app1/ifd/gps/{ushort=21}") as string; double[] longitude = GetQuery(bmpMetadata, "System.GPS.DestLongitude") as double[] ?? ConvertCoordinate(GetQuery(bmpMetadata, @"/app1/ifd/gps/{ushort=22}") as ulong[]); if (!String.IsNullOrEmpty(direction) && (longitude != null)) { return(new GpsDistance(direction, longitude[0], longitude[1], longitude[2])); } else { return(null); } }
/// <summary> /// Determines whether the GPS altitude is above or below sea level. Returns <c>false</c> if the metadata is not present. /// </summary> /// <param name="bmpMetadata">An object containing the metadata.</param> /// <returns> /// <c>true</c> if the GPS position is below sea level; otherwise, <c>false</c>. /// </returns> private static bool IsBelowSeaLevel(IWpfMetadata bmpMetadata) { object directionObj = GetQuery(bmpMetadata, "System.GPS.AltitudeRef") ?? GetQuery(bmpMetadata, @"/app1/ifd/gps/{ushort=5}"); bool isBelowSeaLevel = false; if (directionObj != null) { try { isBelowSeaLevel = (Convert.ToByte(directionObj, CultureInfo.InvariantCulture) == 1); // 0 = above sea level; 1 = below sea level } catch (InvalidCastException) { } } return(isBelowSeaLevel); }
/// <summary> /// Gets the version of the GPS information. Example: "2.2.0.0" /// </summary> /// <param name="bmpMetadata">An object containing the metadata.</param> /// <returns>An instance of <see cref="System.String" />.</returns> private static string GetVersion(IWpfMetadata bmpMetadata) { string version = String.Empty; byte[] versionTokens = GetQuery(bmpMetadata, "System.GPS.VersionID") as byte[] ?? GetQuery(bmpMetadata, @"/app1/ifd/gps/{ushort=0}") as byte[]; if (versionTokens == null) { return(version); } foreach (byte versionToken in versionTokens) { version += versionToken + "."; } return(version.TrimEnd(new[] { '.' })); }
private static double?GetAltitude(IWpfMetadata bmpMetadata) { object altObj = GetQuery(bmpMetadata, "System.GPS.Altitude"); if (altObj == null) { altObj = GetQuery(bmpMetadata, @"/app1/ifd/gps/{ushort=6}"); if (altObj != null) { altObj = ConvertCoordinate(new[] { (ulong)altObj })[0]; } } if (altObj == null) { return(null); } return(IsBelowSeaLevel(bmpMetadata) ? (double)altObj * (-1) : (double)altObj); }
/// <summary> /// Determines whether the GPS altitude is above or below sea level. Returns <c>false</c> if the metadata is not present. /// </summary> /// <param name="bmpMetadata">An object containing the metadata.</param> /// <returns> /// <c>true</c> if the GPS position is below sea level; otherwise, <c>false</c>. /// </returns> private static bool IsBelowSeaLevel(IWpfMetadata bmpMetadata) { object directionObj = GetQuery(bmpMetadata, "System.GPS.AltitudeRef") ?? GetQuery(bmpMetadata, @"/app1/ifd/gps/{ushort=5}"); bool isBelowSeaLevel = false; if (directionObj != null) { try { isBelowSeaLevel = (Convert.ToByte(directionObj, CultureInfo.InvariantCulture) == 1); // 0 = above sea level; 1 = below sea level } catch (InvalidCastException) { } } return isBelowSeaLevel; }
/// <summary> /// Gets the version of the GPS information. Example: "2.2.0.0" /// </summary> /// <param name="bmpMetadata">An object containing the metadata.</param> /// <returns>An instance of <see cref="System.String" />.</returns> private static string GetVersion(IWpfMetadata bmpMetadata) { string version = String.Empty; byte[] versionTokens = GetQuery(bmpMetadata, "System.GPS.VersionID") as byte[] ?? GetQuery(bmpMetadata, @"/app1/ifd/gps/{ushort=0}") as byte[]; if (versionTokens == null) return version; foreach (byte versionToken in versionTokens) { version += versionToken + "."; } return version.TrimEnd(new[] { '.' }); }
/// <summary> /// Invokes the <see cref="BitmapMetadata.GetQuery" /> method on <paramref name="bmpMetadata" />, passing in the specified /// <paramref name="query" />. Any <see cref="NotSupportedException" /> exceptions are silently swallowed. /// </summary> /// <param name="bmpMetadata">An object containing the metadata.</param> /// <param name="query">The query to execute against <paramref name="bmpMetadata" />.</param> /// <returns></returns> private static object GetQuery(IWpfMetadata bmpMetadata, string query) { try { return bmpMetadata.GetQuery(query); } catch (NotSupportedException) { return null; } catch (System.Runtime.InteropServices.COMException) { return null; } }
/// <summary> /// Gets the longitude GPS data from <paramref name="bmpMetadata" />. /// </summary> /// <param name="bmpMetadata">An object containing the metadata.</param> /// <returns>An instance of <see cref="GpsDistance" />.</returns> private static GpsDistance GetLongitude(IWpfMetadata bmpMetadata) { string direction = GetQuery(bmpMetadata, "System.GPS.LongitudeRef") as string ?? GetQuery(bmpMetadata, @"/app1/ifd/gps/{ushort=3}") as string; double[] longitude = GetQuery(bmpMetadata, "System.GPS.Longitude") as double[] ?? ConvertCoordinate(GetQuery(bmpMetadata, @"/app1/ifd/gps/{ushort=4}") as ulong[]); if (!String.IsNullOrEmpty(direction) && (longitude != null)) { return new GpsDistance(direction, longitude[0], longitude[1], longitude[2]); } else { return null; } }
private static double? GetAltitude(IWpfMetadata bmpMetadata) { object altObj = GetQuery(bmpMetadata, "System.GPS.Altitude"); if (altObj == null) { altObj = GetQuery(bmpMetadata, @"/app1/ifd/gps/{ushort=6}"); if (altObj != null) { altObj = ConvertCoordinate(new[] { (ulong)altObj })[0]; } } if (altObj == null) { return null; } return (IsBelowSeaLevel(bmpMetadata) ? (double)altObj * (-1) : (double)altObj); }
/// <summary> /// Parses the GPS data from the specified <paramref name="bmpMetadata" /> and returns the data in an instance of <see cref="GpsLocation" />. /// </summary> /// <param name="bmpMetadata">An object containing the metadata.</param> /// <returns>An instance of <see cref="GpsLocation" />.</returns> public static GpsLocation Parse(IWpfMetadata bmpMetadata) { GpsLocation gps = new GpsLocation(); gps.Version = GetVersion(bmpMetadata); gps.Latitude = GetLatitude(bmpMetadata); gps.Longitude = GetLongitude(bmpMetadata); gps.Altitude = GetAltitude(bmpMetadata); gps.DestLatitude = GetDestLatitude(bmpMetadata); gps.DestLongitude = GetDestLongitude(bmpMetadata); //// Combine date portion of gpsDate or gpsDate2 with time portion of gpsTime2 //object gpsDate = bmpMetadata.GetQuery("System.GPS.Date"); // System.Runtime.InteropServices.ComTypes.FILETIME //object gpsDate2 = bmpMetadata.GetQuery("/app1/ifd/gps/{ushort=29}"); // 2010:08:08 //DateTime gpsDate3 = Convert((System.Runtime.InteropServices.ComTypes.FILETIME)gpsDate); //ulong[] gpsTime2 = bmpMetadata.GetQuery("/app1/ifd/gps/{ushort=7}") as ulong[]; // ulong[3] //double hh = SplitLongAndDivide(gpsTime2[0]); //double mm = SplitLongAndDivide(gpsTime2[1]); //double ss = SplitLongAndDivide(gpsTime2[2]); //object satellites = bmpMetadata.GetQuery("System.GPS.Satellites"); //"05" //object satellites2 = bmpMetadata.GetQuery("/app1/ifd/gps/{ushort=8}"); //"05" //double longitude = ConvertCoordinate(longitudeArray); return gps; }