Skip to content
forked from qedus/osmpbf

OpenStreetMap PBF file format parser in Go Lang.

License

Notifications You must be signed in to change notification settings

karsten42/osmpbf

 
 

Repository files navigation

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.

About

OpenStreetMap PBF file format parser in Go Lang.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 68.6%
  • Protocol Buffer 30.2%
  • Makefile 1.2%