overpass2osm

package module
v0.0.0-...-2d21b2a Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2020 License: MIT Imports: 5 Imported by: 0

README

overpass2josm

The overpass2osm package converts Overpass JSON data into an OSM object. Specifically, it's intended to supplement features of the paulmach/osm package used for handing OpenStreetMap data in Go.

Example

b := []byte(`
  {
    "version": 0.6,
    "generator": "Overpass API 0.7.56.7 b85c4387",
    "elements": [
      {
        "type": "node",
        "id": 7495431894,
        "lat": 45.7042173,
        "lon": -121.5236360,
        "tags": {
          "emergency": "fire_hydrant",
          "water_source": "main"
        }
      }
    ]
  }
`)

ovp := &overpass2osm.Overpass{}

err := json.Unmarshal(b, &ovp)
if err != nil {
  panic(err)
}

o, err := overpass2osm.Convert(ovp) // o object is type *osm.OSM
if err != nil {
  panic(err)
}

The *osm.OSM object can now be converted to GeoJSON using the sub-package paulmach/osm/osmgeojson.

fc, err := osmgeojson.Convert(o)
if err != nil {
  panic(err)
}

gj, _ := json.MarshalIndent(fc, "", " ")

fmt.Println(string(gj))

The resulting GeoJSON string should now be a direct representation of the Overpass JSON element data.

{
 "type": "FeatureCollection",
 "features": [
  {
   "id": "node/7495431894",
   "type": "Feature",
   "geometry": {
    "type": "Point",
    "coordinates": [
     -121.523636,
     45.7042173
    ]
   },
   "properties": {
    "id": 7495431894,
    "meta": {},
    "relations": [],
    "tags": {
     "emergency": "fire_hydrant",
     "water_source": "main"
    },
    "type": "node"
   }
  }
 ]
}

Detail

This overpass2osm package utilizes the paulmach/osm/annotate sub-package to convert the Overpass type defined in this package into an *osm.OSM object. It includes the same options available in paulmach/osm/annotate.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChildFilter

func ChildFilter(filter func(osm.FeatureID) bool) annotate.Option

func Convert

func Convert(ovp *Overpass, opts ...annotate.Option) (*osm.OSM, error)

Convert takes an Overpass object and converts it to an osm.OSM object.

func IgnoreInconsistency

func IgnoreInconsistency(yes bool) annotate.Option

func IgnoreMissingChildren

func IgnoreMissingChildren(yes bool) annotate.Option

func Threshold

func Threshold(t time.Duration) annotate.Option

Types

type Element

type Element struct {
	Type    string  `json:"type,attr,omitempty"`
	ID      int     `json:"id,attr,omitempty"`
	Nodes   []int   `json:"nodes,attr,omitempty"`
	Ways    []int   `json:"ways,attr,omitempty"`
	Tags    Tags    `json:"tags,attr,omitempty"`
	Lat     float64 `json:"lat,attr,omitempty"`
	Lon     float64 `json:"lon,attr,omitempty"`
	Members Members `json:"members,attr,omitempty`
}

Element represents a generalized OSM type (node, way or relation) that's listed in an Overpass response.

type Member

type Member struct {
	Type string `json:"type,attr,omitempty"`
	Ref  int    `json:"ref,attr,omitempty"`
	Role string `json:"role,attr,omitempty"`
}

Member represents a single relation member.

type Members

type Members []Member

Members represents a set of relation members from an Overpass response element.

type Option

type Option func(ctx context.Context) error

type Overpass

type Overpass struct {
	Version   float64 `json:"version,attr,omitempty"`
	Generator string  `json:"generator,attr,omitempty"`

	OSM3S struct {
		TimeStampOSMBase string `json:"timestamp_osm_base,attr,omitempty"`
		Copyright        string `json:"copyright,attr,omitempty"`
	}

	Elements []Element `json:"elements,attr,omitempty"`
}

Overpass represents the response from an Overpass query (JSON only).

func UnmarshalOverpass

func UnmarshalOverpass(data []byte) (*Overpass, error)

UnmarshalOverpass will unmarshal the JSON data into an Overpass object.

type Tags

type Tags map[string]string

Tags represents a map of key/value tag strings.

Jump to

Keyboard shortcuts

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