Exif Rational[] for GPSLongitude #1295
-
Hello, I'm trying to figure out exactly how the Rational[] works with Latitude/Longitude. I have an image I took with my phone with a Longitude of 78.764446. If I load the image into ImageSharp I get an array that looks like If I save that image back to hard drive it is fine, and using and Exif Viewer the data is correct. When I am trying to set the longitude myself on a different photo I am just creating a new Rational[] { Rational.FromDouble(78.764446) }; This seems to also work when I save it, however I don't follow what happening with the original photo loading with the array and how it has two Whole numbers 78/1 and 45/1 in the array. The FromDouble when I call it looks a lot different. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Those 3 rational numbers represent a geographic location in sexagesimal degree units of degrees, minutes, and seconds If you add this code to your LinqPad output // degrees + (minutes / 60) + (seconds /3600)
(78 + (45 / 60D) + ((52004642 / 1000000D) / 3600D)).Dump(); You get the answer When you use a single rational in your array is it interpreted as a single decimal value. |
Beta Was this translation helpful? Give feedback.
-
@JimBobSquarePants Just my opinion, but I think code snippets like this are so helpful that they'd be great to see in something like a Metadata Cookbook in the Wiki or as a helper method in the package. static double? GetExifLatitude(ImageMetadata metadata)
{
if (metadata.ExifProfile?.TryGetValue(ExifTag.GPSLatitude, out IExifValue<Rational[]>? latitudeParts) == true && latitudeParts?.Value?.Length == 3)
{
uint degrees = latitudeParts.Value[0].Numerator;
double minutes = latitudeParts.Value[1].Numerator / 60D;
double seconds = (latitudeParts.Value[2].Numerator / (double)latitudeParts.Value[2].Denominator) / 3600D;
return degrees + minutes + seconds;
}
return null;
} |
Beta Was this translation helpful? Give feedback.
Those 3 rational numbers represent a geographic location in sexagesimal degree units of degrees, minutes, and seconds
If you add this code to your LinqPad output
You get the answer
78.76444573388889
which matches your input to 6 decimal places.When you use a single rational in your array is it interpreted as a single decimal value.