All Projects → RomanIakovlev → timeshape

RomanIakovlev / timeshape

Licence: MIT license
Java library to find timezone based on geo coordinates

Programming Languages

java
68154 projects - #9 most used programming language
scala
5932 projects
shell
77523 projects

Projects that are alternatives of or similar to timeshape

Timezone Boundary Builder
A tool to extract data from Open Street Map (OSM) to build the boundaries of the world's timezones.
Stars: ✭ 469 (+304.31%)
Mutual labels:  openstreetmap, timezone
temps-lite
A smart, good-looking little app which tries to speak your language the way you are used to.
Stars: ✭ 40 (-65.52%)
Mutual labels:  timezone
mapsplit
A fast way to split OSM data in to a portable tiled format
Stars: ✭ 55 (-52.59%)
Mutual labels:  openstreetmap
openstreetmap-americana
A quintessentially American map style
Stars: ✭ 89 (-23.28%)
Mutual labels:  openstreetmap
3D-Public-Transport-Simulator
The 3D Public Transport Simulator is a Unity-based simulation, which uses OpenStreetMap data in order to support the simulation of worldwide locations. The development was part of a Bachelor thesis.
Stars: ✭ 87 (-25%)
Mutual labels:  openstreetmap
geoguessrnim
GeoGuessr browser plugin, hide Ads, Filters for StreetView and Mapillary for Chromium and Firefox
Stars: ✭ 17 (-85.34%)
Mutual labels:  openstreetmap
osmot
Preprocessor for make public transit maps from Openstreetmap data
Stars: ✭ 14 (-87.93%)
Mutual labels:  openstreetmap
osmdata
Scripts for creating OSM data derived data sets
Stars: ✭ 20 (-82.76%)
Mutual labels:  openstreetmap
OpenNameSearch
Script for Building a Basic Nominatim Server
Stars: ✭ 14 (-87.93%)
Mutual labels:  openstreetmap
gtfs-osm-sync
Synchronizes public transportation data in GTFS format with OpenStreetMap.org
Stars: ✭ 85 (-26.72%)
Mutual labels:  openstreetmap
chef
Chef configuration management repo for configuring & maintaining the OpenStreetMap servers.
Stars: ✭ 94 (-18.97%)
Mutual labels:  openstreetmap
ciclomapa
Beautiful, interactive & open bike maps of Brazilian cities. Powered by OpenStreetMap.
Stars: ✭ 56 (-51.72%)
Mutual labels:  openstreetmap
psycopgr
A Python wrapper of pgRouting for routing from nodes to nodes on real map.
Stars: ✭ 24 (-79.31%)
Mutual labels:  openstreetmap
nagmapReborn
Nagmap Reborn - Standalone integration with some server monitoring systems providing a user-friendly interface through geographic visualization.
Stars: ✭ 19 (-83.62%)
Mutual labels:  openstreetmap
maproulette2
MapRoulette back-end / API
Stars: ✭ 46 (-60.34%)
Mutual labels:  openstreetmap
Friend-Time
Discord bot - Friend Time helps your server coordinate times and events by converting times mentioned in chat between time zones!
Stars: ✭ 62 (-46.55%)
Mutual labels:  timezone
osm-static-maps
Openstreetmap static maps is a nodejs lib, CLI and server open source inspired on google static map service
Stars: ✭ 130 (+12.07%)
Mutual labels:  openstreetmap
osm-parquetizer
A converter for the OSM PBFs to Parquet files
Stars: ✭ 71 (-38.79%)
Mutual labels:  openstreetmap
osm-gis-export
Export OSM data to GIS formats like Shapefiles, Spatialite or PostGIS.
Stars: ✭ 20 (-82.76%)
Mutual labels:  openstreetmap
time machine
A date and time API for Dart
Stars: ✭ 120 (+3.45%)
Mutual labels:  timezone

Timeshape

Maven Central Build status Gitter

Timeshape is a Java library that can be used to determine to which time zone a given geo coordinate belongs. It's based on data published at https://github.com/evansiroky/timezone-boundary-builder/releases, which itself is inherited from the OpenStreetMap data.

But what if knowing just time zone for a geo coordinate is not enough? Wouldn't it be nice to know more, like administrative area or city neighborhood? Check out GeoBundle, now there's a Java library for that, too!

