whosonfirst / go-whosonfirst-export

Go package for exporting Who's On First documents.
BSD 3-Clause "New" or "Revised" License
2 stars 1 forks source link

go-whosonfirst-export

Go package for exporting Who's On First documents.

What is this?

go-whosonfirst-export is a Go package for exporting Who's On First documents in Go. It is a port of the py-mapzen-whosonfirst-geojson package and mmmmmmmaybe some or all of the py-mapzen-whosonfirst-export package.

Important

This package is still in flux. It is starting to settle down with the v2 release but it might still change.

Documentation

Go Reference

Example

Simple

Error handling removed for the sake of brevity.

import (
    "context"
    "github.com/whosonfirst/go-whosonfirst-export/v2"
    "io/ioutil"
    "os
)

func main() {

    ctx := context.Background()

    path := "some.geojson"      
    fh, _ := os.Open(path)
    defer fh.Close()

    body, _ := ioutil.ReadAll(fh)

    opts, _ := export.NewDefaultOptions(ctx)
    export.Export(body, opts, os.Stdout)
}

Exporter

import (
    "context"
    "github.com/whosonfirst/go-whosonfirst-export/v2"
    "io/ioutil"
    "os
)

func main() {

    ctx := context.Background()

    ex, _ := export.NewExporter(ctx, "whosonfirst://")

    path := "some.geojson"      
    fh, _ := os.Open(path)
    defer fh.Close()

    body, _ := ioutil.ReadAll(fh)

    body, _ = ex.Export(ctx, body)
    os.Stdout.Write(body)
}

Interfaces

Exporter

type Exporter interface {
    Export(context.Context, []byte) ([]byte, error)
    ExportFeature(context.Context, interface{}) ([]byte, error)
}

To do

This package needs to hold hands with the go-whosonfirst-validate package.

See also