views:

54

answers:

2

I'm writing a geotagging app and running into headaches with timezones. Basically, my app has the following data:

  • Images with local timestamps (i.e. relative to a timezone)
  • GPS track files consisting of entries using UTC timestamps

My problem: I need a way to get all data that belongs to a give day, based on the timezone where the data was acquired. For the images, that is easy (I ask the timezone from the user upon import and save it in the EXIF data), but I'm not sure how to do it for the GPS tracks (there usually are multiple tracks per day, and assigning them timezones is not easy for the user when importing data that spans sever days and timezones). I can think of two possible solutions:

  • Use a heuristic based on the fact that the tracks are recorded at the same time and place as the images - but there can be tracks before a day's first image or after its last one that still need to be included - I'm not sure how to realiably handle such edge cases
  • Determine the timezone from the GPS coordinates - this would be an ideal solution, but is there an open source library that does this (ideally one that works offline)?
+1  A: 

Option two: you could start by checking this site: http://www.twinsun.com/tz/tz-link.htm

Option one (less complicated, but I am not sure I accurately understand your need...) So you have as input:

  • A target day defined in a known timezone TZ, starting at t0 and ending at t1 (excluded)
  • Images with timestamps ti in the same timezone TZ (is this hypothesis true?)
  • GPS tracks with UTC timestamps tg which can span over several time zones We also know that there is at least one GPS track for each image.

Here's something that should work:

  • Convert your target day into UTC. You get the values t0/UTC and t1/UTC
  • Convert images' timestamps into UTC (you get ti/UTC from known ti/TZ)
  • process image if (t0/UTC <= ti/UTC < t1/UTC) i.e. it was taken during your target day.
  • find a GPS track including ti/UTC (no problem since tracks are timestamped in UTC), and then the closest timestamp within the list of points in this track. This point is the most likely position of your image.
Stéphane
My problem is not geotagging the images - I can do that easily (normalizing all dates to UTC and performing a binary search on the sorted list of all waypoints). My problem is that I want to find which target day each GPS track belongs to. The point is to divide the data into the days as experienced by a traveller.
Michael Borgwardt
Therefore, days (and the images and GPS tracks which belong to them) can span several timezones, though I'm much more concerned with the common case of having one and sometimes two timezones. The whole concept of "days" breaks down with flights that cross multiple timezones - that's why we experience jet lag, after all. I don't expect to be able to cover all edge cases consistently in those cases.
Michael Borgwardt
+1  A: 

The heuristic method I don't think will work well.

Firstly always store times as UTC and timezone of origin, otherwise time is less meaningful.

After some thought I think that it would be sufficient to resolve down to the country code and from that lookup the timezone.

Depending on how much detail you want I think GeoTog may help you to locate a city and therefore a country from a lat/long (although it will need changing to work the other way).

If not that then Gisgraphy will work with the larger GeoNames database. You could use the web service or extract the data.

If none of these are good enough then I think you'll need to get a some GIS data, possibly boundaries from VMAP0 and process it into polygons or something searchable.

Richard Harrison
Finally got around to dealing with this again: the geonames DB is the ideal solution, providing a DB of cities, each with coordinates and time zone - so all I have to do is a nearest neighbour search. Just determining the country would have been insufficient, as some countries span multiple time zones.
Michael Borgwardt