osmxml

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: MIT Imports: 5 Imported by: 5

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Scanner

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

Scanner provides a convenient interface reading a stream of osm data from a file or url. Successive calls to the Scan method will step through the data.

Scanning stops unrecoverably at EOF, the first I/O error, the first xml error or the context being cancelled. When a scan stops, the reader may have advanced arbitrarily far past the last token.

The Scanner API is based on bufio.Scanner https://golang.org/pkg/bufio/#Scanner

Example
package main

import (
	"context"
	"fmt"
	"os"

	"github.com/paulmach/osm"
	"github.com/paulmach/osm/osmxml"
)

func main() {
	scanner := osmxml.New(context.Background(), os.Stdin)
	for scanner.Scan() {
		fmt.Println(scanner.Object().(*osm.Changeset))
	}

	if err := scanner.Err(); err != nil {
		fmt.Fprintln(os.Stderr, "reading standard input:", err)
	}
}
Output:

func New

func New(ctx context.Context, r io.Reader) *Scanner

New returns a new Scanner to read from r.

func (*Scanner) Close

func (s *Scanner) Close() error

Close causes all future calls to Scan to return false. Does not close the underlying reader.

func (*Scanner) Err

func (s *Scanner) Err() error

Err returns the first non-EOF error that was encountered by the Scanner.

func (*Scanner) Object

func (s *Scanner) Object() osm.Object

Object returns the most recent token generated by a call to Scan as a new osm.Object. This interface is implemented by:

*osm.Bounds
*osm.Node
*osm.Way
*osm.Relation
*osm.Changeset
*osm.Note
*osm.User

func (*Scanner) Scan

func (s *Scanner) Scan() bool

Scan advances the Scanner to the next element, which will then be available through the Object method. It returns false when the scan stops, either by reaching the end of the input, an io error, an xml error or the context being cancelled. After Scan returns false, the Err method will return any error that occurred during scanning, except if it was io.EOF, Err will return nil.

Jump to

Keyboard shortcuts

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