मुझे आज भी एक ही समस्या का सामना करना पड़ा, और मुझे यकीन नहीं है कि इस समय के बाद मेरा जवाब कितना प्रासंगिक है, लेकिन मूल रूप से मैंने केवल एक पायथन समारोह लिखा जो आप चाहते हैं। आप इसे यहां देख सकते हैं।
https://github.com/cstich/gpstotz
संपादित करें:
टिप्पणी मैं भी कोड पोस्ट करना चाहिए में उल्लेख किया है। कोड एरिक मुलर के टाइमज़ोन के आकारफाइल पर आधारित है, जिसे आप यहां प्राप्त कर सकते हैं - http://efele.net/maps/tz/world/।
संपादित करें 2:
यह शेपफ़ाइलें पता चला है के रूप में (मूल रूप से बाहरी छल्ले, दाएँ हाथ के नियम का उपयोग कर रहे हैं, जबकि आंतरिक छल्ले बाएँ हाथ के नियम का उपयोग कर रहे हैं) बाहरी और आंतरिक के छल्ले के कुछ पुरातन परिभाषा नहीं है। किसी भी मामले में फियोना का ख्याल रखना प्रतीत होता है और मैंने तदनुसार कोड अपडेट किया।
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'
ठीक है, इसमें एक दूरस्थ API शामिल है, लेकिन इस प्रश्न का उत्तर देखें। यह आपको वही दे सकता है जो आप चाहते हैं: http://stackoverflow.com/questions/41504/timezone-lookup-from-latitude- longitude। –