Skip to content

Commit

Permalink
GEORef: Fix changed field name in TRIG log message
Browse files Browse the repository at this point in the history
  • Loading branch information
EosBandi committed Nov 27, 2024
1 parent fdcbb09 commit e619003
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions ExtLibs/Utilities/GeoRefImageBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected DateTime getPhotoTime(string fn)
Image myImage = Image.FromFile(fn);
PropertyItem propItem = myImage.GetPropertyItem(36867); // 36867 // 306
//Convert date taken metadata to a DateTime object
//Convert date taken metadata to a DateTime object
string sdate = Encoding.UTF8.GetString(propItem.Value).Trim();
string secondhalf = sdate.Substring(sdate.IndexOf(" "), (sdate.Length - sdate.IndexOf(" ")));
string firsthalf = sdate.Substring(0, 10);
Expand Down Expand Up @@ -435,9 +435,12 @@ public Dictionary<long, VehicleLocation> readTRIGMsgInLog(string fn)
int raltindex = sr.dflog.FindMessageOffset("TRIG", "RelAlt");
int galtindex = sr.dflog.FindMessageOffset("TRIG", "GPSAlt");

int rindex = sr.dflog.FindMessageOffset("TRIG", "Roll");
int pindex = sr.dflog.FindMessageOffset("TRIG", "Pitch");
int yindex = sr.dflog.FindMessageOffset("TRIG", "Yaw");
int rindex = sr.dflog.FindMessageOffset("TRIG", "R");
if (rindex == -1) { rindex = sr.dflog.FindMessageOffset("TRIG", "Roll"); }
int pindex = sr.dflog.FindMessageOffset("TRIG", "P");
if (pindex == -1) { pindex = sr.dflog.FindMessageOffset("TRIG", "Pitch"); }
int yindex = sr.dflog.FindMessageOffset("TRIG", "Y");
if (yindex == -1) { yindex = sr.dflog.FindMessageOffset("TRIG", "Yaw"); }

