export

package module
v2.7.1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2023 License: BSD-3-Clause Imports: 15 Imported by: 53

README

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

Documentation

Overview

go-whosonfirst-export is a Go package for exporting Who's On First documents in Go.

Example

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

func main() {

	ctx := context.Background()

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

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

	body, _ := io.ReadAll(fh)

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssignProperties added in v2.1.0

func AssignProperties(ctx context.Context, body []byte, to_assign map[string]interface{}) ([]byte, error)

func AssignPropertiesIfChanged added in v2.3.1

func AssignPropertiesIfChanged(ctx context.Context, body []byte, to_assign map[string]interface{}) (bool, []byte, error)

func CessateRecord added in v2.6.0

func CessateRecord(ctx context.Context, ex Exporter, old_body []byte) ([]byte, error)

CessateRecord will assign the relevant properties to make 'old_body' as cessated (ceased) using the current time.

func CessateRecordWithTime added in v2.6.0

func CessateRecordWithTime(ctx context.Context, ex Exporter, t time.Time, old_body []byte) ([]byte, error)

CessateRecordWithTime will assign the relevant properties to make 'old_body' as cessated (ceased) using the time defined by 't'.

func DeprecateRecord added in v2.6.0

func DeprecateRecord(ctx context.Context, ex Exporter, old_body []byte) ([]byte, error)

DeprecateRecord will assign the relevant properties to make 'old_body' as deprecated using the current time. This method does not handle assigning or updating "supersedes" or "superseded_by" properties.

func DeprecateRecordWithTime added in v2.6.0

func DeprecateRecordWithTime(ctx context.Context, ex Exporter, t time.Time, old_body []byte) ([]byte, error)

DeprecateRecordWithTime will assign the relevant properties to make 'old_body' as deprecated using the time defined by 't'. This method does not handle assigning or updating "supersedes" or "superseded_by" properties.

func EnsureProperties added in v2.1.0

func EnsureProperties(ctx context.Context, body []byte, to_ensure map[string]interface{}) ([]byte, error)

func Export

func Export(feature []byte, opts *Options, wr io.Writer) error

func ExportChanged

func ExportChanged(feature []byte, existingFeature []byte, opts *Options, wr io.Writer) (changed bool, err error)

ExportChanged returns a boolean which indicates whether the file was changed by comparing it to the `existingFeature` byte slice, before the lastmodified timestamp is incremented. If the `feature` is identical to `existingFeature` it doesn't write to the `io.Writer`.

func Exporters

func Exporters() []string

func Format

func Format(feature []byte, opts *Options) ([]byte, error)

func Prepare

func Prepare(feature []byte, opts *Options) ([]byte, error)

func RegisterExporter

func RegisterExporter(ctx context.Context, scheme string, init_func ExporterInitializationFunc) error

func RemoveProperties added in v2.1.0

func RemoveProperties(ctx context.Context, body []byte, to_remove []string) ([]byte, error)

func SupersedeRecord added in v2.1.0

func SupersedeRecord(ctx context.Context, ex Exporter, old_body []byte) ([]byte, []byte, error)

func SupersedeRecordWithParent added in v2.2.0

func SupersedeRecordWithParent(ctx context.Context, ex Exporter, to_supersede_f []byte, parent_f []byte) ([]byte, []byte, error)

Types

type Exporter

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

func NewExporter

func NewExporter(ctx context.Context, uri string) (Exporter, error)

func NewWhosOnFirstExporter

func NewWhosOnFirstExporter(ctx context.Context, uri string) (Exporter, error)

type ExporterInitializationFunc

type ExporterInitializationFunc func(ctx context.Context, uri string) (Exporter, error)

type Feature

type Feature struct {
	Type       string      `json:"type"`
	Id         int64       `json:"id"`
	Properties interface{} `json:"properties"`
	Bbox       []float64   `json:"bbox,omitempty"`
	Geometry   interface{} `json:"geometry"`
}

type Options

type Options struct {
	IDProvider id.Provider
}

func NewDefaultOptions

func NewDefaultOptions(ctx context.Context) (*Options, error)

func NewDefaultOptionsWithProvider

func NewDefaultOptionsWithProvider(ctx context.Context, provider id.Provider) (*Options, error)

type WhosOnFirstExporter

type WhosOnFirstExporter struct {
	Exporter
	// contains filtered or unexported fields
}

func (*WhosOnFirstExporter) Export

func (ex *WhosOnFirstExporter) Export(ctx context.Context, feature []byte) ([]byte, error)

func (*WhosOnFirstExporter) ExportFeature

func (ex *WhosOnFirstExporter) ExportFeature(ctx context.Context, feature interface{}) ([]byte, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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