unofficial api client for Geofabrik.
go install github.com/iwpnd/go-geofabrik/cmd/geofabrik@latest
โ geofabrik --help
NAME:
geofabrik - geofabrik
USAGE:
geofabrik [global options] command [command options] [arguments...]
COMMANDS:
md5 get latest md5 of geofabrik dataset
polygon get extent of dataset as geojson feature
download download dataset to outputpath
download-if-changed download dataset to outputpath if md5 changed
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--help, -h show help
Get latest md5 of a dataset by name
import (
"contxt"
"fmt"
"github.com/iwpnd/go-geofabrik"
"github.com/iwpnd/rip"
)
func main() {
g, err := geofabrik.New("http://download.geofabrik.de", false)
if err != nil {
panic("wuaah!")
}
ctx := context.Background()
name := "europe/germany/berlin"
md5, err := g.MD5(ctx, name)
if err != nil {
panic(err)
}
fmt.Println(md5)
// >> 379b462358f660744c1a9eed6f46b031
}
Get a dataset by name to output path
import (
"contxt"
"fmt"
"github.com/iwpnd/go-geofabrik"
"github.com/iwpnd/rip"
)
func main() {
g, err := geofabrik.New("http://download.geofabrik.de", false)
if err != nil {
panic("wuaah!")
}
ctx := context.Background()
name := "europe/germany/berlin"
outputPath := "./tmp"
err := g.Download(ctx, name, outputPath)
if err != nil {
panic(err)
}
}
Get a dataset extend as Polygon Feature
import (
"contxt"
"fmt"
"github.com/iwpnd/go-geofabrik"
"github.com/iwpnd/rip"
)
func main() {
g, err := geofabrik.New("http://download.geofabrik.de", false)
if err != nil {
panic("wuaah!")
}
ctx := context.Background()
name := "europe/germany/berlin"
polygon, err := g.Polygon(ctx, name)
if err != nil {
panic(err)
}
f, err := polygon.ToFeature()
if err != nil {
panic(err)
}
fmt.Println(f)
// > {"type":"Feature"...}
}
MIT
awesome folks at Geofabrik
Benjamin Ramser - @iwpnd
Project Link: https://github.com/iwpnd/go-geofabrik