osm

package module
v0.0.0-...-16aac61 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2017 License: MIT Imports: 5 Imported by: 5

README

go-osm

OpenStreetMap XML Data parser in golang

Install

go get github.com/glaslos/go-osm

Usage

package main

import (
	"fmt"
	"github.com/glaslos/go-osm"
)

var data = `<?xml version="1.0" encoding="UTF-8"?>
<osm>
  <bounds minlat="64.0918000" minlon="-21.9304200" maxlat="64.0928200" maxlon="-21.9262200"/>
  <node id="14586443" lat="64.0912791" lon="-21.9271369"/>
  <way id="23341403">
    <nd ref="137868465"/>
    <tag k="name" v="Vífilsstaðavegur"/>
  </way>
</osm>
`

func main() {
	m, _ := osm.DecodeString(data)
	// 64.0912791 -21.9271369
	fmt.Println(m.Nodes[0].Lat, m.Nodes[0].Lng)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bounds

type Bounds struct {
	XMLName xml.Name `xml:"bounds"`
	Minlat  float64  `xml:"minlat,attr"`
	Minlon  float64  `xml:"minlon,attr"`
	Maxlat  float64  `xml:"maxlat,attr"`
	Maxlon  float64  `xml:"maxlon,attr"`
}

Bounds struct

type Elem

type Elem struct {
	ID        int64 `xml:"id,attr"`
	Loc       Location
	Version   int       `xml:"version,attr"`
	Ts        time.Time `xml:"timestamp,attr"`
	UID       int64     `xml:"uid,attr"`
	User      string    `xml:"user,attr"`
	ChangeSet int64     `xml:"changeset,attr"`
}

Elem is a OSM base element

type Location

type Location struct {
	Type        string
	Coordinates []float64
}

Location struct

type Map

type Map struct {
	Bounds    Bounds
	Nodes     []Node
	Ways      []Way
	Relations []Relation
}

Osm struct

func Decode

func Decode(reader io.Reader) (*Map, error)

Decode an reader

func DecodeFile

func DecodeFile(fileName string) (*Map, error)

DecodeFile an OSM file

func DecodeString

func DecodeString(data string) (*Map, error)

type Member

type Member struct {
	Type string `xml:"type,attr"`
	Ref  int64  `xml:"ref,attr"`
	Role string `xml:"role,attr"`
}

Member struct

type Node

type Node struct {
	Elem
	XMLName xml.Name `xml:"node"`
	Lat     float64  `xml:"lat,attr"`
	Lng     float64  `xml:"lon,attr"`
	Tag     []Tag    `xml:"tag"`
}

Node structure

type Relation

type Relation struct {
	Elem
	Visible bool     `xml:"visible,attr"`
	Version string   `xml:"version,attr"`
	Members []Member `xml:"member"`
	Tags    []Tag    `xml:"tag"`
}

Relation struct

type Tag

type Tag struct {
	XMLName xml.Name `xml:"tag"`
	Key     string   `xml:"k,attr"`
	Value   string   `xml:"v,attr"`
}

Tag struct

type Way

type Way struct {
	Elem
	XMLName xml.Name `xml:"way"`
	Tags    map[string]string
	RTags   []Tag `xml:"tag"`
	Nds     []struct {
		ID int64 `xml:"ref,attr"`
	} `xml:"nd"`
}

Way struct

Jump to

Keyboard shortcuts

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