pbf – github.com/codesoap/pbf Index | Files | Directories

package pbf

import "github.com/codesoap/pbf"

package extractor provides functions for extracting OSM entities within a given area from PBF files. The entities can further be filtered by their tags.

The entities, as well as the filter options, do not contain all available data and metadata in order to simplify the interface and reduce resource use.

Index

Types

type Entities

type Entities struct {
	Nodes     map[int64]Node     // Nodes by their ID.
	Ways      map[int64]Way      // Ways by their ID.
	Relations map[int64]Relation // Relations by their ID.
}

func ExtractEntities

func ExtractEntities(pbfFile string, filter Filter) (Entities, error)

ExtractEntities extracts all entities matching filter from the given pbfFile.

type Entity

type Entity interface {
	ID() int64
	Tags() map[string]string
}

An Entity is an OSM entity: either a Node, Way or Relation.

type Filter

type Filter struct {
	// Location filters results by geographic location. If it is nil, this
	// filter is inactive.
	//
	// Note that ways and relations which only pass through Location, but
	// have no nodes there, will be missed.
	//
	// Example:
	//     myFilter.Location = func(lat, lon int64) bool {
	//         return lat >= 50_000_000_000 &&
	//             lat <= 50_010_000_000 &&
	//             lon >= 10_000_000_000 &&
	//             lon <= 10_010_000_000
	//     }
	Location LocationFilter

	// The Tags filter will filter entities by their tags. Keys are tags
	// and values are accepted values. If a value is an empty slice, every
	// value for this tag is accepted, but a value for this tag must be
	// present.
	Tags map[string][]string

	// If ExcludePartial is true, the filter will not match ways and
	// relations, where only some of their nodes lay within Location. This
	// can improve performance.
	ExcludePartial bool
}

Filter is a filter for OSM entities.

type LocationFilter

type LocationFilter func(lat, lon int64) bool

LocationFilter is a function that takes a latitude and longitude in nanodegrees and returns true if the given coordinates match the filter.

type Node

type Node struct {
	// contains filtered or unexported fields
}

func (Node) Coords

func (n Node) Coords() (lat, lon int64)

func (Node) ID

func (n Node) ID() int64

func (Node) Tags

func (n Node) Tags() map[string]string

type Relation

type Relation struct {
	// contains filtered or unexported fields
}

func (Relation) ID

func (r Relation) ID() int64

func (Relation) Nodes

func (r Relation) Nodes() []int64

func (Relation) Relations

func (r Relation) Relations() []int64

func (Relation) Tags

func (r Relation) Tags() map[string]string

func (Relation) Ways

func (r Relation) Ways() []int64

type Way

type Way struct {
	// contains filtered or unexported fields
}

func (Way) ID

func (w Way) ID() int64

func (Way) Nodes

func (w Way) Nodes() []int64

func (Way) Tags

func (w Way) Tags() map[string]string

Source Files

doc.go entity.go extractor.go filter.go

Directories

PathSynopsis
fileblock
pbfproto
util
Version
v0.1.2 (latest)
Published
Oct 4, 2024
Platform
linux/amd64
Imports
8 packages
Last checked
1 week ago

Tools for package owners.