zverok / wheretz

Fast and precise time zone by geo coordinates lookup
MIT License
99 stars 12 forks source link

WhereTZ: fast and precise timezone lookup

WhereTZ is a small gem for lookup of timezone by georgraphic coordinates.

Features:

Usage

Install it with your usual routines (Gemfile or gem install) as wheretz gem. Then:

require 'wheretz'

WhereTZ.lookup(50.004444, 36.231389) # (lat, lng) order
# => 'Europe/Kiev'

WhereTZ.get(50.004444, 36.231389)
# => #<TZInfo::DataTimezone: Europe/Kiev>

# you should have tzinfo gem installed, wheretz doesn't list it as dependency

From command-line, after gem installed:

wheretz 50.004444,36.231389
# => Europe/Kiev

How it works

  1. Latest version of timezone-boundary-builder dataset is converted into ~400 data/*.geojson files;
  2. Each of those files corresponds to one timezone; filename contains timezone name and bounding box (min and max latitude and longitude);
  3. On each lookup WhereTZ first checks provided coordinates by bounding boxes, and if only one bbox (extracted from filename) corresponds to them, returns timezone name immediately;
  4. If there's several intersecting bounding boxes, WhereTZ reads only relevant timezone files (which are not very large) and checks which polygon actually contains the point.

Known problems

Author

Victor Shepelev

License

Data license is ODbL.

Code license is usual MIT.