Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

forceTZ returning unexpected result #37

Open
josiekre opened this issue Jun 14, 2016 · 5 comments
Open

forceTZ returning unexpected result #37

josiekre opened this issue Jun 14, 2016 · 5 comments

Comments

@josiekre
Copy link

I've been using forceTZ=True to deal with coastal points. Thanks for adding this feature. Seems to be working well except for these rare points in Vancouver.

>>> from tzwhere import tzwhere
>>> tz = tzwhere.tzwhere(shapely=True, forceTZ=True)
2016-06-14 23:34:20,283 tzwhere.py _read_polygons_from_csv 288 INFO  Reading from CSV input file: /home/ec2-user/.local/lib/python2.7/site-packages/tzwhere/tz_world.csv

>>> tz.tzNameAt(49.2698, -123.1302)
>>> tz.tzNameAt(49.2698, -123.1302, forceTZ=True)
'America/Los_Angeles'

It should return 'America/Vancouver' as that's the closest polygon by far. Am I missing something?

@jannikmi
Copy link

I really don't want to hijack this post, but since no one answered yet, here is my explanation:

Like in other older issues (e.g. mattbornski/tzwhere#8), probably the timezone data used by this package is slightly off at this exact point (bay areas seem to be prone to errors). The description of this package also describes the forceTZ option as "[...] a somewhat 'hacky' workaround [...]". I actually don't know why the algorithm would return 'America/Los_Angeles' however.

What I think you are actually looking for is a real proximity algorithm. You should consider using my packages option closest_timezone_at(...): https://github.com/MrMinimal64/timezonefinder
See the documentation for more options on this.

Hope I could help. Greetings

@cstich
Copy link
Contributor

cstich commented Jun 17, 2016

I am not completely sure why it doesn't return the correct timezone either. I'll have a look into it.

@josiekre
Copy link
Author

@MrMinimal64: Thanks for sharing timezonefinder. What's the difference between tf.timezone_at(*point) and closest_timezone_at()? It's not entirely clear via the description.

@cstich: Happy to help debugging or testing. I haven't had a chance to dig into the algorithm you're using for forceTZ option yet which is why I thought I see if you quickly knew why it was doing this before investing a bunch of time.

@jannikmi
Copy link

Hm, that's not good... timezone_at() is the normal function for checking timezones (like tz_NameAt) with just a few optimizations. closest_timezone_at() is a real proximity algorithm (searching for the closest timezone, like the name suggests).

@famanson
Copy link
Contributor

Sorry to barge in after a year, but the reason that forceTz is acting weirdly is because of the distances being sorted using the wrong key

I've submitted a PR here #40, using @josiekre's exact example as test data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants