Skip to content

Commit 022ffc6

Browse files
authored
Merge pull request #30 from paulmach/filter
osmpbf: add filter functions
2 parents 614b2d0 + a4dc65a commit 022ffc6

File tree

4 files changed

+297
-53
lines changed

4 files changed

+297
-53
lines changed

osmpbf/README.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
osm/osmpbf [![Go Reference](https://pkg.go.dev/badge/github.com/paulmach/osm.svg)](https://pkg.go.dev/github.com/paulmach/osm/osmpbf)
2-
==========
1+
# osm/osmpbf [![Go Reference](https://pkg.go.dev/badge/github.com/paulmach/osm.svg)](https://pkg.go.dev/github.com/paulmach/osm/osmpbf)
32

43
Package osmpbf provides a scanner for decoding large [OSM PBF](https://wiki.openstreetmap.org/wiki/PBF_Format) files.
54
They are typically found at [planet.osm.org](https://planet.openstreetmap.org/) or [Geofabrik Download](https://download.geofabrik.de/).
65

7-
### Example:
6+
## Example:
87

98
```go
109
file, err := os.Open("./delaware-latest.osm.pbf")
@@ -34,7 +33,7 @@ if err := scanner.Err(); err != nil {
3433
**Note:** Scanners are **not** safe for parallel use. One should feed the
3534
objects into a channel and have workers read from that.
3635

37-
### Skipping Types
36+
## Skipping Types
3837

3938
Sometimes only ways or relations are needed. In this case reading and creating
4039
those objects can be skipped completely. After creating the Scanner set the appropriate
@@ -53,7 +52,29 @@ type Scanner struct {
5352
}
5453
```
5554

56-
### OSM PBF files with node locations on ways
55+
## Filtering Elements
56+
57+
The above skips all elements of a type. To filter based on the element's tags or
58+
other values, use the filter functions. These filter functions are called in parallel
59+
and not in a predefined order. This can be a performant way to filter for elements
60+
with a certain set of tags.
61+
62+
```
63+
type Scanner struct {
64+
// If the Filter function is false, the element well be skipped
65+
// at the decoding level. The functions should be fast, they block the
66+
// decoder, there are `procs` number of concurrent decoders.
67+
// Elements can be stored if the function returns true. Memory is
68+
// reused if the filter returns false.
69+
FilterNode func(*osm.Node) bool
70+
FilterWay func(*osm.Way) bool
71+
FilterRelation func(*osm.Relation) bool
72+
73+
// contains filtered or unexported fields
74+
}
75+
```
76+
77+
## OSM PBF files with node locations on ways
5778

5879
This package supports reading OSM PBF files where the ways have been annotated with the coordinates of each node. Such files can be generated using [osmium](https://osmcode.org/osmium-tool), with the [add-locations-to-ways](https://docs.osmcode.org/osmium/latest/osmium-add-locations-to-ways.html) subcommand. This feature makes it possible to work with the ways and their geometries without having to keep all node locations in some index (which takes work and memory resources).
5980

0 commit comments

Comments
 (0)