Documentation
¶
Overview ¶
Package tzf is a package convert (lng,lat) to timezone.
Inspired by timezonefinder https://github.com/jannikmi/timezonefinder, fast python package for finding the timezone of any point on earth (coordinates) offline.
Index ¶
- Variables
- func SetDropPBTZ(opt *Option)
- type DefaultFinder
- func (f *DefaultFinder) DataVersion() string
- func (f *DefaultFinder) GetGeoJSON() *convert.BoundaryFile
- func (f *DefaultFinder) GetTZGeoJSON(tzName string) (*convert.BoundaryFile, error)
- func (f *DefaultFinder) GetTimezoneName(lng float64, lat float64) string
- func (f *DefaultFinder) GetTimezoneNames(lng float64, lat float64) ([]string, error)
- func (f *DefaultFinder) TimezoneNames() []string
- type F
- func NewDefaultFinder() (F, error)
- func NewFinderFromCompressed(input *pb.CompressedTimezones, opts ...OptionFunc) (F, error)deprecated
- func NewFinderFromCompressedTopo(input *pb.CompressedTopoTimezones, opts ...OptionFunc) (F, error)
- func NewFinderFromPB(input *pb.Timezones, opts ...OptionFunc) (F, error)
- func NewFinderFromRawJSON(input *convert.BoundaryFile, opts ...OptionFunc) (F, error)
- func NewFullFinder() (F, error)
- func NewFuzzyFinderFromPB(input *pb.PreindexTimezones) (F, error)
- type Finder
- func (f *Finder) DataVersion() string
- func (f *Finder) GetGeoJSON() *convert.BoundaryFile
- func (f *Finder) GetTZGeoJSON(tzName string) (*convert.BoundaryFile, error)
- func (f *Finder) GetTimezoneName(lng float64, lat float64) string
- func (f *Finder) GetTimezoneNames(lng float64, lat float64) ([]string, error)
- func (f *Finder) TimezoneNames() []string
- type FuzzyFinder
- func (f *FuzzyFinder) DataVersion() string
- func (f *FuzzyFinder) GetGeoJSON() *convert.BoundaryFile
- func (f *FuzzyFinder) GetTZGeoJSON(tzName string) (*convert.BoundaryFile, error)
- func (f *FuzzyFinder) GetTimezoneName(lng float64, lat float64) string
- func (f *FuzzyFinder) GetTimezoneNames(lng float64, lat float64) ([]string, error)
- func (f *FuzzyFinder) TimezoneNames() []string
- type Option
- type OptionFunc
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoTimezoneFound = errors.New("tzf: no timezone found")
Functions ¶
func SetDropPBTZ ¶ added in v0.9.2
func SetDropPBTZ(opt *Option)
SetDropPBTZ will make Finder not save github.com/ringsaturn/tzf/pb.Timezone in memory
Types ¶
type DefaultFinder ¶ added in v0.9.0
type DefaultFinder struct {
// contains filtered or unexported fields
}
DefaultFinder is a finder impl combine both FuzzyFinder and Finder.
It's designed for performance first and allow some not so correct return at some area.
func (*DefaultFinder) DataVersion ¶ added in v0.13.0
func (f *DefaultFinder) DataVersion() string
func (*DefaultFinder) GetGeoJSON ¶ added in v1.1.0
func (f *DefaultFinder) GetGeoJSON() *convert.BoundaryFile
GetGeoJSON returns a GeoJSON FeatureCollection covering all timezones.
func (*DefaultFinder) GetTZGeoJSON ¶ added in v1.1.0
func (f *DefaultFinder) GetTZGeoJSON(tzName string) (*convert.BoundaryFile, error)
GetTZGeoJSON returns a GeoJSON FeatureCollection for the named timezone.
func (*DefaultFinder) GetTimezoneName ¶ added in v0.9.0
func (f *DefaultFinder) GetTimezoneName(lng float64, lat float64) string
Example ¶
package main
import (
"fmt"
"github.com/ringsaturn/tzf"
)
func main() {
finder, err := tzf.NewDefaultFinder()
if err != nil {
panic(err)
}
fmt.Println(finder.GetTimezoneName(116.6386, 40.0786)) // In longitude-latitude order
}
Output: Asia/Shanghai
func (*DefaultFinder) GetTimezoneNames ¶ added in v0.10.0
func (f *DefaultFinder) GetTimezoneNames(lng float64, lat float64) ([]string, error)
Example ¶
package main
import (
"fmt"
"github.com/ringsaturn/tzf"
)
func main() {
finder, err := tzf.NewDefaultFinder()
if err != nil {
panic(err)
}
fmt.Println(finder.GetTimezoneNames(87.6168, 43.8254)) // In longitude-latitude order
}
Output: [Asia/Shanghai Asia/Urumqi] <nil>
func (*DefaultFinder) TimezoneNames ¶ added in v0.9.0
func (f *DefaultFinder) TimezoneNames() []string
Example ¶
package main
import (
"fmt"
"github.com/ringsaturn/tzf"
)
func main() {
finder, err := tzf.NewDefaultFinder()
if err != nil {
panic(err)
}
fmt.Println(finder.TimezoneNames())
}
Output:
type F ¶ added in v0.12.0
type F interface {
GetTimezoneName(lng float64, lat float64) string
GetTimezoneNames(lng float64, lat float64) ([]string, error)
TimezoneNames() []string
DataVersion() string
}
func NewDefaultFinder ¶ added in v0.9.0
func NewFinderFromCompressed
deprecated
added in
v0.8.0
func NewFinderFromCompressed(input *pb.CompressedTimezones, opts ...OptionFunc) (F, error)
Deprecated: use NewFinderFromCompressedTopo instead and update data source.
func NewFinderFromCompressedTopo ¶ added in v1.1.0
func NewFinderFromCompressedTopo(input *pb.CompressedTopoTimezones, opts ...OptionFunc) (F, error)
NewFinderFromCompressedTopo builds a Finder directly from a pb.CompressedTopoTimezones input without materialising an intermediate pb.Timezones, reducing peak memory usage.
It accepts both the full-precision combined-with-oceans.compress.topo.bin and the topology-aware simplified combined-with-oceans.topology.compress.topo.bin from tzf-dist.
func NewFinderFromPB ¶
func NewFinderFromPB(input *pb.Timezones, opts ...OptionFunc) (F, error)
func NewFinderFromRawJSON ¶ added in v0.2.0
func NewFinderFromRawJSON(input *convert.BoundaryFile, opts ...OptionFunc) (F, error)
func NewFullFinder ¶ added in v1.1.0
NewFullFinder builds a DefaultFinder from the tzf-dist embedded data with no parameters required. It combines a FuzzyFinder (topology.preindex) with a Finder (topology.compress.topo) for fast lookups with accurate fallback.
Example ¶
package main
import (
"fmt"
"github.com/ringsaturn/tzf"
)
func main() {
finder, err := tzf.NewFullFinder()
if err != nil {
panic(err)
}
fmt.Println(finder.GetTimezoneName(139.6917, 35.6895))
}
Output: Asia/Tokyo
func NewFuzzyFinderFromPB ¶ added in v0.9.0
func NewFuzzyFinderFromPB(input *pb.PreindexTimezones) (F, error)
type Finder ¶
type Finder struct {
// contains filtered or unexported fields
}
Finder is based on point-in-polygon search algo.
Memory will use about 100MB if lite data and 1G if full data. Performance is very stable and very accuate.
func (*Finder) DataVersion ¶ added in v0.13.0
func (*Finder) GetGeoJSON ¶ added in v1.1.0
func (f *Finder) GetGeoJSON() *convert.BoundaryFile
GetGeoJSON returns a GeoJSON FeatureCollection covering all timezones.
func (*Finder) GetTZGeoJSON ¶ added in v1.1.0
func (f *Finder) GetTZGeoJSON(tzName string) (*convert.BoundaryFile, error)
GetTZGeoJSON returns a GeoJSON FeatureCollection for the named timezone. The same timezone name may map to more than one item in the dataset, so the result is a FeatureCollection that may contain multiple Features.
func (*Finder) GetTimezoneName ¶
GetTimezoneName will use alphabet order and return first matched result.
Example ¶
package main
import (
"fmt"
"github.com/ringsaturn/tzf"
tzfdist "github.com/ringsaturn/tzf-dist"
pb "github.com/ringsaturn/tzf/gen/go/tzf/v1"
"google.golang.org/protobuf/proto"
)
func main() {
input := &pb.CompressedTopoTimezones{}
if err := proto.Unmarshal(tzfdist.TopologyCompressTopoData, input); err != nil {
panic(err)
}
finder, _ := tzf.NewFinderFromCompressedTopo(input)
fmt.Println(finder.GetTimezoneName(116.6386, 40.0786))
}
Output: Asia/Shanghai
func (*Finder) GetTimezoneNames ¶ added in v0.10.0
Example ¶
package main
import (
"fmt"
"github.com/ringsaturn/tzf"
tzfdist "github.com/ringsaturn/tzf-dist"
pb "github.com/ringsaturn/tzf/gen/go/tzf/v1"
"google.golang.org/protobuf/proto"
)
func main() {
input := &pb.CompressedTopoTimezones{}
if err := proto.Unmarshal(tzfdist.TopologyCompressTopoData, input); err != nil {
panic(err)
}
finder, _ := tzf.NewFinderFromCompressedTopo(input)
fmt.Println(finder.GetTimezoneNames(87.6168, 43.8254))
}
Output: [Asia/Shanghai Asia/Urumqi] <nil>
func (*Finder) TimezoneNames ¶ added in v0.6.2
Example ¶
package main
import (
"fmt"
"github.com/ringsaturn/tzf"
tzfdist "github.com/ringsaturn/tzf-dist"
pb "github.com/ringsaturn/tzf/gen/go/tzf/v1"
"google.golang.org/protobuf/proto"
)
func main() {
input := &pb.CompressedTopoTimezones{}
if err := proto.Unmarshal(tzfdist.TopologyCompressTopoData, input); err != nil {
panic(err)
}
finder, _ := tzf.NewFinderFromCompressedTopo(input)
fmt.Println(finder.TimezoneNames())
}
Output:
type FuzzyFinder ¶ added in v0.9.0
type FuzzyFinder struct {
// contains filtered or unexported fields
}
FuzzyFinder use a tile map to store timezone name. Data are made by github.com/ringsaturn/tzf/cmd/preindextzpb which powerd by github.com/ringsaturn/tzf/preindex.PreIndexTimezones.
Tiles are split into two maps for memory efficiency:
- single: tiles that belong to exactly one timezone (vast majority); value is a names index.
- multi: tiles that straddle a timezone boundary; value is a slice of names indices.
func (*FuzzyFinder) DataVersion ¶ added in v0.13.0
func (f *FuzzyFinder) DataVersion() string
func (*FuzzyFinder) GetGeoJSON ¶ added in v1.1.0
func (f *FuzzyFinder) GetGeoJSON() *convert.BoundaryFile
GetGeoJSON returns a GeoJSON FeatureCollection covering all timezones, where each polygon is the bounding box of one preindex tile.
func (*FuzzyFinder) GetTZGeoJSON ¶ added in v1.1.0
func (f *FuzzyFinder) GetTZGeoJSON(tzName string) (*convert.BoundaryFile, error)
GetTZGeoJSON returns a GeoJSON FeatureCollection for the named timezone, where each polygon is the bounding box of one preindex tile.
func (*FuzzyFinder) GetTimezoneName ¶ added in v0.9.0
func (f *FuzzyFinder) GetTimezoneName(lng float64, lat float64) string
Example ¶
package main
import (
"fmt"
"github.com/ringsaturn/tzf"
tzfdist "github.com/ringsaturn/tzf-dist"
pb "github.com/ringsaturn/tzf/gen/go/tzf/v1"
"google.golang.org/protobuf/proto"
)
func main() {
input := &pb.PreindexTimezones{}
if err := proto.Unmarshal(tzfdist.PreindexData, input); err != nil {
panic(err)
}
finder, _ := tzf.NewFuzzyFinderFromPB(input)
fmt.Println(finder.GetTimezoneName(116.6386, 40.0786)) // In longitude-latitude order
}
Output: Asia/Shanghai
func (*FuzzyFinder) GetTimezoneNames ¶ added in v0.10.0
func (f *FuzzyFinder) GetTimezoneNames(lng float64, lat float64) ([]string, error)
Example ¶
package main
import (
"fmt"
"github.com/ringsaturn/tzf"
tzfdist "github.com/ringsaturn/tzf-dist"
pb "github.com/ringsaturn/tzf/gen/go/tzf/v1"
"google.golang.org/protobuf/proto"
)
func main() {
input := &pb.PreindexTimezones{}
if err := proto.Unmarshal(tzfdist.PreindexData, input); err != nil {
panic(err)
}
finder, _ := tzf.NewFuzzyFinderFromPB(input)
fmt.Println(finder.GetTimezoneNames(87.6168, 43.8254))
}
Output: [Asia/Shanghai Asia/Urumqi] <nil>
func (*FuzzyFinder) TimezoneNames ¶ added in v0.11.2
func (f *FuzzyFinder) TimezoneNames() []string
Example ¶
package main
import (
"fmt"
"github.com/ringsaturn/tzf"
tzfdist "github.com/ringsaturn/tzf-dist"
pb "github.com/ringsaturn/tzf/gen/go/tzf/v1"
"google.golang.org/protobuf/proto"
)
func main() {
input := &pb.PreindexTimezones{}
if err := proto.Unmarshal(tzfdist.PreindexData, input); err != nil {
panic(err)
}
finder, _ := tzf.NewFuzzyFinderFromPB(input)
fmt.Println(finder.TimezoneNames())
}
Output:
type OptionFunc ¶ added in v0.9.2
type OptionFunc = func(opt *Option)
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
buildgridtzpb
command
CLI tool to embed a 1°×1° grid candidate-reduction index into an existing CompressedTopoTimezones protobuf file.
|
CLI tool to embed a 1°×1° grid candidate-reduction index into an existing CompressedTopoTimezones protobuf file. |
|
checkboundaryrelease
command
|
|
|
compresstopotzpb
command
CLI tool to apply polyline coordinate compression to a TopoTimezones .topo.bin file.
|
CLI tool to apply polyline coordinate compression to a TopoTimezones .topo.bin file. |
|
compresstzpb
command
CLI tool to reduce polygon filesize
|
CLI tool to reduce polygon filesize |
|
deduplicatetzpb
command
CLI tool to convert a Timezones .bin file into the topology-aware TopoTimezones format where shared boundary edges are stored only once.
|
CLI tool to convert a Timezones .bin file into the topology-aware TopoTimezones format where shared boundary edges are stored only once. |
|
geojson2tzpb
command
CLI tool to convert GeoJSON based Timezone boundary to tzf's Probuf format.
|
CLI tool to convert GeoJSON based Timezone boundary to tzf's Probuf format. |
|
preindextzpb
command
CLI tool to preindex timezone shape.
|
CLI tool to preindex timezone shape. |
|
reducetzpb
command
CLI tool to reduce polygon filesize
|
CLI tool to reduce polygon filesize |
|
tzf
command
tzf-cli tool for local query.
|
tzf-cli tool for local query. |
|
gen
|
|
|
internal
|
|
|
borderchange
Package borderchange measures the geometric error introduced by boundary simplification.
|
Package borderchange measures the geometric error introduced by boundary simplification. |
|
cmd/bench-memory
command
bench-memory measures the retained heap of each finder type after initialization.
|
bench-memory measures the retained heap of each finder type after initialization. |
|
cmd/borderchange
command
Command borderchange measures boundary movement caused by topology-aware simplification.
|
Command borderchange measures boundary movement caused by topology-aware simplification. |
|
cmd/i32compare
command
i32compare cross-checks the scaled-integer Finder (NewFinderFromCompressedTopo) against the float reference path (DecompressTopoTimezones → DecodeTopoTimezones → NewFinderFromPB, which round-trips coordinates through float32 pb.Point).
|
i32compare cross-checks the scaled-integer Finder (NewFinderFromCompressedTopo) against the float reference path (DecompressTopoTimezones → DecodeTopoTimezones → NewFinderFromPB, which round-trips coordinates through float32 pb.Point). |
|
cmd/topodecode
command
Decode a CompressedTopoTimezones file back into flat Timezones.
|
Decode a CompressedTopoTimezones file back into flat Timezones. |
|
geom
Package geom provides zero-dependency 2-D geometry primitives and a YStripes-indexed point-in-polygon query optimised for timezone lookup.
|
Package geom provides zero-dependency 2-D geometry primitives and a YStripes-indexed point-in-polygon query optimised for timezone lookup. |
|
gridindex
Package gridindex builds and parses the 1°×1° grid candidate-reduction index.
|
Package gridindex builds and parses the 1°×1° grid candidate-reduction index. |
|
maps
Package maps defines various functions useful with maps of any type.
|
Package maps defines various functions useful with maps of any type. |
|
polyf
Package polyf is a zero-external-dependency port of github.com/ringsaturn/polyf.
|
Package polyf is a zero-external-dependency port of github.com/ringsaturn/polyf. |
|
polyline
Package polyline implements the Google Maps Encoded Polyline algorithm.
|
Package polyline implements the Google Maps Encoded Polyline algorithm. |
|
topology
Package topology provides topology-aware polygon simplification and deduplication for timezone boundary data.
|
Package topology provides topology-aware polygon simplification and deduplication for timezone boundary data. |
|
Package preindex
|
Package preindex |
|
Package reduce could reduce Polygon size both polygon lines and float precise.
|
Package reduce could reduce Polygon size both polygon lines and float precise. |
