https://github.com/shanghuiyang/pbfmap
pbfmap is a reader of osm pbf in pure golang.
https://github.com/shanghuiyang/pbfmap
golang openstreetmap osm pbf
Last synced: about 2 months ago
JSON representation
pbfmap is a reader of osm pbf in pure golang.
- Host: GitHub
- URL: https://github.com/shanghuiyang/pbfmap
- Owner: shanghuiyang
- License: mit
- Created: 2020-09-10T14:01:42.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-12-31T05:03:21.000Z (over 4 years ago)
- Last Synced: 2024-06-20T07:57:33.746Z (about 2 years ago)
- Topics: golang, openstreetmap, osm, pbf
- Language: Go
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pbfmap
[](https://github.com/shanghuiyang/pbfmap/actions/workflows/ci.yml)
[](https://github.com/shanghuiyang/pbfmap/blob/master/LICENSE)
pbfmap is a reader of osm pbf in pure golang.
## usage
```go
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
}
```