Quote

“Time is an illusion.”

Albert Einstein

Getting started

Timeshape is published on Maven Central. The coordinates are the following:

<dependency>
    <groupId>net.iakovlev</groupId>
    <artifactId>timeshape</artifactId>
    <version>2022f.15</version>
</dependency>

Android

Android developers should add Timeshape to the app level gradle.build as follows:

implementation('net.iakovlev:timeshape:2022f.15') {
  // Exclude standard compression library
  exclude group: 'com.github.luben', module: 'zstd-jni'
}
// Import aar for native component compilation
implementation 'com.github.luben:zstd-jni:1.5.2-3@aar'

Adopters

Are you using Timeshape? Please consider opening a pull request to list your organization here:

  • Name and website of your organization

Using the library

The user API of library is in net.iakovlev.timeshape.TimeZoneEngine class. To use it, follow these steps:

Initialization

Initialize the class with the data for the whole world:

import net.iakovlev.timeshape.TimeZoneEngine;
TimeZoneEngine engine = TimeZoneEngine.initialize();

Or, alternatively, initialize it with some bounding box only, to reduce memory usage:

TimeZoneEngine engine = TimeZoneEngine.initialize(47.0599, 4.8237, 55.3300, 15.2486);

It is important to mention that for the time zone to be loaded by the second method, it must be covered by the bounding box completely, not just intersect with it.

During initialization, the data is read from resource and the index is built. Initialization takes a significant amount of time (approximately 1 second), so do it only once in program lifetime.

Data can also be read from an external file, see overloads of TimeZoneEngine.initialize that accept TarArchiveInputStream. The file format should be same as produced by running builder sbt project (see here). It is responsibility of caller to close input stream passed to TimeZoneEngine.initialize.

Query for java.time.ZoneId:

Once initialization is completed, you can query the ZoneId based on latitude and longitude:

import java.util.Optional;
import java.time.ZoneId;
Optional<ZoneId> maybeZoneId = engine.query(52.52, 13.40);

Multiple time zones for single geo point

Starting from release 2019b.7, the data source from which Timeshape is built contains overlapping geometries. In other words, some geo points can simultaneously belong to multiple time zones. To accommodate this, Timeshape has made the following change. It's now possible to query all the time zones, to which given geo point belongs:

List<ZoneId> allZones = engine.queryAll(52.52, 13.40);

The Optional<ZoneId> query(double latitude, double longitude) method is still there, and it still returns maximum one ZoneId. If given geo point belongs to multiple time zones, only single one will be returned. Which of multiple zones will be returned is entirely arbitrary. Because of this, method Optional<ZoneId> query(double latitude, double longitude) is not suitable for use cases where such choice must be deliberate. In such cases use List<ZoneId> queryAll(double latitude, double longitude) method and apply further business logic to its output to choose the right time zone. Consult file https://raw.githubusercontent.com/evansiroky/timezone-boundary-builder/master/expectedZoneOverlaps.json for information about areas of the world where multiple time zones are to be expected.

Querying polyline

Timeshape supports querying of multiple sequential geo points (a polyline, e.g. a GPS trace) in an optimized way using method List<SameZoneSpan> queryPolyline(double[] points). Performance tests (see net.iakovlev.timeshape.PolylineQueryBenchmark) show significant speedup of using this method for querying a polyline, comparing to separately querying each point from polyline using Optional<ZoneId> query(double latitude, double longitude) method:

Benchmark                                  Mode  Cnt  Score   Error  Units
PolylineQueryBenchmark.testQueryPoints    thrpt    5  2,188 ▒ 0,044  ops/s
PolylineQueryBenchmark.testQueryPolyline  thrpt    5  4,073 ▒ 0,017  ops/s

Architecture

See dedicated document for description of Timeshape internals.

Versioning

Version of Timeshape consist of data version and software version, divided by a '.' symbol. Data version is as specified at https://github.com/evansiroky/timezone-boundary-builder/releases. Software version is an integer, starting from 1 and incrementing for each published artifact.

Licenses

The code of the library is licensed under the MIT License.

The time zone data contained in library is licensed under the Open Data Commons Open Database License (ODbL).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].