osm

package
v0.2.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2021 License: BSD-2-Clause Imports: 15 Imported by: 3

Documentation

Overview

Package osm extracts and manipulates OpenStreetMap (OSM) data. Refer to openstreetmap.org for more information about OSM data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	Nodes     map[osm.NodeID]*Node
	Ways      map[osm.WayID]*Way
	Relations map[osm.RelationID]*Relation
	// contains filtered or unexported fields
}

Data holds OpenStreetMap data and relationships.

func ExtractFile added in v0.2.5

func ExtractFile(ctx context.Context, file string, keep KeepFunc, keepTags bool) (*Data, error)

ExtractFile extracts OpenStreetMap data from the given file path, determining whether it is an XML or PBF file from the extension (.osm or .pbf, respectively). keep determines which records are included in the output. keepTags determines whether the tags and other metadata should be removed from each record to reduce memeory use.

func ExtractPBF added in v0.2.4

func ExtractPBF(ctx context.Context, rs io.ReadSeeker, keep KeepFunc, keepTags bool) (*Data, error)

ExtractPBF extracts OpenStreetMap data from osm.pbf file rs. keep determines which records are included in the output.

func ExtractTag

func ExtractTag(rs io.ReadSeeker, tag string, keepTags bool, values ...string) (*Data, error)

ExtractTag extracts OpenStreetMap data with the given tag set to one of the given values. keepTags determines whether the tags and other metadata should be removed from each record to reduce memeory use.

func ExtractXML added in v0.2.4

func ExtractXML(ctx context.Context, rs io.ReadSeeker, keep KeepFunc, keepTags bool) (*Data, error)

ExtractXML extracts OpenStreetMap data from osm file rs. keep determines which records are included in the output.

func (*Data) Check

func (o *Data) Check() error

Check checks OSM data to ensure that all necessary components are present.

func (*Data) CountTags added in v0.2.4

func (o *Data) CountTags() Tags

CountTags returns the different tags in the receiver and the number of instances of each one.

func (*Data) Filter added in v0.2.4

func (o *Data) Filter(keep KeepFunc) *Data

Filter returns a copy of the receiver where only objects selected by keep are retained.

func (*Data) Geom

func (o *Data) Geom() ([]*GeomTags, error)

Geom converts the OSM data to geometry objects, keeping the tag information.

type GeomTags

type GeomTags struct {
	geom.Geom
	Tags map[string][]string
}

GeomTags holds a geometry object and the tags that apply to it.

type GeomType

type GeomType int

GeomType specifies the valid geometry types.

const (
	// Point is a point geometry.
	Point GeomType = iota

	// Line is a linear geometry.
	Line

	// Poly is a polygonal geometry.
	Poly
)

func DominantType

func DominantType(gt []*GeomTags) (GeomType, error)

DominantType returns the most frequently occurring type among the given features.

type KeepFunc added in v0.2.4

type KeepFunc func(d *Data, object interface{}) bool

KeepFunc is a function that determines whether an OSM object should be included in the output. The object may be either *osmpbf.Node, *osmpbf.Way, or *osmpbf.Relation

func KeepAll added in v0.2.8

func KeepAll() KeepFunc

KeepAll specifies that all objects should be kept.

func KeepBounds added in v0.2.4

func KeepBounds(b *geom.Bounds) KeepFunc

KeepBounds keeps OSM objects that overlap with b. Using KeepBounds in combination with other KeepFuncs may result in unexpected results.

func KeepTags added in v0.2.4

func KeepTags(tags map[string][]string) KeepFunc

KeepTags keeps OSM objects that contain the given tag key with at least one of the given tag values, where the keys and values correspond to the keys and values of the 'tags' input. If no tag valuse are given, then all object with the given key will be kept.

type Member added in v0.2.10

type Member struct {
	Ref  int64
	Type osm.Type
}

Member is a member of a relation.

type Node

type Node struct {
	ID   osm.NodeID
	Lat  float64
	Lon  float64
	Tags osm.Tags
}

Node holds a subset of the information specifying an OpenStreetMap node.

type ObjectType

type ObjectType int

ObjectType specifies the valid OpenStreetMap types.

const (
	// NodeType is an OpenStreetMap node.
	NodeType ObjectType = iota
	// WayType can be either open or closed.
	WayType
	// ClosedWayType is an OpenStreetMap way that is closed (i.e., a polygon).
	ClosedWayType
	// OpenWayType is an OpenStreetMap way that is open (i.e., a line string).
	OpenWayType
	// RelationType is an OpenStreetMap relation.
	RelationType
)

type Relation

type Relation struct {
	ID      osm.RelationID
	Members []Member
	Tags    osm.Tags
}

Relation holds a subset of the information specifying an OpenStreetMap way.

type TagCount

type TagCount struct {
	Key, Value  string
	ObjectCount map[ObjectType]int
	TotalCount  int
}

TagCount hold information about the number of instances of the specified tag in a database.

func (*TagCount) DominantType

func (t *TagCount) DominantType() ObjectType

DominantType returns the most frequently occuring ObjectType for this tag.

type Tags

type Tags []*TagCount

Tags holds information about the tags that are in a database.

func CountTags

func CountTags(ctx context.Context, rs io.ReadSeeker) (Tags, error)

CountTags returns the different tags in the database and the number of instances of each one.

func (*Tags) Filter

func (t *Tags) Filter(f func(*TagCount) bool) *Tags

Filter applies function f to all records in the receiver and returns a copy of the receiver that only contains the records for which f returns true.

func (*Tags) Len

func (t *Tags) Len() int

Len returns the length of the receiver to implement the sort.Sort interface.

func (*Tags) Less

func (t *Tags) Less(i, j int) bool

Less returns whether item i is less than item j to implement the sort.Sort interface.

func (*Tags) Swap

func (t *Tags) Swap(i, j int)

Swap swaps elements i and j to implement the sort.Sort interface.

func (*Tags) Table

func (t *Tags) Table() [][]string

Table creates a table of the information held by the receiver.

type Way added in v0.2.4

type Way struct {
	ID    osm.WayID
	Nodes []osm.NodeID
	Tags  osm.Tags
}

Way holds a subset of the information specifying an OpenStreetMap way.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL