Home

Awesome

<!-- HEADER --> <br /> <p align="center"> <a href="https://github.com/SmilyOrg/tinygpkg"> <img src="assets/logo.png" alt="Logo" width="80" height="80"> </a> <h3 align="center">tinygpkg</h3> <p align="center"> Go library for local, small, fast reverse geocoding with <a href="https://github.com/TWKB/Specification/blob/master/twkb.md">TWKB</a> & <a href="http://www.geopackage.org/">GeoPackage</a>. <br /> <br /> <a href="https://github.com/SmilyOrg/tinygpkg-data">📥 Get Datasets</a> · <a href="https://github.com/SmilyOrg/tinygpkg/issues">🐛 Report Bug</a> · <a href="https://github.com/SmilyOrg/tinygpkg/issues">💡 Request Feature</a> </p> </p> <!-- TABLE OF CONTENTS --> <details open="open"> <summary>Table of Contents</summary> <ol> <li> <a href="#about">About</a> <ul> <li><a href="#features">Features</a></li> <li><a href="#limitations">Limitations</a></li> <li><a href="#built-with">Built With</a></li> </ul> </li> <li><a href="#benchmarks">Benchmarks</a></li> <li><a href="#usage">Usage</a></li> <li><a href="#contributing">Contributing</a></li> <li><a href="#license">License</a></li> <li><a href="#acknowledgements">Acknowledgements</a></li> </ol> </details>

About

tinygpkg is a Go library for fast, local, and small-scale geospatial processing. Currently the main use-case is local reverse geocoding by using GeoPackage files that have been simplified and compressed into Tiny Well-known Binary (TWKB) format.

The library has been heavily inspired by sams96/rgeo, a Go library for local reverse geocoding. The main difference is that rgeo uses embedded compressed GeoJSON, which it uses to build a s2.ShapeIndex at initialization time, while tinygpkg uses the GeoPackage format (based on SQLite), which it queries and deserializes at query time.

This means that for comparable datasets tinygpkg has almost no startup cost (12ms vs 14s) and drastically lower runtime memory usage (27MB vs 1.5GB) at the expense of slower reverse geocoding queries (63µs vs 500ns) compared to rgeo. tinygpkg can also work with much larger datasets (like geoBoundaries CGAZ), as it doesn't need to index the entire dataset in memory.

Features

Limitations

Built With

Benchmarks

See a more detailed comparison below using two Natural Earth datasets.

Benchmark - 110m countries datasetrgeotinygpkg% of rgeo
Compiled code size3.2 MB7.8 MB243%
Bundle size (code + data)32 MB8.2 MB26%
Startup time93 ms14 ms15%
Startup allocated bytes22 MB12 KB0.05%
Runtime memory usage25 MB27 MB108%
Reverse geocode time1.2 µs87 µs7250%
Benchmark - 10m cities datasetrgeotinygpkg% of rgeo
Compiled code size3.2 MB7.8 MB243%
Bundle size (code + data)32 MB11.5 MB35%
Bundle size (7z compressed)30 MB5 MB17%
Startup time14000 ms12 ms0.08%
Startup allocated bytes6 GB13 KB0.0002%
Runtime memory usage1.5 GB27 MB1.8%
Reverse geocode time0.5 µs63 µs12600%

See also detailed benchmark results.

Usage

go get github.com/smilyorg/tinygpkg

See example, shortened below.


// Open GeoPackage with dataset and column for reverse geocoding
g, _ := gpkg.Open(
  "../testdata/ne_110m_admin_0_countries_s4_twkb_p3.gpkg",
  "ne_110m_admin_0_countries",
  "NAME",
)
defer g.Close()

// Reverse geocode a point
p := s2.LatLngFromDegrees(48.8566, 2.3522)
name, _ := g.ReverseGeocode(context.Background(), p)
println(name)

// Output: France

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

Distributed under the MIT License. See LICENSE for more information.

Acknowledgements