Categorygithub.com/missinglink/gosmparse
modulepackage
0.0.0-20170628200928-01884c3f2f75
Repository: https://github.com/missinglink/gosmparse.git
Documentation: pkg.go.dev

# README

OpenStreetMap PBF Parser in Go

Build Status

Gosmparse works already, but the API may change (Documentation).

It has been designed with performance and maximum usage convenience in mind; on an Intel Core i7-6820HQ with NVMe flash it is able to process 67 MB/s, so a planet file can be processed in less than 10 minutes. If you find possible speed-ups or other improvements, let me know.

Characteristics

  • fast
  • panic-free
  • tested with different files from different sources/generators
  • more than 80% test coverage and has benchmarks for all hot spots
  • one dependency only: Go protobuf package
  • can read from any io.Reader (e.g. for parsing during download)

Install

go get -u github.com/missinglink/gosmparse

Example Usage

// Implement the gosmparser.OSMReader interface here.
// Streaming data will call those functions.
type dataHandler struct{}

func (d *dataHandler) ReadNode(n gosmparse.Node)         {}
func (d *dataHandler) ReadWay(w gosmparse.Way)           {}
func (d *dataHandler) ReadRelation(r gosmparse.Relation) {}

func ExampleNewDecoder() {
	r, err := os.Open("filename.pbf")
	if err != nil {
		panic(err)
	}
	dec := gosmparse.NewDecoder(r)
	// Parse will block until it is done or an error occurs.
	err = dec.Parse(&dataHandler{})
	if err != nil {
		panic(err)
	}
}

Download & Parse

It is possible to parse during download, so you don't have to wait for a download to finish to be able to start the parsing/processing. You can simply use the standard Go net/http package and pass resp.Body to the decoder.

resp, err := http.Get("http://download.geofabrik.de/europe/germany/bremen-latest.osm.pbf")
if err != nil {
	panic(err)
}
defer resp.Body.Close()
dec := gosmparse.NewDecoder(resp.Body)
err = dec.Parse(&dataHandler{})
if err != nil {
	panic(err)
}

Did it break?

If you found a case, where gosmparse broke, please report it and provide the file that caused the failure.

# Packages

Package OSMPBF is a generated protocol buffer package.

# Functions

FeatureEnabled - return true if feature is enabled, else false.
NewDecoder returns a new decoder that reads from r.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author

# Structs

BlobIndex - an index of all blocks in the file.
BlobInfo - store info about each block.
A Decoder reads and decodes OSM data from an input stream.
GroupInfo - store info about each group.
Node is an OSM data element with a position and tags (key/value pairs).
Relation is an OSM data element that contains multiple elements (RelationMember) and has tags (key/value pairs).
RelationMember refers to an element in a relation.
Way is an OSM data element that consists of Nodes and tags (key/value pairs).

# Interfaces

OSMReader is the interface that needs to be implemented in order to receive Elements from the parsing process.

# Type aliases

MemberType describes the type of a relation member (node/way/relation).