osm

package module
v0.0.0-...-d580851 Latest Latest
Warning

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

Go to latest
Published: May 29, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

README

osm

The osm package is used to parse OpenStreetMap files and manipulate the data

Installation

$ go get github.com/vetinari/osm

Usage

Yet another pbf to osm xml converter:

    package main

    import (
        "fmt"
        "os"
        "github.com/vetinari/osm"
        "github.com/vetinari/osm/pbf"
        "github.com/vetinari/osm/xml"
    )

    func main() {
        if len(os.Args) != 2 {
            fmt.Fprintf(os.Stderr, "%s: Usage: %s PBF_FILE\n", os.Args[0], os.Args[0])
            os.Exit(1)
        }

        fh, err := os.Open(os.Args[1])
        if err != nil {
            fmt.Fprintf(os.Stderr, "%s: failed to open %s: %s\n", os.Args[0], os.Args[1], err)
            os.Exit(1)
        }
        defer fh.Close()

        o, err := osm.New(pbf.Parser(fh))
        if err != nil {
            fmt.Fprintf(os.Stderr, "%s: failed to parse %s: %s\n", os.Args[0], os.Args[1], err)
            os.Exit(1)
        }

        xml.Dump(os.Stdout, o)
    }

Documentation

http://godoc.org/github.com/vetinari/osm

Help

pull requests welcome :-)

To Do

  • More documentation ;-)
  • tests
  • import "log" & debug level / debug
  • don't write/dump deleted items unless explicitly requested
  • download / parse from osm.org API
  • merge 2 or more *osm.OSM into one

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OsmXmlHeader

func OsmXmlHeader() string

Types

type DataFormat

type DataFormat int
const (
	FmtUnknown DataFormat = iota
	FmtXML
	FmtPBF
	FmtGeoJSON
	FmtOverpassJSON
)

type OSM

type OSM struct {
	Version    string
	BBox       bbox.BBox
	Origin     string
	Nodes      map[int64]*node.Node
	Ways       map[int64]*way.Way
	Relations  map[int64]*relation.Relation
	Users      map[uint32]*user.User
	Timestamps map[string]time.Time
	Handler    OSMReader
}

the main entry point for OSM data

func New

func New(p Parser, reader OSMReader) (*OSM, error)

returns a new OSM, which is filled by the passed osm.Parser

func NewOSM

func NewOSM(handler OSMReader) *OSM

returns a new and empty OSM

func (*OSM) BoundingBox

func (o *OSM) BoundingBox() (*bbox.BBox, error)

func (*OSM) FilterTags

func (o *OSM) FilterTags(tl ...*tags.Tags) *OSM

func (*OSM) GetNode

func (o *OSM) GetNode(id int64) *node.Node

func (*OSM) GetNodeList

func (o *OSM) GetNodeList() *node.NodeList

func (*OSM) GetRelation

func (o *OSM) GetRelation(id int64) *relation.Relation

func (*OSM) GetRelationList

func (o *OSM) GetRelationList() *relation.RelationList

func (*OSM) GetWay

func (o *OSM) GetWay(id int64) *way.Way

func (*OSM) GetWayList

func (o *OSM) GetWayList() *way.WayList

func (*OSM) Merge

func (self *OSM) Merge(other *OSM)

func (*OSM) String

func (o *OSM) String() string

func (*OSM) String_old

func (o *OSM) String_old() string

returns a stringified (in osm XML format) version of the OSM. Do not use for huge OSM data, better dump to some file via xml.Dump()

type OSMReader

type OSMReader interface {
	ReadBounds(n *bbox.BBox) bool
	ReadNode(*node.Node) bool
	ReadWay(*way.Way) bool
	ReadRelation(*relation.Relation) bool
}

type Parser

type Parser interface {
	Parse(OSMReader) (*OSM, error)
}

the osm.Parser interface, currently implemented by the xml and pbf sub modules

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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