Documentation ¶
Overview ¶
Package osmpbf decodes OpenStreetMap (OSM) PBF files. Use this package by creating a NewDecoder and passing it a PBF file. Use Start to start decoding process. Use Decode to return Node, Way and Relation structs.
Example ¶
package main import ( "fmt" "github.com/qedus/osmpbf" "io" "log" "os" "runtime" ) func main() { f, err := os.Open("greater-london-140324.osm.pbf") if err != nil { log.Fatal(err) } defer f.Close() d := osmpbf.NewDecoder(f) err = d.Start(runtime.GOMAXPROCS(-1)) // use several goroutines for faster decoding 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) }
Output: Nodes: 2729006, Ways: 459055, Relations: 12833
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
A Decoder reads and decodes OpenStreetMap PBF data from an input stream.
func NewDecoder ¶
NewDecoder returns a new decoder that reads from r.
func (*Decoder) Decode ¶
Decode reads the next object from the input stream and returns either a Node, Way or Relation struct representing the underlying OpenStreetMap PBF data, or error encountered. The end of the input stream is reported by an io.EOF error.
Decode is safe for parallel execution. Only first error encountered will be returned, subsequent invocations will return io.EOF.
type Member ¶
type Member struct { ID int64 Type MemberType Role string }