Region à gogo is a microservice, it's a simple database that returns metadata associated to a fence for a given location.
It uses S2 and a segment tree to create a fast geo shape database, details of implementation are described in this blog post.
It can also be used directly from docker docker run -P akhenakh/regionagogo
You can use any geo data but the provided GeoJSON comes from who's on first.
It works too with Gadm Data but the data are not free for commercial use.
Regionagogo is using a BoltDB datafile to store the fences and a small segment tree as index lives in memory.
go get github.com/akhenakh/regionagogo
cd $GOPATH/src/github.com/akhenakh/regionagogo
make
To generate the database from GeoJSON use the provided ragogenfromjson
command, you can specify the fields you want from the GeoJSON properties to be saved into the DB:
ragogenfromjson -filename testdata/world_region.geojson -importFields iso -dbpath ./region.db
Run regionagogo -dbpath ./region.db
, it will listen on port 8082
.
You can query via HTTP GET:
GET /query?lat=19.542915&lng=-155.665857
{
"code": "US",
"name": "Hawaii"
}
You can use it in your own code without the HTTP interface:
gs := regionagogo.NewGeoSearch("region.db")
r := gs.StabbingQuery(msg.Latitude, msg.Longitude)
- create a struct for data import, change the default coverer ...
- move the cache outside of boltdb storage to make it generic
- implement an in memory storage