geofabrik

package module
v0.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2025 License: MIT Imports: 11 Imported by: 1

README

go-geofabrik

unofficial api client for Geofabrik.

Installation

cli
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
package
MD5

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
}
Download

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)
    }
}
Polygon

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"...}
}

License

MIT

Acknowledgement

awesome folks at Geofabrik

Maintainer

Benjamin Ramser - @iwpnd

Project Link: https://github.com/iwpnd/go-geofabrik

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CopyFailedError added in v0.6.0

type CopyFailedError struct {
	Message string
}

func (CopyFailedError) Error added in v0.6.0

func (e CopyFailedError) Error() string

type DownloadFailedError added in v0.6.0

type DownloadFailedError struct {
	URL     string
	Message string
	Code    int
}

func (DownloadFailedError) Error added in v0.6.0

func (e DownloadFailedError) Error() string

type EmptyNameError added in v0.6.0

type EmptyNameError struct{}

func (EmptyNameError) Error added in v0.6.0

func (e EmptyNameError) Error() string

type FileType added in v0.1.2

type FileType string

type Geofabrik

type Geofabrik struct {
	*rip.Client
}

Geofabrik wraps a rest client.

func New

func New(host string, options ...rip.Option) (*Geofabrik, error)

New is the constructor for a Geofabrik.

func (*Geofabrik) Download added in v0.1.5

func (g *Geofabrik) Download(ctx context.Context, name, outpath string) error

Download a dataset to output path

func (*Geofabrik) MD5 added in v0.1.9

func (g *Geofabrik) MD5(ctx context.Context, name string) (string, error)

MD5 will return the latest MD5 of a dataset

func (*Geofabrik) Polygon added in v0.1.9

func (g *Geofabrik) Polygon(ctx context.Context, name string) (*Polygon, error)

type Path added in v0.1.2

type Path struct {
	// contains filtered or unexported fields
}

type Polygon added in v0.1.9

type Polygon struct {
	Name string
	// contains filtered or unexported fields
}

Polygon ..

func NewPolygon added in v0.1.9

func NewPolygon(name string, data io.Reader) *Polygon

NewPolygon ..

func (*Polygon) Process added in v0.1.9

func (p *Polygon) Process() error

Process iterates over the returned geofabrik .poly document and collects coordinate pairs

func (*Polygon) ToFeature added in v0.1.9

func (p *Polygon) ToFeature() (string, error)

ToFeature returns a feature string if p.rings is populated

func (*Polygon) WithProperties added in v0.1.9

func (p *Polygon) WithProperties(properties map[string]any) *Polygon

WithProperties attaches properties to the Polygon, defaults to {"name":p.name}

Directories

Path Synopsis
cmd
geofabrik command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL