Documentation ¶
Overview ¶
Example ¶
package main import ( "context" "fmt" "io" "log" "os" parser "m4o.io/pbf" ) func main() { in, err := os.Open("testdata/greater-london.osm.pbf") if err != nil { log.Fatal(err) } defer in.Close() const size = 3 * 1024 * 1024 d, err := parser.NewDecoder(context.Background(), in, parser.WithProtoBufferSize(size), parser.WithNCpus(2)) if err != nil { log.Fatal(err) } defer d.Close() 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 *parser.Node: // Process Node v. nc++ case *parser.Way: // Process Way v. wc++ case *parser.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 ¶
const ( // DefaultBufferSize is the default buffer size for protobuf un-marshaling DefaultBufferSize = 1024 * 1024 // DefaultInputChannelLength is the default channel length of raw blobs DefaultInputChannelLength = 16 // DefaultOutputChannelLength is the default channel length of decoded arrays of element DefaultOutputChannelLength = 8 // DefaultDecodedChannelLength is the default channel length of decoded elements coalesced from output channels DefaultDecodedChannelLength = 8000 )
const ( Degree Degrees = 1 Radian = (180 / math.Pi) * Degree E5 Epsilon = 1e-5 E6 Epsilon = 1e-6 E7 Epsilon = 1e-7 E8 Epsilon = 1e-8 E9 Epsilon = 1e-9 )
Degrees units.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BoundingBox ¶
BoundingBox is simply a bounding box.
func (BoundingBox) Contains ¶
func (b BoundingBox) Contains(lon Degrees, lat Degrees) bool
Contains checks if the bounding box contains the lon lat point.
func (BoundingBox) EqualWithin ¶
func (b BoundingBox) EqualWithin(o BoundingBox, eps Epsilon) bool
EqualWithin checks if two bounding boxes are within a specific epsilon.
func (BoundingBox) String ¶
func (b BoundingBox) String() string
type Decoder ¶
type Decoder struct { Header Header // contains filtered or unexported fields }
Decoder reads and decodes OpenStreetMap PBF data from an input stream.
func NewDecoder ¶
NewDecoder returns a new decoder, configured with cfg, that reads from reader. The decoder is initialized with the OSM header.
func (*Decoder) Close ¶
func (d *Decoder) Close()
Close will cancel the background decoding pipeline.
type DecoderOption ¶
type DecoderOption func(*decoderOptions)
DecoderOption configures how we set up the decoder.
func WithDecodedChannelLength ¶
func WithDecodedChannelLength(l int) DecoderOption
WithDecodedChannelLength lets you set the channel length of decoded elements coalesced from output channels.
func WithInputChannelLength ¶
func WithInputChannelLength(l int) DecoderOption
WithInputChannelLength lets you set the channel length of raw blobs.
func WithNCpus ¶
func WithNCpus(n uint16) DecoderOption
WithNCpus lets you set the number of CPUs to use for background processing.
func WithOutputChannelLength ¶
func WithOutputChannelLength(l int) DecoderOption
WithOutputChannelLength lets you set the channel length of decoded arrays of element.
func WithProtoBufferSize ¶
func WithProtoBufferSize(s int) DecoderOption
WithProtoBufferSize lets you set the buffer size for protobuf un-marshaling.
type Degrees ¶
type Degrees float64
Degrees is the decimal degree representation of a longitude or latitude.
func ParseDegrees ¶
ParseDegrees converts a string to a Degrees instance.
func (Degrees) EqualWithin ¶
EqualWithin checks if two degrees are within a specific epsilon.
type ElementType ¶
type ElementType int
ElementType is an enumeration of relation types.
const ( // NODE denotes that the member is a node NODE ElementType = iota // WAY denotes that the member is a way WAY // RELATION denotes that the member is a relation RELATION )
func (ElementType) String ¶
func (i ElementType) String() string
type Epsilon ¶
type Epsilon float64
Epsilon is an enumeration of precisions that can be used when comparing Degrees.
type Header ¶
type Header struct { BoundingBox BoundingBox RequiredFeatures []string OptionalFeatures []string WritingProgram string Source string OsmosisReplicationTimestamp time.Time OsmosisReplicationSequenceNumber int64 OsmosisReplicationBaseURL string }
Header is the contents of the OpenStreetMap PBF data file.
type Info ¶
type Info struct { Version int32 UID int32 Timestamp time.Time Changeset int64 User string Visible bool }
Info represents information common to Node, Way, and Relation elements.
type Member ¶
type Member struct { ID uint64 Type ElementType Role string }
Member represents an element that
type Node ¶
Node represents a specific point on the earth's surface defined by its latitude and longitude. Each node comprises at least an id number and a pair of coordinates.