Acabo de enfrentar el mismo problema hoy, y no estoy seguro de cuán relevante es mi respuesta después de todo este tiempo, pero básicamente escribí una función de Python que hace lo que quiere. Lo puedes encontrar aquí.
https://github.com/cstich/gpstotz
Editar:
Como se ha mencionado en los comentarios También debo Código postal. El código se basa en el shapefile de zonas horarias de Eric Muller, que puede obtener aquí: http://efele.net/maps/tz/world/.
Edición 2:
Como resulta que tienen una definición archivos de forma un tanto arcaica de los anillos exteriores e interiores (básicamente anillos exteriores están usando la regla de la mano derecha, mientras que los anillos interiores están usando la regla de la mano izquierda). En cualquier caso, fiona parece ocuparse de eso y actualicé el código en consecuencia.
from rtree import index # requires libspatialindex-c3.deb
from shapely.geometry import Polygon
from shapely.geometry import Point
import os
import fiona
''' Read the world timezone shapefile '''
tzshpFN = os.path.join(os.path.dirname(__file__),
'resources/world/tz_world.shp')
''' Build the geo-index '''
idx = index.Index()
with fiona.open(tzshpFN) as shapes:
for i, shape in enumerate(shapes):
assert shape['geometry']['type'] == 'Polygon'
exterior = shape['geometry']['coordinates'][0]
interior = shape['geometry']['coordinates'][1:]
record = shape['properties']['TZID']
poly = Polygon(exterior, interior)
idx.insert(i, poly.bounds, obj=(i, record, poly))
def gpsToTimezone(lat, lon):
'''
For a pair of lat, lon coordiantes returns the appropriate timezone info.
If a point is on a timezone boundary, then this point is not within the
timezone as it is on the boundary. Does not deal with maritime points.
For a discussion of those see here:
http://efele.net/maps/tz/world/
@lat: latitude
@lon: longitude
@return: Timezone info string
'''
query = [n.object for n in idx.intersection((lon, lat, lon, lat),
objects=True)]
queryPoint = Point(lon, lat)
result = [q[1] for q in query
if q[2].contains(queryPoint)]
if len(result) > 0:
return result[0]
else:
return None
if __name__ == "__main__":
''' Tests '''
assert gpsToTimezone(0, 0) is None # In the ocean somewhere
assert gpsToTimezone(51.50, 0.12) == 'Europe/London'
Bueno, se trata de una API remota, pero échale un vistazo a la respuesta a esta pregunta. Puede darle lo que desea: http://stackoverflow.com/questions/41504/timezone-lookup-from-latitude-longitude. –