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 Natural Earth Data. Some regions are not precise enough and some accentuated names are wrong, if you are aware of a better source please tell me.
It works too with the better 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_states_10m.geojson -fields iso_a2,name -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)
- move the cache outside of boltdb storage to make it generic
- implement an in memory storage