Categorygithub.com/kkdd/osmpbf
modulepackage
1.0.0
Repository: https://github.com/kkdd/osmpbf.git
Documentation: pkg.go.dev

# README

osmpbf

Build Status Coverage Status Go Report Card GoDoc

Package osmpbf is used to decode OpenStreetMap pbf files.

Installation

$ go get github.com/qedus/osmpbf

Usage

Usage is similar to json.Decoder.

	f, err := os.Open("greater-london-140324.osm.pbf")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	d := osmpbf.NewDecoder(f)

	// use more memory from the start, it is faster
	d.SetBufferSize(osmpbf.MaxBlobSize)

	// start decoding with several goroutines, it is faster
	err = d.Start(runtime.GOMAXPROCS(-1))
	if err != nil {
		log.Fatal(err)
	}

	var nc, wc, rc uint64
	for {
		if v, err := d.Decode(); err == io.EOF {
			break
		} else if err != nil {
			log.Fatal(err)
		} else {
			switch v := v.(type) {
			case *osmpbf.Node:
				// Process Node v.
				nc++
			case *osmpbf.Way:
				// Process Way v.
				wc++
			case *osmpbf.Relation:
				// Process Relation v.
				rc++
			default:
				log.Fatalf("unknown type %T\n", v)
			}
		}
	}

	fmt.Printf("Nodes: %d, Ways: %d, Relations: %d\n", nc, wc, rc)

Documentation

http://godoc.org/github.com/qedus/osmpbf

To Do

The parseNodes code has not been tested as I can only find PBF files with DenseNode format.

An Encoder still needs to be created to reverse the process.

# Packages

Package OSMPBF is a generated protocol buffer package.

# Functions

NewDecoder returns a new decoder that reads from r.

# Constants

MaxBlobSize is maximum supported blob size.
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

A Decoder reads and decodes OpenStreetMap PBF data from an input stream.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author