Beispiel #1
0
        public virtual GeoLocation GetGeoLocation()
        {
            Rational[] latitudes    = GetRationalArray(Com.Drew.Metadata.Exif.GpsDirectory.TagLatitude);
            Rational[] longitudes   = GetRationalArray(Com.Drew.Metadata.Exif.GpsDirectory.TagLongitude);
            string     latitudeRef  = GetString(Com.Drew.Metadata.Exif.GpsDirectory.TagLatitudeRef);
            string     longitudeRef = GetString(Com.Drew.Metadata.Exif.GpsDirectory.TagLongitudeRef);

            // Make sure we have the required values
            if (latitudes == null || latitudes.Length != 3)
            {
                return(null);
            }
            if (longitudes == null || longitudes.Length != 3)
            {
                return(null);
            }
            if (latitudeRef == null || longitudeRef == null)
            {
                return(null);
            }
            double?lat = GeoLocation.DegreesMinutesSecondsToDecimal(latitudes[0], latitudes[1], latitudes[2], Sharpen.Runtime.EqualsIgnoreCase(latitudeRef, "S"));
            double?lon = GeoLocation.DegreesMinutesSecondsToDecimal(longitudes[0], longitudes[1], longitudes[2], Sharpen.Runtime.EqualsIgnoreCase(longitudeRef, "W"));

            // This can return null, in cases where the conversion was not possible
            if (lat == null || lon == null)
            {
                return(null);
            }
            return(new GeoLocation((double)lat, (double)lon));
        }
Beispiel #2
0
        /// <summary>
        /// Parses various tags in an attempt to obtain a single object representing the latitude and longitude
        /// at which this image was captured.
        /// </summary>
        /// <returns>The geographical location of this image, if possible, otherwise <c>null</c>.</returns>
        public GeoLocation?GetGeoLocation()
        {
            var latitudes    = this.GetRationalArray(TagLatitude);
            var longitudes   = this.GetRationalArray(TagLongitude);
            var latitudeRef  = this.GetString(TagLatitudeRef);
            var longitudeRef = this.GetString(TagLongitudeRef);

            // Make sure we have the required values
            if (latitudes == null || latitudes.Length != 3)
            {
                return(null);
            }
            if (longitudes == null || longitudes.Length != 3)
            {
                return(null);
            }
            if (latitudeRef == null || longitudeRef == null)
            {
                return(null);
            }

            var lat = GeoLocation.DegreesMinutesSecondsToDecimal(latitudes[0], latitudes[1], latitudes[2], latitudeRef.Equals("S", StringComparison.OrdinalIgnoreCase));
            var lon = GeoLocation.DegreesMinutesSecondsToDecimal(longitudes[0], longitudes[1], longitudes[2], longitudeRef.Equals("W", StringComparison.OrdinalIgnoreCase));

            // This can return null, in cases where the conversion was not possible
            if (lat == null || lon == null)
            {
                return(null);
            }

            return(new GeoLocation((double)lat, (double)lon));
        }
        public string?GetGpsDestLongitudeDescription()
        {
            var longitudes   = Directory.GetRationalArray(GpsDirectory.TagDestLongitude);
            var longitudeRef = Directory.GetString(GpsDirectory.TagDestLongitudeRef);

            if (longitudes == null || longitudes.Length != 3 || longitudeRef == null)
            {
                return(null);
            }

            var lon = GeoLocation.DegreesMinutesSecondsToDecimal(
                longitudes[0], longitudes[1], longitudes[2], longitudeRef.Equals("S", StringComparison.OrdinalIgnoreCase));

            return(lon == null ? null : GeoLocation.DecimalToDegreesMinutesSecondsString((double)lon));
        }