int gtimeindex = sr.dflog.FindMessageOffset("TRIG", "GPSTime");
int gweekindex = sr.dflog.FindMessageOffset("TRIG", "GPSWeek");
Expand Down Expand Up @@ -507,7 +510,7 @@ public double EstimateOffset(string logFile, string dirWithImages, string UseGps
{
camLocations = readCAMMsgInLog(logFile);
if (usecam)
{
{
vehicleLocations = camLocations;
}
else
Expand Down Expand Up @@ -610,7 +613,7 @@ private VehicleLocation LookForLocation(DateTime t, Dictionary<long, VehicleLoca

public Dictionary<string, PictureInformation> doworkGPSOFFSET(string logFile, string dirWithImages, float offset, string UseGpsorGPS2, bool usecam, Action<string> AppendText)
{
// Lets start over
// Lets start over
Dictionary<string, PictureInformation> picturesInformationTemp =
new Dictionary<string, PictureInformation>();

Expand Down Expand Up @@ -735,7 +738,7 @@ private int compareFileByPhotoTime(string x, string y)

public Dictionary<string, PictureInformation> doworkCAM(string logFile, string dirWithImages, string UseGpsorGPS2, Action<string> AppendText, int dropstart, int dropend)
{
// Lets start over
// Lets start over
Dictionary<string, PictureInformation> picturesInformationTemp =
new Dictionary<string, PictureInformation>();

Expand Down Expand Up @@ -770,7 +773,7 @@ public Dictionary<string, PictureInformation> doworkCAM(string logFile, string d
AppendText("Log file problem. No CAM messages. Aborting....\n");
return null;
}

AppendText("Log Read with - " + camLocations.Count + " - CAM Messages found\n");

camLocations = camLocations.Take(camLocations.Count - dropend).Skip(dropstart).ToDictionary(a => a.Key, a => a.Value);
Expand All @@ -779,7 +782,7 @@ public Dictionary<string, PictureInformation> doworkCAM(string logFile, string d
.PrevNowNext(InvalidValue: new KeyValuePair<long, VehicleLocation>(0,
new VehicleLocation() { Time = DateTime.MinValue }))
.Select(d => ((d.Item3.Value.Time - d.Item2.Value.Time), d.Item2)).ToList();

// Find and remove all CAM messages with shutter speed less than minshutter
foreach (var delta in deltalistv.Where(a => a.Item1.TotalSeconds > 0 && a.Item1.TotalSeconds < minshutter))
{
Expand Down Expand Up @@ -820,7 +823,7 @@ public Dictionary<string, PictureInformation> doworkCAM(string logFile, string d

if(files.Count <= i)
continue;


// Fill shot time in Picture
p.ShotTimeReportedByCamera = getPhotoTime(files[i]);
Expand Down Expand Up @@ -964,7 +967,7 @@ public Dictionary<string, PictureInformation> doworkCAM(string logFile, string d

public Dictionary<string, PictureInformation> doworkTRIG(string logFile, string dirWithImages, string UseGpsorGPS2, Action<string> AppendText, int dropstart, int dropend)
{
// Lets start over
// Lets start over
Dictionary<string, PictureInformation> picturesInformationTemp =
new Dictionary<string, PictureInformation>();

Expand Down Expand Up @@ -1062,7 +1065,7 @@ public static double degrees(double val)

private void newpos(ref double lat, ref double lon, double bearing, double distance)
{
// '''extrapolate latitude/longitude given a heading and distance
// '''extrapolate latitude/longitude given a heading and distance
// thanks to http://www.movable-type.co.uk/scripts/latlong.html
// '''
// from math import sin, asin, cos, atan2, radians, degrees
Expand Down Expand Up @@ -1135,7 +1138,7 @@ 21 00 00 00 01 00 00 00--> 33/1
18 00 00 00 01 00 00 00--> 24/1
06 02 00 00 0A 00 00 00--> 518/10
*/

Array.Copy(BitConverter.GetBytes((uint) d), 0, output, 0, sizeof (uint));
Array.Copy(BitConverter.GetBytes((uint) 1), 0, output, 4, sizeof (uint));
Array.Copy(BitConverter.GetBytes((uint) m), 0, output, 8, sizeof (uint));
Expand Down Expand Up @@ -1188,13 +1191,13 @@ public void WriteCoordinatesToImage(string Filename, double dLat, double dLong,

if (item.Tag == ExifTag.GPSLongitude || item.Tag == ExifTag.GPSLatitude ||
item.Tag == ExifTag.GPSAltitude || item.Tag == ExifTag.GPSLatitudeRef ||
item.Tag == ExifTag.GPSLongitudeRef || item.Tag == ExifTag.MakerNote ||
item.Tag == ExifTag.GPSLongitudeRef || item.Tag == ExifTag.MakerNote ||
item.Tag == ExifTag.ThumbnailYResolution || item.Tag == ExifTag.ThumbnailXResolution ||
item.Tag == ExifTag.FlashpixVersion || item.Tag == ExifTag.ThumbnailXResolution)
data.Properties.Remove(item);

}


var lon = dLong.toDMS();
data.Properties.Add(ExifTag.GPSLongitude, Math.Abs(lon.degrees), Math.Abs(lon.minutes), Math.Abs(lon.seconds));
Expand All @@ -1205,7 +1208,7 @@ public void WriteCoordinatesToImage(string Filename, double dLat, double dLong,

data.Properties.Add(ExifTag.GPSLatitudeRef, dLat < 0 ? "S" : "N");
data.Properties.Add(ExifTag.GPSLongitudeRef, dLong < 0 ? "W" : "E");

// Save file into Geotag folder
string geoTagFolder = rootFolder + Path.DirectorySeparatorChar + "geotagged";

Expand All @@ -1218,7 +1221,7 @@ public void WriteCoordinatesToImage(string Filename, double dLat, double dLong,
File.Delete(outputfilename);

data.Save(outputfilename);

}
catch
{
Expand Down Expand Up @@ -1468,7 +1471,7 @@ public void CreateReportFiles(Dictionary<string, PictureInformation> listPhotosW
/* using (StreamWriter swjpw = new StreamWriter(dirWithImages + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(filename) + ".jgw"))
{
swjpw.WriteLine((rect.Height / 2448.0).ToString("0.00000000000000000"));
swjpw.WriteLine((0).ToString("0.00000000000000000")); //
swjpw.WriteLine((0).ToString("0.00000000000000000")); //
swjpw.WriteLine((0).ToString("0.00000000000000000")); //
swjpw.WriteLine((rect.Width / -3264.0).ToString("0.00000000000000000")); // distance per pixel
swjpw.WriteLine((rect.Left).ToString("0.00000000000000000"));
Expand Down

0 comments on commit e619003

Please sign in to comment.