Giter Club home page Giter Club logo

pytzwhere's Introduction

pytzwhere Build Status Coverage Status

pytzwhere is a Python library to lookup the timezone for a given lat/lng entirely offline.

It is a port from https://github.com/mattbornski/tzwhere with a few improvements. The underlying timezone data is based on work done by Eric Muller

If used as a library, basic usage is as follows:

>>> from tzwhere import tzwhere
>>> tz = tzwhere.tzwhere()
>>> print tz.tzNameAt(35.29, -89.66)
America/Chicago

If you have shapely installed, you can use that library to speed up things by a factor of hundreds. Initialization takes considerably longer (about 20 seconds longer) though. Only really makes sense if you have a lot of points to look up.

>>> tz = tzwhere.tzwhere(shapely=True)
>>> print tz.tzNameAt(35.29, -89.66)
America/Chicago

The polygons used for building the timezones are based on VMAP0. Sometimes points are outside a VMAP0 polygon, but are clearly within a certain timezone (see also this discussion). As a somewhat 'hacky' workaround you can tell the library to return the closest timezone if it doesn't find a proper timezone. Only works if the point is reasonably close to a valid timezone in the first place. This costs you another 80MB of RAM or so. You need to use shapely for this.

>>> tz = tzwhere.tzwhere(shapely=True, forceTZ=True)
>>> # This is on the shore of Lake Michigan
>>> tz.tzNameAt(40.7271, -73.98)
>>> tz.tzNameAt(40.7271, -73.98, forceTZ=True)
'America/New_York'
>>> tz.tzNameAt(50.1536, -5.030)
>>> # This is slightly off the shore of Cornwall
>>> tz.tzNameAt(50.1536, -5.030, forceTZ=True) 
>>> 'Europe/London'
>>> # Far off the coast of Cornwall
>>> tz.tzNameAt(50.26, -9.051, forceTZ=True)

The module can also be run as a script, which offers some other possibilities including producing various input files. Instructions and usage information can be seen by running:

tzwhere.py --help

Dependencies (all optional):

  • docopt - if you want to use tzwhere.py as a script (e.g. as shown above).

  • numpy - if you want to save about 200MB of RAM.

  • shapely - if you want to speed up things by a factor of hundreds

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.