private void parametersChanged() { string text; if (m_wpt != null) { this.Text = "Photo: " + m_wpt.Desc; text = m_wpt.toStringPopup(); } else if (m_photoDescr != null) { this.Text = "Photo: " + m_photoDescr.imageName; text = "" + m_photoDescr.imageName + "\n\n" + m_photoDescr.imageSource; if (m_photoDescr.DTOrig.CompareTo(new DateTime(1, 1, 1, 0, 0, 0)) > 0) { text += "\n\n" + m_photoDescr.DTOrig + " (local before shift) " + m_photoDescr.Width + " x " + m_photoDescr.Height; TimeSpan photoTimeShift = Project.photoTimeShiftCurrent; TimeSpan timeZoneSpan = MyTimeZone.timeSpanById(Project.photoTimeZoneIdCurrent); DateTime timeStamp = m_photoDescr.DTOrig + photoTimeShift + MyTimeZone.zoneTimeShift - timeZoneSpan; text += "\n" + timeStamp + " (local after shift - must match a trackpoint)"; } else { text += "\n\n[no time stamp] " + m_photoDescr.Width + " x " + m_photoDescr.Height; } text += "\n\n[this photo is not related to any trackpoint]"; } else { text = "no image or waypoint"; this.Text = "Photo Preview"; } infoLabel.Text = text; drawLinkLabel.Enabled = (m_photoDescr != null); }
/// <summary> /// Uses the system time to get the timezone set on the system. /// </summary> /// <returns>Return "MyTimeZone" variable, with strings for: utc offset, timezone.</returns> public static MyTimeZone GetMyTimeZone() { var timezone = new MyTimeZone(); var thisis = System.TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now); var time = DateTime.Now; bool isDayLight = TimeZoneInfo.Local.IsDaylightSavingTime(time); int houroffset = thisis.Hours; int minutesoffset = thisis.Minutes; int timeoffset = 0; if (isDayLight) { houroffset = houroffset - 1; } timezone.utc_offset = houroffset.ToString() + ":" + minutesoffset.ToString() + ":00"; //set the time for Zones with half hours in it, itll add the minutes to the hours //exp: 5:30 = 35, 30 minutes plus 5 <-- hours if (minutesoffset != 0) { timeoffset = int.Parse(houroffset.ToString()) + int.Parse(minutesoffset.ToString()); } else { timeoffset = houroffset; } string timeZone = ""; #region switch case to get name of the timezone switch (timeoffset) { case (0): timeZone = "Zulu"; break; case (1): timeZone = "Central European"; break; case (2): timeZone = "Eastern European"; break; case (3): timeZone = "Baghdad"; break; case (33): //3:30 timeZone = "Tehran"; break; case (4): timeZone = "Moscow"; break; case (34): // 4:30 timeZone = "Kabul"; break; case (5): timeZone = "Karachi"; break; case (35): //5:30 timeZone = "New Delhi"; break; case (50): //5:45 timeZone = "Kathmandu"; break; case (6): timeZone = "Astana"; break; case (36): //6:30 timeZone = "Yangon"; break; case (7): timeZone = "Novasibirsk"; break; case (8): timeZone = "China Coast"; break; case (9): timeZone = "Japan Standard"; break; case (39): //9:30 timeZone = "Darwin"; break; case (10): timeZone = "Guam Standard"; break; case (11): timeZone = "Vladivostok"; break; case (12): timeZone = "New Zealand Standard"; break; case (13): timeZone = "Samoa"; break; case (-1): timeZone = "West Africa"; break; case (-2): timeZone = "Azores"; break; case (-3): timeZone = "Greenland"; break; case (-33): //-3:30 timeZone = "Newfoundland"; break; case (-4): timeZone = "Atlantic Standard"; break; case (-34): //-4:30 timeZone = "Caracas"; break; case (-5): timeZone = "Eastern Standard Time"; break; case (-6): timeZone = "Central Standard"; break; case (-7): timeZone = "Mountain Standard"; break; case (-8): timeZone = "Pacific Standard"; break; case (-9): timeZone = "Yukon Standard"; break; case (-10): timeZone = "Alaska-Hawaii Standard"; break; case (-11): timeZone = "Coordinated Universal Time-11"; break; case (-12): timeZone = "International Date Line West"; break; default: timeZone = "Unable to get Time Zone"; break; } #endregion timezone.time_zone = timeZone; return(timezone); }
/// <summary> /// Uses the system time to get the timezone set on the system. /// </summary> /// <returns>Return "MyTimeZone" variable, with strings for: utc offset, timezone.</returns> public static MyTimeZone GetMyTimeZone() { var timezone = new MyTimeZone(); var thisis = System.TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now); var time = DateTime.Now; bool isDayLight = TimeZoneInfo.Local.IsDaylightSavingTime(time); int houroffset = thisis.Hours; int minutesoffset = thisis.Minutes; int timeoffset = 0; if (isDayLight) houroffset = houroffset - 1; timezone.utc_offset = houroffset.ToString() + ":" + minutesoffset.ToString() + ":00"; //set the time for Zones with half hours in it, itll add the minutes to the hours //exp: 5:30 = 35, 30 minutes plus 5 <-- hours if (minutesoffset != 0) timeoffset = int.Parse(houroffset.ToString()) + int.Parse(minutesoffset.ToString()); else timeoffset = houroffset; string timeZone = ""; #region switch case to get name of the timezone switch (timeoffset) { case (0): timeZone = "Zulu"; break; case (1): timeZone = "Central European"; break; case (2): timeZone = "Eastern European"; break; case (3): timeZone = "Baghdad"; break; case (33)://3:30 timeZone = "Tehran"; break; case (4): timeZone = "Moscow"; break; case (34):// 4:30 timeZone = "Kabul"; break; case (5): timeZone = "Karachi"; break; case (35)://5:30 timeZone = "New Delhi"; break; case (50)://5:45 timeZone = "Kathmandu"; break; case (6): timeZone = "Astana"; break; case (36)://6:30 timeZone = "Yangon"; break; case (7): timeZone = "Novasibirsk"; break; case (8): timeZone = "China Coast"; break; case (9): timeZone = "Japan Standard"; break; case (39)://9:30 timeZone = "Darwin"; break; case (10): timeZone = "Guam Standard"; break; case (11): timeZone = "Vladivostok"; break; case (12): timeZone = "New Zealand Standard"; break; case (13): timeZone = "Samoa"; break; case (-1): timeZone = "West Africa"; break; case (-2): timeZone = "Azores"; break; case (-3): timeZone = "Greenland"; break; case (-33)://-3:30 timeZone = "Newfoundland"; break; case (-4): timeZone = "Atlantic Standard"; break; case (-34)://-4:30 timeZone = "Caracas"; break; case (-5): timeZone = "Eastern Standard Time"; break; case (-6): timeZone = "Central Standard"; break; case (-7): timeZone = "Mountain Standard"; break; case (-8): timeZone = "Pacific Standard"; break; case (-9): timeZone = "Yukon Standard"; break; case (-10): timeZone = "Alaska-Hawaii Standard"; break; case (-11): timeZone = "Coordinated Universal Time-11"; break; case (-12): timeZone = "International Date Line West"; break; default: timeZone = "Unable to get Time Zone"; break; } #endregion timezone.time_zone = timeZone; return timezone; }
public static Waypoint createPhotoTrackpoint(PhotoDescr photoDescr, TimeSpan photoTimeShift, int tzId) { if (photoDescr.hasCoordinates) { // There is EXIF coordinates set, use it. GeoCoord loc = new GeoCoord(photoDescr.Longitude, photoDescr.Latitude, photoDescr.Altitude); string name = photoDescr.imageName; string source = photoDescr.imageSource; string url = photoDescr.imageUrl; Waypoint wpt0 = new Waypoint(loc, Project.localToZulu(photoDescr.DTOrig), LiveObjectTypes.LiveObjectTypeWaypoint, -1, name, source, url); wpt0.Desc = photoDescr.imageName; wpt0.ThumbImage = photoDescr.ThumbnailImage; wpt0.ThumbSource = photoDescr.imageThumbSource; wpt0.ThumbPosition = Project.thumbPosition; wpt0.imageWidth = photoDescr.Width; wpt0.imageHeight = photoDescr.Height; wpt0.PhotoTimeShift = new TimeSpan(0L); // we need to shift the timestamp a bit if the spot is taken: while (WaypointsWithThumbs.ContainsKey(wpt0.DateTime)) { DateTime tmp = wpt0.DateTime; wpt0.DateTime = tmp.AddMilliseconds(1); } // make sure the new waypoint is accounted for in the cache: WaypointsWithThumbs.Add(wpt0.DateTime, wpt0); CurrentWptIndex = WaypointsWithThumbs.Count - 1; WaypointsCache.addWaypoint(wpt0); return(wpt0); } if (photoDescr.DTOrig.Equals(DateTime.MinValue)) { // try to get it from file name: photoDescr.ensureImageExists(); Waypoint wpt0 = WaypointsCache.getWaypointByName(photoDescr.imageName); if (wpt0 != null) { //wpt0.Desc = photoDescr.imageName; wpt0.ThumbImage = photoDescr.ThumbnailImage; wpt0.ThumbSource = photoDescr.imageThumbSource; wpt0.ThumbPosition = Project.thumbPosition; wpt0.imageWidth = photoDescr.Width; wpt0.imageHeight = photoDescr.Height; wpt0.PhotoTimeShift = new TimeSpan(0L); // we need to shift the timestamp a bit if the spot is taken: while (WaypointsWithThumbs.ContainsKey(wpt0.DateTime)) { DateTime tmp = wpt0.DateTime; wpt0.DateTime = tmp.AddMilliseconds(1); } // make sure the new waypoint is accounted for in the cache: WaypointsWithThumbs.Add(wpt0.DateTime, wpt0); CurrentWptIndex = WaypointsWithThumbs.Count - 1; return(wpt0); } else { registerUnrelatedPhoto(photoDescr); } return(null); } TimeSpan timeZoneSpan = MyTimeZone.timeSpanById(tzId); DateTime timeStamp = Project.localToZulu(photoDescr.DTOrig + photoTimeShift + MyTimeZone.zoneTimeShift - timeZoneSpan); //LibSys.StatusBar.Trace("adjusted zulu time=" + timeStamp); registerImageTimestamp(timeStamp); if (photoDescr.imageSourceIsLocal && photoDescr.image == null) { // try to get it from file name: photoDescr.ensureImageExists(); registerUnrelatedPhoto(photoDescr); return(null); } Waypoint wpt = null; Waypoint wpt1; Waypoint wpt2; // wpt2 is hit if exact match on the timestamp; wpt1 may turn null, but not wpt2. if (WaypointsCache.trackpointByTime(timeStamp, out wpt1, out wpt2)) { // create duplicate waypoint and add it to the same track - to hold the image wpt = new Waypoint(wpt2); if (wpt1 == null) { // exact match on wpt2 } else { // somewhere between wpt1 and wpt2 double dt = (wpt2.DateTime - wpt1.DateTime).Ticks; double dt1 = (timeStamp - wpt1.DateTime).Ticks; if (dt > 0) { double ratio = dt1 / dt; wpt.Location.Lat = wpt1.Location.Lat + (wpt2.Location.Lat - wpt1.Location.Lat) * ratio; wpt.Location.Lng = wpt1.Location.Lng + (wpt2.Location.Lng - wpt1.Location.Lng) * ratio; } } wpt.DateTime = timeStamp; wpt.Desc = photoDescr.imageName; Track trk = WaypointsCache.getTrackById(wpt.TrackId); // we need to shift the timestamp a bit if the spot is taken: while (WaypointsWithThumbs.ContainsKey(wpt.DateTime) || trk.Trackpoints.ContainsKey(wpt.DateTime)) { DateTime tmp = wpt.DateTime; wpt.DateTime = tmp.AddMilliseconds(1); } trk.insertWaypoint(wpt); wpt.ThumbImage = photoDescr.ThumbnailImage; wpt.ThumbSource = photoDescr.imageThumbSource; wpt.ThumbPosition = Project.thumbPosition; wpt.imageWidth = photoDescr.Width; wpt.imageHeight = photoDescr.Height; wpt.PhotoTimeShift = photoTimeShift; // make sure the new waypoint is accounted for in the cache: WaypointsWithThumbs.Add(wpt.DateTime, wpt); CurrentWptIndex = WaypointsWithThumbs.Count - 1; } else { registerUnrelatedPhoto(photoDescr); } return(wpt); }