Skip to content

Commit

Permalink
fixes and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pegler committed May 25, 2017
1 parent 3346306 commit 032e779
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 302 deletions.
Binary file removed tzwhere/tz_world_polygons.pck
Binary file not shown.
2 changes: 1 addition & 1 deletion tzwhere/tz_world_shortcuts.json

Large diffs are not rendered by default.

Binary file removed tzwhere/tz_world_shortcuts.pck
Binary file not shown.
34 changes: 18 additions & 16 deletions tzwhere/tzwhere.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ def __init__(self, forceTZ=False):
for tzname, poly in pgen:
self.timezoneNamesToPolygons[tzname].append(poly)
for tzname, polys in self.timezoneNamesToPolygons.items():
self.timezoneNamesToPolygons[tzname] = \
numpy.asarray(polys)
self.timezoneNamesToPolygons[tzname] = numpy.asarray(polys)

if forceTZ:
self.unprepTimezoneNamesToPolygons[tzname] = \
numpy.asarray(polys)
self.unprepTimezoneNamesToPolygons[tzname] = numpy.asarray(polys)

with open(tzwhere.DEFAULT_SHORTCUTS, 'r') as f:
self.timezoneLongitudeShortcuts,\
self.timezoneLatitudeShortcuts = json.load(f)
self.timezoneLongitudeShortcuts, self.timezoneLatitudeShortcuts = json.load(f)

self.forceTZ = forceTZ
for tzname in self.timezoneNamesToPolygons:
Expand All @@ -59,6 +58,7 @@ def __init__(self, forceTZ=False):
for tzname in self.timezoneLatitudeShortcuts[degree].keys():
self.timezoneLatitudeShortcuts[degree][tzname] = \
tuple(self.timezoneLatitudeShortcuts[degree][tzname])

for degree in self.timezoneLongitudeShortcuts.keys():
for tzname in self.timezoneLongitudeShortcuts[degree].keys():
self.timezoneLongitudeShortcuts[degree][tzname] = \
Expand All @@ -80,28 +80,30 @@ def tzNameAt(self, latitude, longitude, forceTZ=False):

latTzOptions = self.timezoneLatitudeShortcuts[str(
(math.floor(latitude / self.SHORTCUT_DEGREES_LATITUDE) *
self.SHORTCUT_DEGREES_LATITUDE))
]
self.SHORTCUT_DEGREES_LATITUDE)
)]
latSet = set(latTzOptions.keys())
lngTzOptions = self.timezoneLongitudeShortcuts[str(
(math.floor(longitude / self.SHORTCUT_DEGREES_LONGITUDE) *
self.SHORTCUT_DEGREES_LONGITUDE))
]
self.SHORTCUT_DEGREES_LONGITUDE)
)]
lngSet = set(lngTzOptions.keys())
possibleTimezones = lngSet.intersection(latSet)

queryPoint = geometry.Point(longitude, latitude)

if possibleTimezones:
for tzname in possibleTimezones:
if isinstance(self.timezoneNamesToPolygons[tzname],
numpy.ndarray):
if isinstance(self.timezoneNamesToPolygons[tzname], numpy.ndarray):
self.timezoneNamesToPolygons[tzname] = list(
map(lambda p: prepared.prep(
geometry.Polygon(p[0], p[1])),
self.timezoneNamesToPolygons[tzname]))
geometry.Polygon(p[0], p[1])
), self.timezoneNamesToPolygons[tzname]))

polyIndices = set(latTzOptions[tzname]).intersection(set(
lngTzOptions[tzname]))
lngTzOptions[tzname]
))

for polyIndex in polyIndices:
poly = self.timezoneNamesToPolygons[tzname][polyIndex]
if poly.contains_properly(queryPoint):
Expand All @@ -122,7 +124,7 @@ def __forceTZ__(self, possibleTimezones, latTzOptions,
if isinstance(self.unprepTimezoneNamesToPolygons[tzname],
numpy.ndarray):
self.unprepTimezoneNamesToPolygons[tzname] = list(
map(lambda p: geometry.Polygon(p[0], p[1]),
map(lambda p: p.context if isinstance(p, prepared.PreparedGeometry) else geometry.Polygon(p[0], p[1]),
self.timezoneNamesToPolygons[tzname]))
polyIndices = set(latTzOptions[tzname]).intersection(
set(lngTzOptions[tzname]))
Expand Down
285 changes: 0 additions & 285 deletions tzwhere/tzwhere.py~

This file was deleted.

0 comments on commit 032e779

Please sign in to comment.