Skip to content

shanghuiyang/pbfmap

Repository files navigation

pbfmap

CI License

pbfmap is a reader of osm pbf in pure golang.

usage

package main

import (
	"fmt"

	"github.com/shanghuiyang/pbfmap"
)

func main() {
	pbf := pbfmap.New()
	if err := pbf.Load("test.osm.pbf"); err != nil {
		fmt.Printf("failed to load pbf, error: %v", err)
		return
	}

	fmt.Println("nodes    : ", len(pbf.Nodes))
	fmt.Println("ways     : ", len(pbf.Ways))
	fmt.Println("relations: ", len(pbf.Relations))

	fmt.Println("---------------")
	n := pbf.GetNode(2651270709)
	if n == nil {
		fmt.Printf("node %v not found\n", 2651270709)
		return
	}
	fmt.Println(n)

	fmt.Println("---------------")
	w := pbf.GetWay(330213759)
	if w == nil {
		fmt.Printf("way %v not found\n", 330213759)
		return
	}
	fmt.Println(w)
	fmt.Printf("length: %.4f m\n", w.Length())

	fmt.Println("---------------")
	r := pbf.GetRelation(9146261)
	if r == nil {
		fmt.Printf("relation %v not found\n", 9146261)
		return
	}
	fmt.Println(r)

	return
}

About

pbfmap is a reader of osm pbf in pure golang.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages